diff --git a/test/testlist.py b/test/testlist.py index 7033490d..125f3bf2 100644 --- a/test/testlist.py +++ b/test/testlist.py @@ -47,6 +47,15 @@ class listCommand: print('Test' + x) command.register(listCommand) +headerHeader = '''// Generated by testlist.py; do not edit +struct testingprivCase { + const char *name; + void (*f)(void); +}; +extern const struct testingprivCase testingprivCases[]; +extern const size_t testingprivNumCases;''' +headerEntryFmt = 'extern void testingprivImplName(Test{})(void);' + class headerCommand: filename = None @@ -66,13 +75,49 @@ class headerCommand: return args[1:] def run(self, casenames): - # TODO - raise NotImplementedError + with open(self.filename, 'wt') as f: + print(headerHeader, file = f) + for x in casenames: + print(headerEntryFmt.format(x), file = f) command.register(headerCommand) +sourceHeader = '''// Generated by testlist.py; do not edit +#include "test.h" +const struct testingprivCase testingprivCases[] = {''' +sourceEntryFmt = ' {{ "Test{0}", testingprivImplName(Test{0}) }},' +sourceFooter = '''}}; +const size_t testingprivNumCases = {};''' + +class sourceCommand: + filename = None + + @classmethod + def name(cls): + return 'source' + + @classmethod + def usageString(cls): + return 'source source-file [source-files...]' + + def processArgs(self, args): + if len(args) < 1: + errf('error: output filename missing') + return None + self.filename = args[0] + return args[1:] + + def run(self, casenames): + with open(self.filename, 'wt') as f: + print(sourceHeader, file = f) + for x in casenames: + print(sourceEntryFmt.format(x), file = f) + print(sourceFooter.format(len(casenames)), file = f) +command.register(sourceCommand) + commands = [ listCommand, headerCommand, + sourceCommand, ] def usage(): @@ -96,7 +141,7 @@ def main(): cmdtype = cmd break if cmdtype is None: - errf('error: unknown command {}', cmdname) + errf('error: unknown command {!r}', cmdname) usage() cmd = cmdtype() @@ -109,6 +154,6 @@ def main(): match = r.match(line) if match is not None: casenames.append(match.group(1)) - cmd.run(casenames) + cmd.run(sorted(casenames)) main()