PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/etc/combine-tests.py

http://github.com/jruderman/rust
Python | 70 lines | 56 code | 10 blank | 4 comment | 24 complexity | 85c06a891d1d1b1341be1792367f946c MD5 | raw file
 1#!/usr/bin/env python
 2
 3# this combines all the working run-pass tests into a single large crate so we
 4# can run it "fast": spawning zillions of windows processes is our major build
 5# bottleneck (and it doesn't hurt to run faster on other platforms as well).
 6
 7import sys, os, re, codecs
 8
 9def scrub(b):
10  if sys.version_info >= (3,) and type(b) == bytes:
11    return b.decode('ascii')
12  else:
13    return b
14
15src_dir = scrub(os.getenv("CFG_SRC_DIR"))
16if not src_dir:
17  raise Exception("missing env var CFG_SRC_DIR")
18
19run_pass = os.path.join(src_dir, "src", "test", "run-pass")
20run_pass = os.path.abspath(run_pass)
21stage2_tests = []
22take_args = {}
23
24for t in os.listdir(run_pass):
25    if t.endswith(".rs") and not (
26      t.startswith(".") or t.startswith("#") or t.startswith("~")):
27        f = codecs.open(os.path.join(run_pass, t), "r", "utf8")
28        s = f.read()
29        if not ("xfail-test" in s or
30                "xfail-fast" in s or
31                "xfail-win32" in s):
32            stage2_tests.append(t)
33            if "main(args: ~[~str])" in s:
34                take_args[t] = True
35        f.close()
36
37stage2_tests.sort()
38
39c = open("tmp/run_pass_stage2.rc", "w")
40i = 0
41c.write("// AUTO-GENERATED FILE: DO NOT EDIT\n")
42c.write("#[link(name=\"run_pass_stage2\", vers=\"0.1\")];\n")
43for t in stage2_tests:
44    p = os.path.join(run_pass, t)
45    p = p.replace("\\", "\\\\")
46    c.write("#[path = \"%s\"]" % p);
47    c.write("mod t_%d;\n" % i)
48    i += 1
49c.close()
50
51
52d = open("tmp/run_pass_stage2_driver.rs", "w")
53d.write("// AUTO-GENERATED FILE: DO NOT EDIT\n")
54d.write("use std;\n")
55d.write("use run_pass_stage2;\n")
56d.write("import run_pass_stage2::*;\n")
57d.write("import io::writer_util;\n");
58d.write("fn main() {\n");
59d.write("    let out = io::stdout();\n");
60i = 0
61for t in stage2_tests:
62    p = os.path.join("test", "run-pass", t)
63    p = p.replace("\\", "\\\\")
64    d.write("    out.write_str(~\"run-pass [stage2]: %s\\n\");\n" % p)
65    if t in take_args:
66        d.write("    t_%d::main(~[~\"arg0\"]);\n" % i)
67    else:
68        d.write("    t_%d::main();\n" % i)
69    i += 1
70d.write("}\n")