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