blob: 451d2de34ee4ed2ac74f1176a15c1e0ec349953a [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;
Nika Layzella2a1a4a2017-11-19 11:33:17 -05004extern crate syntax;
Michael Layzell53fc31a2017-06-07 09:21:53 -04005
Michael Layzell53fc31a2017-06-07 09:21:53 -04006use std::env;
Alex Crichton86374772017-07-07 20:39:28 -07007use 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
Alex Crichtone21116f2017-08-28 09:56:12 -070070 // TODO: support `macro` definitions
71 if path_string.starts_with("tests/rust/src/test/run-pass/hygiene") {
72 return false;
73 }
74
Michael Layzell53fc31a2017-06-07 09:21:53 -040075 match path_string.as_ref() {
76 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070077 //
78 // let a = A { #[a] b: c };
Michael Layzell53fc31a2017-06-07 09:21:53 -040079 "tests/rust/src/librustc_data_structures/blake2b.rs" |
80 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070081 //
82 // enum A { B = #[a] 2 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040083 "tests/rust/src/test/incremental/hashes/enum_defs.rs" |
84 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070085 //
86 // { #![foo] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040087 "tests/rust/src/test/pretty/stmt_expr_attributes.rs" |
Michael Layzell53fc31a2017-06-07 09:21:53 -040088 // TODO better support for attributes
89 "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" |
90 // TODO weird glob import
Alex Crichton39567892017-08-28 09:55:44 -070091 //
92 // use ::*;
Michael Layzell53fc31a2017-06-07 09:21:53 -040093 "tests/rust/src/test/run-pass/import-glob-crate.rs" |
94 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070095 //
96 // impl Foo { #![a] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040097 "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" |
98 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070099 "tests/rust/src/test/run-pass/item-attributes.rs" |
Alex Crichtone21116f2017-08-28 09:56:12 -0700100 // TODO support lifetimes before traits
101 //
102 // Box<'foo + Bar>
103 "tests/rust/src/test/run-pass/trait-object-lifetime-first.rs" |
Alex Crichton39567892017-08-28 09:55:44 -0700104 // not actually a test case
105 "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" => false,
Michael Layzell53fc31a2017-06-07 09:21:53 -0400106 _ => true,
107 }
108}
109
Alex Crichton86374772017-07-07 20:39:28 -0700110pub fn clone_rust() {
David Tolnay11e6da92017-11-19 11:57:24 -0800111 let result = Command::new("tests/rust/clone.sh").status().unwrap();
Alex Crichton86374772017-07-07 20:39:28 -0700112 println!("result: {}", result);
113 assert!(result.success());
114}