import os import glob import simplejson for program in [ #'./tokeniser_ocaml_opt', './tokeniser_cpp --json', ]: for testfile in glob.glob('../html5lib/testdata/tokenizer/*.test'): tests = simplejson.load(open(testfile)) for test in tests['tests']: if 'contentModelFlags' in test: cmds = ["%s --%s=%s" % (program, cm.lower(), test.get('lastStartTag', '')) for cm in test['contentModelFlags']] else: cmds = [program] for cmd in cmds: i,o = os.popen2(cmd) i.write(test['input']) i.close() s = o.readline() o.close() try: output = simplejson.loads(s) except Exception, e: output = e if output != test['output']: print "%s - %s: Failed %s\nExpected: %s\nGot: %s\n" % ( cmd, testfile.rpartition('/')[2], test['description'], test['output'], output)