Commits

Hadley Wickham committed 199b10c

Only close context if it's already open

Comments (0)

Files changed (3)

 #' context("String processing")
 #' context("Remote procedure calls")
 context <- function(desc) {
-  test_reporter()$end_context()
-  test_reporter()$start_context(desc)
+  rep <- test_reporter()
+  if (rep$context_open) {
+    rep$end_context()
+  }
+  rep$context_open <- TRUE
+  rep$start_context(desc)
 }
-
   self$context <- ""
   self$test <- NULL
   self$failed <- FALSE
+  
+  self$context_open <- FALSE
     
   self$start_reporter <- function() {
     self$failed <- FALSE
   self$end_context <- function() {}
   self$end_reporter <- function() {}
 })
-

inst/tests/test-context.r

 })
 
 test_that("contexts are opened, then closed", {
-  reporter <- CountReporter$clone()
-  test_file("context.r", reporter)
+  report <- CountReporter$clone()
+  test_file("context.r", report)
   expect_that(report$context_count, equals(2))
   expect_that(report$context, equals(0))
-  expect_that(report$test_count, equals(2))
+  expect_that(report$test_count, equals(4))
   expect_that(report$test, equals(0))
 })