changeset 27927:0de4dfc9af0c stable

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.
author Laurent Charignon <lcharignon@fb.com>
date Tue, 19 Jan 2016 08:22:27 -0800
parents 4c6053a6b17d
children c0f11347b107
files tests/run-tests.py tests/test-run-tests.t
diffstat 2 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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))
--- 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