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 | |
| 70 | match path_string.as_ref() { |
| 71 | // TODO better support for attributes |
| 72 | "tests/rust/src/librustc_data_structures/blake2b.rs" | |
| 73 | // TODO better support for attributes |
| 74 | "tests/rust/src/test/incremental/hashes/enum_defs.rs" | |
| 75 | // TODO better support for attributes |
| 76 | "tests/rust/src/test/pretty/stmt_expr_attributes.rs" | |
| 77 | // not actually a test case |
| 78 | "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" | |
| 79 | // TODO better support for attributes |
| 80 | "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" | |
| 81 | // TODO weird glob import |
| 82 | "tests/rust/src/test/run-pass/import-glob-crate.rs" | |
| 83 | // TODO better support for attributes |
| 84 | "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" | |
| 85 | // TODO better support for attributes |
| 86 | "tests/rust/src/test/run-pass/item-attributes.rs" => false, |
| 87 | _ => true, |
| 88 | } |
| 89 | } |
| 90 | |
Alex Crichton | 8637477 | 2017-07-07 20:39:28 -0700 | [diff] [blame^] | 91 | pub fn clone_rust() { |
| 92 | if Path::new("tests/rust").is_dir() { |
| 93 | return |
| 94 | } |
| 95 | |
| 96 | println!("cloning rust-lang/rust"); |
| 97 | let result = Command::new("git") |
| 98 | .arg("clone") |
| 99 | .arg("https://github.com/rust-lang/rust") |
| 100 | .arg("tests/rust") |
| 101 | .status() |
| 102 | .unwrap(); |
| 103 | println!("result: {}", result); |
| 104 | assert!(result.success()); |
| 105 | |
| 106 | println!("reset to known-good rev"); |
| 107 | let result = Command::new("git") |
| 108 | .arg("reset") |
| 109 | .arg("--hard") |
| 110 | .arg("ddc5d7bd4b9ea3e8a8ccf82cb443e950be311d61") |
| 111 | .current_dir("tests/rust") |
| 112 | .status() |
| 113 | .unwrap(); |
| 114 | println!("result: {}", result); |
| 115 | assert!(result.success()); |
| 116 | } |