blob: 4e5fc4757dbeaed66eb88b6bc56f1a1b263a35ad [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;
David Tolnayec5b52e2017-12-17 22:42:32 -080016 let stderr = ::std::io::stderr();
17 write!(stderr.lock(), $($tt)*).unwrap();
Michael Layzell53fc31a2017-06-07 09:21:53 -040018 }
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.
David Tolnayee97dbf2017-11-19 14:24:38 -080034pub fn abort_after() -> usize {
35 match env::var("ABORT_AFTER_FAILURE") {
36 Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"),
37 Err(_) => std::usize::MAX,
Michael Layzell53fc31a2017-06-07 09:21:53 -040038 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040039}
40
41pub fn base_dir_filter(entry: &DirEntry) -> bool {
42 let path = entry.path();
43 if path.is_dir() {
44 return true; // otherwise walkdir does not visit the files
45 }
46 if path.extension().map(|e| e != "rs").unwrap_or(true) {
47 return false;
48 }
49 let path_string = path.to_string_lossy();
50 let path_string = if cfg!(windows) {
51 path_string.replace('\\', "/").into()
52 } else {
53 path_string
54 };
55 // TODO assert that parsing fails on the parse-fail cases
56 if path_string.starts_with("tests/rust/src/test/parse-fail") ||
57 path_string.starts_with("tests/rust/src/test/compile-fail") {
58 return false;
59 }
60
61 if path_string.starts_with("tests/rust/src/test/ui") {
62 let stderr_path = path.with_extension("stderr");
63 if stderr_path.exists() {
64 // Expected to fail in some way
65 return false;
66 }
67 }
68
69 match path_string.as_ref() {
70 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070071 //
72 // let a = A { #[a] b: c };
Michael Layzell53fc31a2017-06-07 09:21:53 -040073 "tests/rust/src/librustc_data_structures/blake2b.rs" |
74 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070075 //
76 // enum A { B = #[a] 2 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040077 "tests/rust/src/test/incremental/hashes/enum_defs.rs" |
78 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070079 //
80 // { #![foo] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040081 "tests/rust/src/test/pretty/stmt_expr_attributes.rs" |
Michael Layzell53fc31a2017-06-07 09:21:53 -040082 // TODO better support for attributes
83 "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" |
84 // TODO weird glob import
Alex Crichton39567892017-08-28 09:55:44 -070085 //
86 // use ::*;
Michael Layzell53fc31a2017-06-07 09:21:53 -040087 "tests/rust/src/test/run-pass/import-glob-crate.rs" |
88 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070089 //
90 // impl Foo { #![a] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040091 "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" |
92 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070093 "tests/rust/src/test/run-pass/item-attributes.rs" |
Alex Crichtone21116f2017-08-28 09:56:12 -070094 // TODO support lifetimes before traits
95 //
96 // Box<'foo + Bar>
97 "tests/rust/src/test/run-pass/trait-object-lifetime-first.rs" |
David Tolnayb0d21412017-12-19 21:11:47 -080098 // TODO feature(use_nested_groups)
99 //
100 // use a::{B, D::{self, *, g::H}};
101 "tests/rust/src/test/run-pass/use-nested-groups.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 Tolnayed8716e2017-12-25 21:49:39 -0500109 let result = Command::new("tests/clone.sh").status().unwrap();
Alex Crichton86374772017-07-07 20:39:28 -0700110 println!("result: {}", result);
111 assert!(result.success());
112}