This is the way how to get the the source code that belongs to uncovered bytecodes (expecting "trace" from the previous code) class := Time. selector := #print24:showSeconds:on:. m := class >> selector. usedBytecodes := ((trace at: class) at: selector ifAbsent: Set new). allBytecodes := Set new. m symbolicLinesDo: [:pc :lineForPC | allBytecodes add: pc ]. unusedBytecodes := allBytecodes copyWithoutAll: usedBytecodes. dm := m debuggerMap. source := (class sourceCodeAt: selector) asText. unusedBytecodes do: [:pc | range := dm rangeForPC: pc contextIsActiveContext: false. source makeBoldFrom: range first to: range last.]. source asMorph openInWindow. Cheers, -- Pavel On Tue, Feb 21, 2012 at 4:03 PM, Pavel Krivanek <pavel.krivanek@gmail.com> wrote:
Hi,
what about to intrroduce tests that will test coverage of tests? Some improved version of the code below. Are there some tool for Smalltalk showing uncovered lines of code? There are such tools in Java world :-) One little problem is that this code do not work on Linux because of a VM error that cause test failures on CI server too.
Cheers, Â Pavel
| class test trace classTrace result  |
class := Time. test := TimeTest.
trace := Dictionary new.
thisContext runSimulated: [test suite run] Â contextAtEachStep: [ :current | Â Â Â Â | cls sel methods bytecodes | Â Â Â Â cls := current method methodClass. Â Â Â Â sel := current method selector. Â Â Â Â methods := trace at: cls ifAbsentPut: Dictionary new. Â Â Â Â bytecodes := methods at: sel ifAbsentPut: Set new. Â Â Â Â bytecodes add: current pc.]
trace .
result := String streamContents: [:s |
classTrace := trace at: class ifAbsent: nil. classTrace     ifNil: [         s nextPutAll: 'Class ', class name, ' not called'; cr. ]     ifNotNil: [         s nextPutAll: class name; cr.         class selectorsDo: [:sel |             | m usedBytecodes allBytecodes |             m := class >> sel.             usedBytecodes := (classTrace at: sel ifAbsent: Set new) size.             allBytecodes := 0.             m symbolicLinesDo: [:pc :lineForPC | allBytecodes := allBytecodes + 1 ]..             s tab; nextPutAll: sel; nextPutAll: ' - '; nextPutAll: (usedBytecodes  /  allBytecodes * 100) asFloat asString; nextPutAll: '%'; cr. ]]. ]. result..