blob: ff98037adde4fec754d5653afdc24f3a1ad907cb [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::path::Path;
8use std::process::Command;
Michael Layzell53fc31a2017-06-07 09:21:53 -04009use std::u32;
10
David Tolnayc7a5d3d2017-06-04 12:11:05 -070011use self::walkdir::DirEntry;
12
Michael Layzell53fc31a2017-06-07 09:21:53 -040013macro_rules! errorf {
14 ($($tt:tt)*) => {
15 {
16 use ::std::io::Write;
17 write!(::std::io::stderr(), $($tt)*).unwrap();
18 }
19 };
20}
21
22pub mod parse;
23pub mod respan;
24
25pub fn check_min_stack() {
26 let min_stack_value = env::var("RUST_MIN_STACK")
27 .expect("RUST_MIN_STACK env var should be set since some tests require it.");
28 let min_stack_value: usize = min_stack_value.parse()
29 .expect("RUST_MIN_STACK env var should be set since some tests require it.");
30 assert!(min_stack_value >= 16000000);
31}
32
33/// Read the `ABORT_AFTER_FAILURE` environment variable, and parse it.
34pub fn abort_after() -> u32 {
35 if let Ok(s) = env::var("ABORT_AFTER_FAILURE") {
36 if let Ok(n) = s.parse::<u32>() {
37 return n;
38 }
39 }
40 u32::MAX
41}
42
43pub fn base_dir_filter(entry: &DirEntry) -> bool {
44 let path = entry.path();
45 if path.is_dir() {
46 return true; // otherwise walkdir does not visit the files
47 }
48 if path.extension().map(|e| e != "rs").unwrap_or(true) {
49 return false;
50 }
51 let path_string = path.to_string_lossy();
52 let path_string = if cfg!(windows) {
53 path_string.replace('\\', "/").into()
54 } else {
55 path_string
56 };
57 // TODO assert that parsing fails on the parse-fail cases
58 if path_string.starts_with("tests/rust/src/test/parse-fail") ||
59 path_string.starts_with("tests/rust/src/test/compile-fail") {
60 return false;
61 }
62
63 if path_string.starts_with("tests/rust/src/test/ui") {
64 let stderr_path = path.with_extension("stderr");
65 if stderr_path.exists() {
66 // Expected to fail in some way
67 return false;
68 }
69 }
70
Alex Crichtone21116f2017-08-28 09:56:12 -070071 // TODO: support `macro` definitions
72 if path_string.starts_with("tests/rust/src/test/run-pass/hygiene") {
73 return false;
74 }
75
Michael Layzell53fc31a2017-06-07 09:21:53 -040076 match path_string.as_ref() {
77 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070078 //
79 // let a = A { #[a] b: c };
Michael Layzell53fc31a2017-06-07 09:21:53 -040080 "tests/rust/src/librustc_data_structures/blake2b.rs" |
81 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070082 //
83 // enum A { B = #[a] 2 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040084 "tests/rust/src/test/incremental/hashes/enum_defs.rs" |
85 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070086 //
87 // { #![foo] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040088 "tests/rust/src/test/pretty/stmt_expr_attributes.rs" |
Michael Layzell53fc31a2017-06-07 09:21:53 -040089 // TODO better support for attributes
90 "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" |
91 // TODO weird glob import
Alex Crichton39567892017-08-28 09:55:44 -070092 //
93 // use ::*;
Michael Layzell53fc31a2017-06-07 09:21:53 -040094 "tests/rust/src/test/run-pass/import-glob-crate.rs" |
95 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070096 //
97 // impl Foo { #![a] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040098 "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" |
99 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -0700100 "tests/rust/src/test/run-pass/item-attributes.rs" |
Alex Crichtone21116f2017-08-28 09:56:12 -0700101 // TODO support lifetimes before traits
102 //
103 // Box<'foo + Bar>
104 "tests/rust/src/test/run-pass/trait-object-lifetime-first.rs" |
Alex Crichton39567892017-08-28 09:55:44 -0700105 // not actually a test case
106 "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" => false,
Michael Layzell53fc31a2017-06-07 09:21:53 -0400107 _ => true,
108 }
109}
110
Alex Crichton86374772017-07-07 20:39:28 -0700111pub fn clone_rust() {
112 if Path::new("tests/rust").is_dir() {
113 return
114 }
115
116 println!("cloning rust-lang/rust");
117 let result = Command::new("git")
118 .arg("clone")
119 .arg("https://github.com/rust-lang/rust")
120 .arg("tests/rust")
121 .status()
122 .unwrap();
123 println!("result: {}", result);
124 assert!(result.success());
125
126 println!("reset to known-good rev");
127 let result = Command::new("git")
128 .arg("reset")
129 .arg("--hard")
Alex Crichtone21116f2017-08-28 09:56:12 -0700130 .arg("eb8f2586ebd842dec49d3d7f50e49a985ab31493")
Alex Crichton86374772017-07-07 20:39:28 -0700131 .current_dir("tests/rust")
132 .status()
133 .unwrap();
134 println!("result: {}", result);
135 assert!(result.success());
136}