3 # Copyright 2015 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
13 # ignore-tidy-linelength
21 # usage: testparser.py [-h] [-p PARSER [PARSER ...]] -s SOURCE_DIR
23 # Parsers should read from stdin and return exit status 0 for a
24 # successful parse, and nonzero for an unsuccessful parse
26 parser = argparse.ArgumentParser()
27 parser.add_argument('-p', '--parser', nargs='+')
28 parser.add_argument('-s', '--source-dir', nargs=1, required=True)
29 args = parser.parse_args(sys.argv[1:])
34 for parser in args.parser:
37 devnull = open(os.devnull, 'w')
40 for base, dirs, files in os.walk(args.source_dir[0]):
41 for f in filter(lambda p: p.endswith('.rs'), files):
42 p = os.path.join(base, f)
43 parse_fail = 'parse-fail' in p
44 if sys.version_info.major == 3:
45 lines = open(p, encoding='utf-8').readlines()
47 lines = open(p).readlines()
48 if any('ignore-test' in line or 'ignore-lexer-test' in line for line in lines):
51 for parser in args.parser:
52 if subprocess.call(parser, stdin=open(p), stderr=subprocess.STDOUT, stdout=devnull) == 0:
62 parser_stats = ', '.join(['{}: {}'.format(parser, ok[parser]) for parser in args.parser])
63 sys.stdout.write("\033[K\r total: {}, {}, scanned {}"
64 .format(total, os.path.relpath(parser_stats), os.path.relpath(p)))
70 for parser in args.parser:
71 filename = os.path.basename(parser) + '.bad'
72 print("writing {} files that did not yield the correct result with {} to {}".format(len(bad[parser]), parser, filename))
73 with open(filename, "w") as f: