@@ -11,50 +11,52 @@ ListReporter <- R6::R6Class(
1111  " ListReporter"  ,
1212  inherit  =  Reporter ,
1313  public  =  list (
14-     current_start_time  =  NA ,
15-     current_expectations  =  NULL ,
16-     current_file  =  NULL ,
17-     current_context  =  NULL ,
18-     current_test  =  NULL ,
14+     running  =  NULL ,
15+     current_file  =  " "  , #  so we can still subset with this
1916    results  =  NULL ,
2017
2118    initialize  =  function () {
2219      super $ initialize()
2320      self $ capabilities $ parallel_support  <-  TRUE 
21+       self $ capabilities $ parallel_updates  <-  TRUE 
2422      self $ results  <-  Stack $ new()
23+       self $ running  <-  new.env(parent  =  emptyenv())
2524    },
2625
2726    start_test  =  function (context , test ) {
27+       #  is this a new test block?
2828      if  (
29-         ! identical(self $ current_context , context ) || 
30-           ! identical(self $ current_test , test )
29+         ! identical(self $ running [[ self $ current_file ]] $ context , context ) || 
30+           ! identical(self $ running [[ self $ current_file ]] $ test , test )
3131      ) {
32-         self $ current_context  <-  context 
33-         self $ current_test  <-  test 
34-         self $ current_expectations  <-  Stack $ new()
35-         self $ current_start_time  <-  proc.time()
32+         self $ running [[ self $ current_file ]] $ context  <-  context 
33+         self $ running [[ self $ current_file ]] $ test  <-  test 
34+         self $ running [[ self $ current_file ]] $ expectations  <-  Stack $ new()
35+         self $ running [[ self $ current_file ]] $ start_time  <-  proc.time()
3636      }
3737    },
3838
3939    add_result  =  function (context , test , result ) {
40-       if  (is.null(self $ current_expectations )) {
40+       if  (is.null(self $ running [[ self $ current_file ]] $ expectations )) {
4141        #  we received a result outside of a test:
4242        #  could be a bare expectation or an exception/error
4343        if  (! inherits(result , ' error'  )) {
4444          return ()
4545        }
46-         self $ current_expectations  <-  Stack $ new()
46+         self $ running [[ self $ current_file ]] $ expectations  <-  Stack $ new()
4747      }
4848
49-       self $ current_expectations $ push(result )
49+       self $ running [[ self $ current_file ]] $ expectations $ push(result )
5050    },
5151
5252    end_test  =  function (context , test ) {
53-       elapsed  <-  as.double(proc.time() -  self $ current_start_time )
53+       elapsed  <-  as.double(
54+         proc.time() -  self $ running [[self $ current_file ]]$ start_time 
55+       )
5456
5557      results  <-  list ()
56-       if  (! is.null(self $ current_expectations )) {
57-         results  <-  self $ current_expectations $ as_list()
58+       if  (! is.null(self $ running [[ self $ current_file ]] $ expectations )) {
59+         results  <-  self $ running [[ self $ current_file ]] $ expectations $ as_list()
5860      }
5961
6062      self $ results $ push(list (
@@ -67,28 +69,39 @@ ListReporter <- R6::R6Class(
6769        results  =  results 
6870      ))
6971
70-       self $ current_expectations  <-  NULL 
72+       self $ running [[ self $ current_file ]] $ expectations  <-  NULL 
7173    },
7274
7375    start_file  =  function (name ) {
76+       if  (! name  %in%  names(self $ running )) {
77+         newfile  <-  list (
78+           start_time  =  NA ,
79+           expectations  =  NULL ,
80+           context  =  NULL ,
81+           test  =  NULL 
82+         )
83+         assign(name , newfile , envir  =  self $ running )
84+       }
7485      self $ current_file  <-  name 
7586    },
7687
7788    end_file  =  function () {
7889      #  fallback in case we have errors but no expectations
7990      self $ end_context(self $ current_file )
91+       rm(list  =  self $ current_file , envir  =  self $ running )
8092    },
8193
8294    end_context  =  function (context ) {
83-       results  <-  self $ current_expectations 
95+       results  <-  self $ running [[ self $ current_file ]] $ expectations 
8496      if  (is.null(results )) {
8597        return ()
8698      }
8799
88-       self $ current_expectations  <-  NULL 
100+       self $ running [[ self $ current_file ]] $ expectations  <-  NULL 
89101
90102      #  look for exceptions raised outside of tests
91-       #  they happened just before end_context since they interrupt the test_file execution
103+       #  they happened just before end_context since they interrupt the test_
104+       #  file execution
92105      results  <-  results $ as_list()
93106      if  (length(results ) ==  0 ) {
94107        return ()
0 commit comments