Patchwork [STABLE] run-tests: fix crash when --json and --blacklist are both used (issue5050)

login
register
mail settings
Submitter Laurent Charignon
Date Jan. 19, 2016, 4:22 p.m.
Message ID <def9add370dc6eb1c850.1453220576@dev5073.prn1.facebook.com>
Download mbox | patch
Permalink /patch/12833/
State Accepted
Headers show

Comments

Laurent Charignon - Jan. 19, 2016, 4:22 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1453220547 28800
#      Tue Jan 19 08:22:27 2016 -0800
# Branch stable
# Node ID def9add370dc6eb1c850edc71f40fb0a60ea511f
# Parent  3203dfe341f962e33256d6475fc3585563db78ad
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.
Pierre-Yves David - Jan. 22, 2016, 7:09 p.m.
On 01/19/2016 08:22 AM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1453220547 28800
> #      Tue Jan 19 08:22:27 2016 -0800
> # Branch stable
> # Node ID def9add370dc6eb1c850edc71f40fb0a60ea511f
> # Parent  3203dfe341f962e33256d6475fc3585563db78ad
> run-tests: fix crash when --json and --blacklist are both used (issue5050)

Pushed to the clowncopter, Thanks.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -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 --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -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