Ticket #57: trace-no-posn.patch
File trace-no-posn.patch, 3.5 KB (added by hopscc, 16 years ago) |
---|
-
Source/CobraLang.cobra
80 80 81 81 def trace(source as SourceSite, nameValues as vari Object) 82 82 require nameValues.length % 2 == 0 83 writeSrcPosn = true 84 exprEqForm = true 83 85 if .isActive 84 86 _dest.write(.prefix) 85 87 sep = .separator 86 88 i = 0 89 opt = nameValues[0] to String 90 switch = opt[1:-1] # remove quotes 91 if switch in [ '-at', '-noPosition'] # or -xAt or -xPos 92 writeSrcPosn = false 93 i += 2 87 94 while i < nameValues.length-1 88 95 name = nameValues[i] to String 89 96 value = CobraImp._techStringMaker.makeString(nameValues[i+1]) 90 _dest.write('[name]=[value][sep]') 97 switch = name[1:-1] 98 if switch in ['-=', '-noExprEq'] # or -x= 99 exprEqForm = false 100 i += 2 101 continue 102 _dest.write( if(exprEqForm, '[name]=[value][sep]', '[value][sep]')) 91 103 i += 2 92 _dest.writeLine(source.oneLiner(.separator, .willOutputDirectoryNames)) 104 exprEqForm = true 105 if writeSrcPosn, _dest.write(source.oneLiner(.separator, .willOutputDirectoryNames)) 106 _dest.writeLine 93 107 if .willAutoFlush 94 108 _dest.flush 95 109 -
Tests/110-basics-two/900-trace.cobra
3 3 def main is shared 4 4 Test().testTrace(1, 2) 5 5 .testStaticTrace 6 Test().testTraceSw(1, 2) 6 7 7 8 def testTrace(x as int, y as int) 8 9 tracer = CobraCore.tracer … … 11 12 tracer.separator = ' | ' 12 13 tracer.destination = StringWriter() 13 14 14 15 15 trace 16 16 trace x 17 17 x = 2 … … 45 45 expected = expected.replace('RuntimeType', 'MonoType') 46 46 # fix filename in actual 47 47 i = actual.indexOf(' at ') 48 i += 449 j = actual.indexOf(':', i)50 actual = actual[:i] + 'FILE' + actual[j:]51 48 if i >= 0 49 i += 4 50 j = actual.indexOf(':', i) 51 actual = actual[:i] + 'FILE' + actual[j:] 52 52 assert actual == expected 53 53 54 54 def testStaticTrace is shared … … 64 64 trace all 65 65 output = CobraCore.tracer.destination.toString.trim 66 66 .check(output, "prefix: this=Test (RuntimeType) | output='o' | at FILE:64 | in Test.testStaticTrace") 67 68 def testTraceSw(x as int, y as int) 69 tracer = CobraCore.tracer 70 tracer.prefix = 'prefix: ' 71 tracer.separator = ' . ' 72 tracer.destination = StringWriter() 73 74 trace '-noPosition', x 75 trace '-noPosition', '-noExprEq', 'Str:value of y=[y]' 76 trace '-noPosition', '-noExprEq', 'Str:value =[x]', y 77 trace '-noPosition', '-noExprEq', 'Str:value =[x]', y, x 78 79 # short form 80 trace '-at', x 81 trace '-at', '-=', 'Str:value R=[x]' 82 trace '-at', '-=', 'Str:value R=[x]', y 83 trace '-at', '-=', 'Str:value R=[x]', y, x 84 trace '-at', '-=', 'Str:value R=[x]', y, '-=', x 85 86 output = tracer.destination.toString.replace('\r', '') 87 lines = output.split(c'\n') 88 .check(lines[0], 'prefix: x=1 . ') 89 .check(lines[1], "prefix: 'Str:value of y=2' . ") 90 .check(lines[2], "prefix: 'Str:value =1' . y=2 . ") 91 .check(lines[3], "prefix: 'Str:value =1' . y=2 . x=1 . ") 92 93 .check(lines[4], 'prefix: x=1 . ') 94 .check(lines[5], "prefix: 'Str:value R=1' . ") 95 .check(lines[6], "prefix: 'Str:value R=1' . y=2 . ") 96 .check(lines[7], "prefix: 'Str:value R=1' . y=2 . x=1 . ") 97 .check(lines[8], "prefix: 'Str:value R=1' . y=2 . 1 . ") 98