blob: ecf4f881da6f7130864bde63354924f6a6e3506c [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
David Tolnayee97dbf2017-11-19 14:24:38 -08006use std;
Michael Layzell53fc31a2017-06-07 09:21:53 -04007use std::env;
Alex Crichton86374772017-07-07 20:39:28 -07008use std::process::Command;
Michael Layzell53fc31a2017-06-07 09:21:53 -04009
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.
David Tolnayee97dbf2017-11-19 14:24:38 -080033pub fn abort_after() -> usize {
34 match env::var("ABORT_AFTER_FAILURE") {
35 Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"),
36 Err(_) => std::usize::MAX,
Michael Layzell53fc31a2017-06-07 09:21:53 -040037 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040038}
39
40pub fn base_dir_filter(entry: &DirEntry) -> bool {
41 let path = entry.path();
42 if path.is_dir() {
43 return true; // otherwise walkdir does not visit the files
44 }
45 if path.extension().map(|e| e != "rs").unwrap_or(true) {
46 return false;
47 }
48 let path_string = path.to_string_lossy();
49 let path_string = if cfg!(windows) {
50 path_string.replace('\\', "/").into()
51 } else {
52 path_string
53 };
54 // TODO assert that parsing fails on the parse-fail cases
55 if path_string.starts_with("tests/rust/src/test/parse-fail") ||
56 path_string.starts_with("tests/rust/src/test/compile-fail") {
57 return false;
58 }
59
60 if path_string.starts_with("tests/rust/src/test/ui") {
61 let stderr_path = path.with_extension("stderr");
62 if stderr_path.exists() {
63 // Expected to fail in some way
64 return false;
65 }
66 }
67
Alex Crichtone21116f2017-08-28 09:56:12 -070068 // TODO: support `macro` definitions
69 if path_string.starts_with("tests/rust/src/test/run-pass/hygiene") {
70 return false;
71 }
72
Michael Layzell53fc31a2017-06-07 09:21:53 -040073 match path_string.as_ref() {
74 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070075 //
76 // let a = A { #[a] b: c };
Michael Layzell53fc31a2017-06-07 09:21:53 -040077 "tests/rust/src/librustc_data_structures/blake2b.rs" |
78 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070079 //
80 // enum A { B = #[a] 2 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040081 "tests/rust/src/test/incremental/hashes/enum_defs.rs" |
82 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070083 //
84 // { #![foo] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040085 "tests/rust/src/test/pretty/stmt_expr_attributes.rs" |
Michael Layzell53fc31a2017-06-07 09:21:53 -040086 // TODO better support for attributes
87 "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" |
88 // TODO weird glob import
Alex Crichton39567892017-08-28 09:55:44 -070089 //
90 // use ::*;
Michael Layzell53fc31a2017-06-07 09:21:53 -040091 "tests/rust/src/test/run-pass/import-glob-crate.rs" |
92 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070093 //
94 // impl Foo { #![a] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040095 "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" |
96 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070097 "tests/rust/src/test/run-pass/item-attributes.rs" |
Alex Crichtone21116f2017-08-28 09:56:12 -070098 // TODO support lifetimes before traits
99 //
100 // Box<'foo + Bar>
101 "tests/rust/src/test/run-pass/trait-object-lifetime-first.rs" |
Alex Crichton39567892017-08-28 09:55:44 -0700102 // not actually a test case
103 "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" => false,
Michael Layzell53fc31a2017-06-07 09:21:53 -0400104 _ => true,
105 }
106}
107
Alex Crichton86374772017-07-07 20:39:28 -0700108pub fn clone_rust() {
David Tolnay11e6da92017-11-19 11:57:24 -0800109 let result = Command::new("tests/rust/clone.sh").status().unwrap();
Alex Crichton86374772017-07-07 20:39:28 -0700110 println!("result: {}", result);
111 assert!(result.success());
112}