RegressionTests__CoverageInstrumentationTest.st
changeset 746 4ac3ed420d3e
parent 628 b248c1c1fec4
child 747 0b1b5e48be6f
equal deleted inserted replaced
745:fde865b5dece 746:4ac3ed420d3e
    23     ^ 2345
    23     ^ 2345
    24 !
    24 !
    25 
    25 
    26 f3:aBoolean
    26 f3:aBoolean
    27     aBoolean ifTrue:[
    27     aBoolean ifTrue:[
    28         ^ 1234
    28         ^ 1234  "both should be executed with a true arg, and coverage should see that"
    29     ] ifFalse:[
    29     ] ifFalse:[
    30         ^ 2345
    30         ^ 2345  "bith should be executed with a true arg, and coverage should see that"
    31     ].
    31     ].
    32     ^ 3456
    32     ^ 3456
    33 !
    33 !
    34 
    34 
    35 f4:aBoolean
    35 f4:aBoolean
    36     aBoolean ifFalse:[
    36     aBoolean ifFalse:[
    37         ^ 1234
    37         ^ 1234  "should not be executed with a true arg, and coverage should see that"
       
    38     ].
       
    39 !
       
    40 
       
    41 f5:loopCount
       
    42     1 to:loopCount do:[:i |
       
    43         1 + 2   "should be executed 10 times, and coverage should see that"
    38     ].
    44     ].
    39 ! !
    45 ! !
    40 
    46 
    41 !CoverageInstrumentationTest methodsFor:'tests'!
    47 !CoverageInstrumentationTest methodsFor:'tests'!
    42 
    48 
    48     m1 := (self class compiledMethodAt:#f1).
    54     m1 := (self class compiledMethodAt:#f1).
    49 
    55 
    50     self assert:(m1 hasBeenCalled not).
    56     self assert:(m1 hasBeenCalled not).
    51 
    57 
    52     "/ execute
    58     "/ execute
    53     InstrumentationContext run:[
    59     InstrumentationContext runForCoverage:[
    54         self f1.
    60         self f1.
    55     ].
    61     ].
    56     self assert:(m1 hasBeenCalled).
    62     self assert:(m1 hasBeenCalled).
    57 
    63 
    58     "
    64     "
    73     self assert:(m2 blockInvocationInfo conform:[:i | i hasBeenExecuted not]).
    79     self assert:(m2 blockInvocationInfo conform:[:i | i hasBeenExecuted not]).
    74     self assert:(m2 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
    80     self assert:(m2 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
    75 
    81 
    76     "/ execute
    82     "/ execute
    77     context := InstrumentationContext new.
    83     context := InstrumentationContext new.
    78     context run:[
    84     context runForCoverage:[
    79         self f2:true.
    85         self f2:true.
    80     ].
    86     ].
    81     self assert:(m2 hasBeenCalled).
    87     self assert:(m2 hasBeenCalled).
    82     self assert:(m2 blockInvocationInfo conform:[:i | i hasBeenExecuted]).
    88     self assert:(m2 blockInvocationInfo conform:[:i | i hasBeenExecuted]).
    83     self assert:(m2 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
    89     self assert:(m2 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
    84 
    90 
    85     "/ execute in the same context
    91     "/ execute in the same context
    86     context run:[
    92     context runForCoverage:[
    87         self f2:false.
    93         self f2:false.
    88     ].
    94     ].
    89 
    95 
    90     self assert:(m2 hasBeenCalled).
    96     self assert:(m2 hasBeenCalled).
    91     self assert:(m2 blockInvocationInfo conform:[:i | i hasBeenExecuted]).
    97     self assert:(m2 blockInvocationInfo conform:[:i | i hasBeenExecuted]).
   101 
   107 
   102     self class recompile:#f3: usingCompilerClass:InstrumentingCompiler.
   108     self class recompile:#f3: usingCompilerClass:InstrumentingCompiler.
   103 
   109 
   104     m3 := (self class compiledMethodAt:#f3:).
   110     m3 := (self class compiledMethodAt:#f3:).
   105 
   111 
       
   112     "/ before execution
   106     self assert:(m3 hasBeenCalled not).
   113     self assert:(m3 hasBeenCalled not).
   107     self assert:(m3 blockInvocationInfo size == 2).
   114     self assert:(m3 blockInvocationInfo size == 2).
   108     self assert:(m3 statementInvocationInfo size == 1).
   115     self assert:(m3 statementInvocationInfo size == 1).
   109     self assert:(m3 blockInvocationInfo conform:[:i | i hasBeenExecuted not]).
   116     self assert:(m3 blockInvocationInfo conform:[:i | i hasBeenExecuted not]).
       
   117     self assert:(m3 blockInvocationInfo conform:[:i | i count == 0]).
   110     self assert:(m3 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   118     self assert:(m3 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   111 
   119 
   112     "/ execute
   120     "/ execute
   113     context := InstrumentationContext new.
   121     context := InstrumentationContext new.
   114     context run:[
   122     context runForCoverage:[
   115         self f3:true.
   123         self f3:true.
   116     ].
   124     ].
   117 
   125 
       
   126     "/ one block should have been invoked, the other not"
   118     self assert:(m3 hasBeenCalled).
   127     self assert:(m3 hasBeenCalled).
   119     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted]) = 1.
   128     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted]) = 1.
   120     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted not]) = 1.
   129     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted not]) = 1.
   121     self assert:(m3 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   130     self assert:(m3 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   122 
   131 
   123     "/ execute
   132     "/ execute
   124     context run:[
   133     context runForCoverage:[
   125         self f3:false.
   134         self f3:false.
   126     ].
   135     ].
   127 
   136 
       
   137     "/ both blocks should have been invoked"
   128     self assert:(m3 hasBeenCalled).
   138     self assert:(m3 hasBeenCalled).
   129     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted]) = 2.
   139     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted]) = 2.
   130     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted not]) = 0.
   140     self assert:(m3 blockInvocationInfo count:[:i | i hasBeenExecuted not]) = 0.
       
   141     self assert:(m3 blockInvocationInfo conform:[:i | i count == 1]).
   131     self assert:(m3 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   142     self assert:(m3 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   132 
   143 
   133     "
   144     "
   134      self new test_03_instrumentation
   145      self new test_03_instrumentation
   135     "
   146     "
   147     self assert:(m4 statementInvocationInfo size == 0).
   158     self assert:(m4 statementInvocationInfo size == 0).
   148     self assert:(m4 blockInvocationInfo conform:[:i | i hasBeenExecuted not]).
   159     self assert:(m4 blockInvocationInfo conform:[:i | i hasBeenExecuted not]).
   149     self assert:(m4 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   160     self assert:(m4 statementInvocationInfo conform:[:i | i hasBeenExecuted not]).
   150 
   161 
   151     "/ execute
   162     "/ execute
       
   163     InstrumentationContext runForCoverage:[
       
   164         self f4:true.
       
   165     ].
       
   166 
       
   167     self assert:(m4 hasBeenCalled).
       
   168 
       
   169     "
       
   170      self new test_04_instrumentation
       
   171     "
       
   172 !
       
   173 
       
   174 test_05_instrumentation_loop_count
       
   175     |m5|
       
   176 
       
   177     self class recompile:#f5: usingCompilerClass:InstrumentingCompiler.
       
   178 
       
   179     m5 := (self class compiledMethodAt:#f5:).
       
   180 
       
   181     self assert:(m5 hasBeenCalled not).
       
   182     self assert:(m5 blockInvocationInfo size == 1).
       
   183 
       
   184     "/ execute
   152     InstrumentationContext run:[
   185     InstrumentationContext run:[
   153         self f4:true.
   186         self f5:10.
   154     ].
   187     ].
   155 
   188 
   156     self assert:(m4 hasBeenCalled).
   189     self assert:(m5 hasBeenCalled).
   157 
   190     self assert:(m5 blockInvocationInfo first count == 10).
   158     "
   191     self assert:(m5 hasBeenCalled).
   159      self new test_04_instrumentation
   192 
       
   193     "
       
   194      self new test_05_instrumentation
   160     "
   195     "
   161 ! !
   196 ! !
   162 
   197 
   163 !CoverageInstrumentationTest class methodsFor:'documentation'!
   198 !CoverageInstrumentationTest class methodsFor:'documentation'!
   164 
   199