7 from webkitpy
.common
.host
import Host
8 from webkitpy
.layout_tests
.port
import platform_options
, configuration_options
12 parser
= optparse
.OptionParser(usage
='%prog [path-to-results.json]')
13 parser
.add_option('--failures', action
='store_true',
14 help='show failing tests')
15 parser
.add_option('--flakes', action
='store_true',
16 help='show flaky tests')
17 parser
.add_option('--expected', action
='store_true',
18 help='include expected results along with unexpected')
19 parser
.add_option('--passes', action
='store_true',
20 help='show passing tests')
21 parser
.add_option('--ignored-failures-path', action
='store',
22 help='ignore failures seen in a previous run')
23 parser
.add_options(platform_options())
24 parser
.add_options(configuration_options())
25 options
, args
= parser
.parse_args(argv
)
30 txt
= sys
.stdin
.read()
31 elif os
.path
.exists(args
[0]):
32 with
open(args
[0], 'r') as fp
:
35 print >> sys
.stderr
, "file not found: %s" % args
[0]
38 txt
= host
.filesystem
.read_text_file(host
.filesystem
.join(host
.port_factory
.get(options
=options
).results_directory(), 'full_results.json'))
40 if txt
.startswith('ADD_RESULTS(') and txt
.endswith(');'):
41 txt
= txt
[12:-2] # ignore optional JSONP wrapper
42 results
= json
.loads(txt
)
44 passes
, failures
, flakes
= decode_results(results
, options
.expected
)
48 tests_to_print
+= passes
.keys()
50 tests_to_print
+= failures
.keys()
52 tests_to_print
+= flakes
.keys()
53 print "\n".join(sorted(tests_to_print
))
55 if options
.ignored_failures_path
:
56 with
open(options
.ignored_failures_path
, 'r') as fp
:
58 if txt
.startswith('ADD_RESULTS(') and txt
.endswith(');'):
59 txt
= txt
[12:-2] # ignore optional JSONP wrapper
60 results
= json
.loads(txt
)
61 _
, ignored_failures
, _
= decode_results(results
, options
.expected
)
62 new_failures
= set(failures
.keys()) - set(ignored_failures
.keys())
65 print "\n".join(sorted(new_failures
))
68 print "Ignored failures:"
69 print "\n".join(sorted(ignored_failures
.keys()))
75 def decode_results(results
, include_expected
=False):
76 tests
= convert_trie_to_flat_paths(results
['tests'])
80 for (test
, result
) in tests
.iteritems():
81 if include_expected
or result
.get('is_unexpected'):
82 actual_results
= result
['actual'].split()
83 expected_results
= result
['expected'].split()
84 if len(actual_results
) > 1:
85 if actual_results
[1] in expected_results
:
86 flakes
[test
] = actual_results
[0]
88 # We report the first failure type back, even if the second
90 failures
[test
] = actual_results
[0]
91 elif actual_results
[0] == 'PASS':
94 failures
[test
] = actual_results
[0]
96 return (passes
, failures
, flakes
)
99 def convert_trie_to_flat_paths(trie
, prefix
=None):
100 # Cloned from webkitpy.layout_tests.layout_package.json_results_generator
101 # so that this code can stand alone.
103 for name
, data
in trie
.iteritems():
105 name
= prefix
+ "/" + name
107 if len(data
) and not "actual" in data
and not "expected" in data
:
108 result
.update(convert_trie_to_flat_paths(data
, name
))
115 if __name__
== '__main__':
116 sys
.exit(main(sys
.argv
[1:]))