blob: f252884b53040b3e9d2bf2750a152f4fac1b9c08 [file] [log] [blame]
#!/usr/bin/python
import json
import optparse
import os
import sys
def main(argv):
parser = optparse.OptionParser(usage='%prog [path-to-results.json]')
parser.add_option('--failures', action='store_true',
help='show failing tests')
parser.add_option('--flakes', action='store_true',
help='show flaky tests')
parser.add_option('--expected', action='store_true',
help='include expected results along with unexpected')
parser.add_option('--passes', action='store_true',
help='show passing tests')
options, args = parser.parse_args(argv)
if args and args[0] != '-':
if os.path.exists(args[0]):
with open(args[0], 'r') as fp:
txt = fp.read()
else:
print >> sys.stderr, "file not found: %s" % args[0]
sys.exit(1)
else:
txt = sys.stdin.read()
if txt.startswith('ADD_RESULTS(') and txt.endswith(');'):
txt = txt[12:-2] # ignore optional JSONP wrapper
results = json.loads(txt)
passes, failures, flakes = decode_results(results, options.expected)
tests_to_print = []
if options.passes:
tests_to_print += passes.keys()
if options.failures:
tests_to_print += failures.keys()
if options.flakes:
tests_to_print += flakes.keys()
print "\n".join(sorted(tests_to_print))
def decode_results(results, include_expected=False):
tests = convert_trie_to_flat_paths(results['tests'])
failures = {}
flakes = {}
passes = {}
for (test, result) in tests.iteritems():
if include_expected or result.get('is_unexpected'):
actual_result = result['actual']
if ' PASS' in actual_result:
flakes[test] = actual_result
elif actual_result == 'PASS':
passes[test] = result
else:
failures[test] = actual_result
return (passes, failures, flakes)
def convert_trie_to_flat_paths(trie, prefix=None):
# Cloned from webkitpy.layout_tests.layout_package.json_results_generator
# so that this code can stand alone.
result = {}
for name, data in trie.iteritems():
if prefix:
name = prefix + "/" + name
if len(data) and not "actual" in data and not "expected" in data:
result.update(convert_trie_to_flat_paths(data, name))
else:
result[name] = data
return result
if __name__ == '__main__':
main(sys.argv[1:])