David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 1 | #![allow(dead_code)] |
| 2 | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 3 | extern crate walkdir; |
| 4 | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 5 | use std::env; |
Alex Crichton | 8637477 | 2017-07-07 20:39:28 -0700 | [diff] [blame] | 6 | use std::path::Path; |
| 7 | use std::process::Command; |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 8 | use std::u32; |
| 9 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 10 | use self::walkdir::DirEntry; |
| 11 | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 12 | macro_rules! errorf { |
| 13 | ($($tt:tt)*) => { |
| 14 | { |
| 15 | use ::std::io::Write; |
| 16 | write!(::std::io::stderr(), $($tt)*).unwrap(); |
| 17 | } |
| 18 | }; |
| 19 | } |
| 20 | |
| 21 | pub mod parse; |
| 22 | pub mod respan; |
| 23 | |
| 24 | pub 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. |
| 33 | pub 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 | |
| 42 | pub 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 Crichton | e21116f | 2017-08-28 09:56:12 -0700 | [diff] [blame^] | 70 | // TODO: support `macro` definitions |
| 71 | if path_string.starts_with("tests/rust/src/test/run-pass/hygiene") { |
| 72 | return false; |
| 73 | } |
| 74 | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 75 | match path_string.as_ref() { |
| 76 | // TODO better support for attributes |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 77 | // |
| 78 | // let a = A { #[a] b: c }; |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 79 | "tests/rust/src/librustc_data_structures/blake2b.rs" | |
| 80 | // TODO better support for attributes |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 81 | // |
| 82 | // enum A { B = #[a] 2 } |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 83 | "tests/rust/src/test/incremental/hashes/enum_defs.rs" | |
| 84 | // TODO better support for attributes |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 85 | // |
| 86 | // { #![foo] } |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 87 | "tests/rust/src/test/pretty/stmt_expr_attributes.rs" | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 88 | // TODO better support for attributes |
| 89 | "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" | |
| 90 | // TODO weird glob import |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 91 | // |
| 92 | // use ::*; |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 93 | "tests/rust/src/test/run-pass/import-glob-crate.rs" | |
| 94 | // TODO better support for attributes |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 95 | // |
| 96 | // impl Foo { #![a] } |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 97 | "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" | |
| 98 | // TODO better support for attributes |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 99 | "tests/rust/src/test/run-pass/item-attributes.rs" | |
Alex Crichton | e21116f | 2017-08-28 09:56:12 -0700 | [diff] [blame^] | 100 | // TODO support lifetimes before traits |
| 101 | // |
| 102 | // Box<'foo + Bar> |
| 103 | "tests/rust/src/test/run-pass/trait-object-lifetime-first.rs" | |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 104 | // not actually a test case |
| 105 | "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" => false, |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 106 | _ => true, |
| 107 | } |
| 108 | } |
| 109 | |
Alex Crichton | 8637477 | 2017-07-07 20:39:28 -0700 | [diff] [blame] | 110 | pub fn clone_rust() { |
| 111 | if Path::new("tests/rust").is_dir() { |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | println!("cloning rust-lang/rust"); |
| 116 | let result = Command::new("git") |
| 117 | .arg("clone") |
| 118 | .arg("https://github.com/rust-lang/rust") |
| 119 | .arg("tests/rust") |
| 120 | .status() |
| 121 | .unwrap(); |
| 122 | println!("result: {}", result); |
| 123 | assert!(result.success()); |
| 124 | |
| 125 | println!("reset to known-good rev"); |
| 126 | let result = Command::new("git") |
| 127 | .arg("reset") |
| 128 | .arg("--hard") |
Alex Crichton | e21116f | 2017-08-28 09:56:12 -0700 | [diff] [blame^] | 129 | .arg("eb8f2586ebd842dec49d3d7f50e49a985ab31493") |
Alex Crichton | 8637477 | 2017-07-07 20:39:28 -0700 | [diff] [blame] | 130 | .current_dir("tests/rust") |
| 131 | .status() |
| 132 | .unwrap(); |
| 133 | println!("result: {}", result); |
| 134 | assert!(result.success()); |
| 135 | } |