blob: 25a88242143aed3129ad5ea26cae62d0e6e1195a [file] [log] [blame]
David Tolnayc7a5d3d2017-06-04 12:11:05 -07001#![allow(dead_code)]
2
Michael Layzell53fc31a2017-06-07 09:21:53 -04003extern crate walkdir;
4
Michael Layzell53fc31a2017-06-07 09:21:53 -04005use std::env;
Alex Crichton86374772017-07-07 20:39:28 -07006use std::path::Path;
7use std::process::Command;
Michael Layzell53fc31a2017-06-07 09:21:53 -04008use std::u32;
9
David Tolnayc7a5d3d2017-06-04 12:11:05 -070010use self::walkdir::DirEntry;
11
Michael Layzell53fc31a2017-06-07 09:21:53 -040012macro_rules! errorf {
13 ($($tt:tt)*) => {
14 {
15 use ::std::io::Write;
16 write!(::std::io::stderr(), $($tt)*).unwrap();
17 }
18 };
19}
20
21pub mod parse;
22pub mod respan;
23
24pub fn check_min_stack() {
25 let min_stack_value = env::var("RUST_MIN_STACK")
26 .expect("RUST_MIN_STACK env var should be set since some tests require it.");
27 let min_stack_value: usize = min_stack_value.parse()
28 .expect("RUST_MIN_STACK env var should be set since some tests require it.");
29 assert!(min_stack_value >= 16000000);
30}
31
32/// Read the `ABORT_AFTER_FAILURE` environment variable, and parse it.
33pub fn abort_after() -> u32 {
34 if let Ok(s) = env::var("ABORT_AFTER_FAILURE") {
35 if let Ok(n) = s.parse::<u32>() {
36 return n;
37 }
38 }
39 u32::MAX
40}
41
42pub fn base_dir_filter(entry: &DirEntry) -> bool {
43 let path = entry.path();
44 if path.is_dir() {
45 return true; // otherwise walkdir does not visit the files
46 }
47 if path.extension().map(|e| e != "rs").unwrap_or(true) {
48 return false;
49 }
50 let path_string = path.to_string_lossy();
51 let path_string = if cfg!(windows) {
52 path_string.replace('\\', "/").into()
53 } else {
54 path_string
55 };
56 // TODO assert that parsing fails on the parse-fail cases
57 if path_string.starts_with("tests/rust/src/test/parse-fail") ||
58 path_string.starts_with("tests/rust/src/test/compile-fail") {
59 return false;
60 }
61
62 if path_string.starts_with("tests/rust/src/test/ui") {
63 let stderr_path = path.with_extension("stderr");
64 if stderr_path.exists() {
65 // Expected to fail in some way
66 return false;
67 }
68 }
69
70 match path_string.as_ref() {
71 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070072 //
73 // let a = A { #[a] b: c };
Michael Layzell53fc31a2017-06-07 09:21:53 -040074 "tests/rust/src/librustc_data_structures/blake2b.rs" |
75 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070076 //
77 // enum A { B = #[a] 2 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040078 "tests/rust/src/test/incremental/hashes/enum_defs.rs" |
79 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070080 //
81 // { #![foo] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040082 "tests/rust/src/test/pretty/stmt_expr_attributes.rs" |
Michael Layzell53fc31a2017-06-07 09:21:53 -040083 // TODO better support for attributes
84 "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" |
85 // TODO weird glob import
Alex Crichton39567892017-08-28 09:55:44 -070086 //
87 // use ::*;
Michael Layzell53fc31a2017-06-07 09:21:53 -040088 "tests/rust/src/test/run-pass/import-glob-crate.rs" |
89 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070090 //
91 // impl Foo { #![a] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040092 "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" |
93 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070094 "tests/rust/src/test/run-pass/item-attributes.rs" |
95 // not actually a test case
96 "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" => false,
Michael Layzell53fc31a2017-06-07 09:21:53 -040097 _ => true,
98 }
99}
100
Alex Crichton86374772017-07-07 20:39:28 -0700101pub fn clone_rust() {
102 if Path::new("tests/rust").is_dir() {
103 return
104 }
105
106 println!("cloning rust-lang/rust");
107 let result = Command::new("git")
108 .arg("clone")
109 .arg("https://github.com/rust-lang/rust")
110 .arg("tests/rust")
111 .status()
112 .unwrap();
113 println!("result: {}", result);
114 assert!(result.success());
115
116 println!("reset to known-good rev");
117 let result = Command::new("git")
118 .arg("reset")
119 .arg("--hard")
120 .arg("ddc5d7bd4b9ea3e8a8ccf82cb443e950be311d61")
121 .current_dir("tests/rust")
122 .status()
123 .unwrap();
124 println!("result: {}", result);
125 assert!(result.success());
126}