# HG changeset patch # User Laurent Charignon # Date 1453220547 28800 # Node ID 0de4dfc9af0c36f9ebbf06cab74d70d7bfe2ca44 # Parent 4c6053a6b17d682b34fb88bbeb5e94ed9085d900 run-tests: fix crash when --json and --blacklist are both used (issue5050) This patch fixes a crash when both --json and --blacklist were given as arguments of run-tests.py. Now, instead of crashing, we add an entry for blacklisted tests in the json output to show that the tests were skipped. diff -r 4c6053a6b17d -r 0de4dfc9af0c tests/run-tests.py --- a/tests/run-tests.py Thu Jan 21 12:37:12 2016 -0800 +++ b/tests/run-tests.py Tue Jan 19 08:22:27 2016 -0800 @@ -1727,14 +1727,20 @@ ('skip', result.skipped)] for res, testcases in groups: for tc, __ in testcases: - tres = {'result': res, - 'time': ('%0.3f' % timesd[tc.name][2]), - 'cuser': ('%0.3f' % timesd[tc.name][0]), - 'csys': ('%0.3f' % timesd[tc.name][1]), - 'start': ('%0.3f' % timesd[tc.name][3]), - 'end': ('%0.3f' % timesd[tc.name][4]), - 'diff': result.faildata.get(tc.name, ''), - } + if tc.name in timesd: + tres = {'result': res, + 'time': ('%0.3f' % timesd[tc.name][2]), + 'cuser': ('%0.3f' % timesd[tc.name][0]), + 'csys': ('%0.3f' % timesd[tc.name][1]), + 'start': ('%0.3f' % timesd[tc.name][3]), + 'end': ('%0.3f' % timesd[tc.name][4]), + 'diff': result.faildata.get(tc.name, + ''), + } + else: + # blacklisted test + tres = {'result': res} + outcome[tc.name] = tres jsonout = json.dumps(outcome, sort_keys=True, indent=4) fp.writelines(("testreport =", jsonout)) diff -r 4c6053a6b17d -r 0de4dfc9af0c tests/test-run-tests.t --- a/tests/test-run-tests.t Thu Jan 21 12:37:12 2016 -0800 +++ b/tests/test-run-tests.t Tue Jan 19 08:22:27 2016 -0800 @@ -494,13 +494,21 @@ Missing skips or blacklisted skips don't count as executed: $ echo test-failure.t > blacklist - $ rt --blacklist=blacklist \ + $ rt --blacklist=blacklist --json\ > test-failure.t test-bogus.t ss Skipped test-bogus.t: Doesn't exist Skipped test-failure.t: blacklisted # Ran 0 tests, 2 skipped, 0 warned, 0 failed. - + $ cat report.json + testreport ={ + "test-bogus.t": { + "result": "skip" + }, + "test-failure.t": { + "result": "skip" + } + } (no-eol) #if json test for --json