diff options
author | Christopher Haster <chaster@utexas.edu> | 2020-11-27 00:23:38 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2020-11-29 05:11:36 +0300 |
commit | aa46bb68ca24c586a7ebbed75a1fefb9284ab0a0 (patch) | |
tree | c86501e3a6e875fd63d8ff7e21a4cfd8c05b8085 /scripts | |
parent | 190eb833a2e6f2e26bb5a5f30119978cbfe51aea (diff) |
Made it easier to debug generated test files
Added internal lineno tracking of generated test files so that test.py
can reset the generated #line directives after a test case. This helps
debug issues with the generated glue code itself, which would previously
end up with invalid/unhelpful lineno information in error messages.
Also changed suffix from .c.t to .tc
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/test.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/scripts/test.py b/scripts/test.py index 1e19ee5..e9647a0 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -211,6 +211,7 @@ class TestCase: f.write(self.code) # epilogue + f.write(4*' '+'#line %d "%s"\n' % (f.lineno+1, f.path)) f.write(EPILOGUE) f.write('}\n') @@ -514,18 +515,32 @@ class TestSuite: return self.perms def build(self, **args): + # intercept writes to keep track of linenos + def lineno_open(path, flags): + f = open(path, flags) + f.path = path + f.lineno = 1 + write = f.write + + def lineno_write(s): + f.lineno += s.count('\n') + write(s) + f.write = lineno_write + return f + # build test files - tf = open(self.path + '.test.c.t', 'w') + tf = lineno_open(self.path + '.test.tc', 'w') tf.write(BEFORE_TESTS) if self.code is not None: tf.write('#line %d "%s"\n' % (self.code_lineno, self.path)) tf.write(self.code) + tf.write('#line %d "%s"\n' % (tf.lineno+1, tf.path)) tfs = {None: tf} for case in self.cases: if case.in_ not in tfs: - tfs[case.in_] = open(self.path+'.'+ - case.in_.replace('/', '.')+'.t', 'w') + tfs[case.in_] = lineno_open(self.path+'.'+ + case.in_.replace('/', '.')[:-2]+'.tc', 'w') tfs[case.in_].write('#line 1 "%s"\n' % case.in_) with open(case.in_) as f: for line in f: @@ -576,12 +591,12 @@ class TestSuite: mk.write('%s: %s | %s\n' % ( self.path+'.test.c', self.path, - self.path+'.test.c.t')) + self.path+'.test.tc')) else: mk.write('%s: %s %s | %s\n' % ( self.path+'.'+path.replace('/', '.'), self.path, path, - self.path+'.'+path.replace('/', '.')+'.t')) + self.path+'.'+path.replace('/', '.')[:-2]+'.tc')) mk.write('\t./scripts/explode_asserts.py $| -o $@\n') self.makefile = self.path + '.mk' |