mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 00:38:29 +01:00
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
This commit is contained in:
@@ -211,6 +211,7 @@ class TestCase:
|
|||||||
f.write(self.code)
|
f.write(self.code)
|
||||||
|
|
||||||
# epilogue
|
# epilogue
|
||||||
|
f.write(4*' '+'#line %d "%s"\n' % (f.lineno+1, f.path))
|
||||||
f.write(EPILOGUE)
|
f.write(EPILOGUE)
|
||||||
f.write('}\n')
|
f.write('}\n')
|
||||||
|
|
||||||
@@ -514,18 +515,32 @@ class TestSuite:
|
|||||||
return self.perms
|
return self.perms
|
||||||
|
|
||||||
def build(self, **args):
|
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
|
# build test files
|
||||||
tf = open(self.path + '.test.c.t', 'w')
|
tf = lineno_open(self.path + '.test.tc', 'w')
|
||||||
tf.write(BEFORE_TESTS)
|
tf.write(BEFORE_TESTS)
|
||||||
if self.code is not None:
|
if self.code is not None:
|
||||||
tf.write('#line %d "%s"\n' % (self.code_lineno, self.path))
|
tf.write('#line %d "%s"\n' % (self.code_lineno, self.path))
|
||||||
tf.write(self.code)
|
tf.write(self.code)
|
||||||
|
tf.write('#line %d "%s"\n' % (tf.lineno+1, tf.path))
|
||||||
|
|
||||||
tfs = {None: tf}
|
tfs = {None: tf}
|
||||||
for case in self.cases:
|
for case in self.cases:
|
||||||
if case.in_ not in tfs:
|
if case.in_ not in tfs:
|
||||||
tfs[case.in_] = open(self.path+'.'+
|
tfs[case.in_] = lineno_open(self.path+'.'+
|
||||||
case.in_.replace('/', '.')+'.t', 'w')
|
case.in_.replace('/', '.')[:-2]+'.tc', 'w')
|
||||||
tfs[case.in_].write('#line 1 "%s"\n' % case.in_)
|
tfs[case.in_].write('#line 1 "%s"\n' % case.in_)
|
||||||
with open(case.in_) as f:
|
with open(case.in_) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
@@ -576,12 +591,12 @@ class TestSuite:
|
|||||||
mk.write('%s: %s | %s\n' % (
|
mk.write('%s: %s | %s\n' % (
|
||||||
self.path+'.test.c',
|
self.path+'.test.c',
|
||||||
self.path,
|
self.path,
|
||||||
self.path+'.test.c.t'))
|
self.path+'.test.tc'))
|
||||||
else:
|
else:
|
||||||
mk.write('%s: %s %s | %s\n' % (
|
mk.write('%s: %s %s | %s\n' % (
|
||||||
self.path+'.'+path.replace('/', '.'),
|
self.path+'.'+path.replace('/', '.'),
|
||||||
self.path, path,
|
self.path, path,
|
||||||
self.path+'.'+path.replace('/', '.')+'.t'))
|
self.path+'.'+path.replace('/', '.')[:-2]+'.tc'))
|
||||||
mk.write('\t./scripts/explode_asserts.py $| -o $@\n')
|
mk.write('\t./scripts/explode_asserts.py $| -o $@\n')
|
||||||
|
|
||||||
self.makefile = self.path + '.mk'
|
self.makefile = self.path + '.mk'
|
||||||
|
|||||||
Reference in New Issue
Block a user