blob: 4665ef7d02cbcee2f9ca380331f50f3d2d83e46a [file] [log] [blame]
David Tolnayc7a5d3d2017-06-04 12:11:05 -07001#![allow(dead_code)]
2
Nika Layzella2a1a4a2017-11-19 11:33:17 -05003extern crate syntax;
David Tolnay51382052017-12-27 13:46:21 -05004extern crate walkdir;
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.");
David Tolnay51382052017-12-27 13:46:21 -050028 let min_stack_value: usize = min_stack_value
29 .parse()
Michael Layzell53fc31a2017-06-07 09:21:53 -040030 .expect("RUST_MIN_STACK env var should be set since some tests require it.");
David Tolnay3cede942017-12-26 12:29:24 -050031 assert!(min_stack_value >= 16_000_000);
Michael Layzell53fc31a2017-06-07 09:21:53 -040032}
33
34/// Read the `ABORT_AFTER_FAILURE` environment variable, and parse it.
David Tolnayee97dbf2017-11-19 14:24:38 -080035pub fn abort_after() -> usize {
36 match env::var("ABORT_AFTER_FAILURE") {
37 Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"),
38 Err(_) => std::usize::MAX,
Michael Layzell53fc31a2017-06-07 09:21:53 -040039 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040040}
41
42pub 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
David Tolnay51382052017-12-27 13:46:21 -050057 if path_string.starts_with("tests/rust/src/test/parse-fail")
58 || path_string.starts_with("tests/rust/src/test/compile-fail")
59 {
Michael Layzell53fc31a2017-06-07 09:21:53 -040060 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
71 match path_string.as_ref() {
72 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070073 //
74 // let a = A { #[a] b: c };
Michael Layzell53fc31a2017-06-07 09:21:53 -040075 "tests/rust/src/librustc_data_structures/blake2b.rs" |
76 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070077 //
78 // enum A { B = #[a] 2 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040079 "tests/rust/src/test/incremental/hashes/enum_defs.rs" |
80 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070081 //
82 // { #![foo] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040083 "tests/rust/src/test/pretty/stmt_expr_attributes.rs" |
Michael Layzell53fc31a2017-06-07 09:21:53 -040084 // TODO better support for attributes
85 "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" |
86 // TODO weird glob import
Alex Crichton39567892017-08-28 09:55:44 -070087 //
88 // use ::*;
Michael Layzell53fc31a2017-06-07 09:21:53 -040089 "tests/rust/src/test/run-pass/import-glob-crate.rs" |
90 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070091 //
92 // impl Foo { #![a] }
Michael Layzell53fc31a2017-06-07 09:21:53 -040093 "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" |
94 // TODO better support for attributes
Alex Crichton39567892017-08-28 09:55:44 -070095 "tests/rust/src/test/run-pass/item-attributes.rs" |
Alex Crichtone21116f2017-08-28 09:56:12 -070096 // TODO support lifetimes before traits
97 //
98 // Box<'foo + Bar>
99 "tests/rust/src/test/run-pass/trait-object-lifetime-first.rs" |
David Tolnayb0d21412017-12-19 21:11:47 -0800100 // TODO feature(use_nested_groups)
101 //
102 // use a::{B, D::{self, *, g::H}};
103 "tests/rust/src/test/run-pass/use-nested-groups.rs" |
David Tolnay8701a5c2017-12-28 23:31:10 -0500104 // Deprecated placement syntax
105 "tests/rust/src/test/run-pass/new-box-syntax.rs" |
106 // Deprecated placement syntax
107 "tests/rust/src/test/run-pass/placement-in-syntax.rs" |
Alex Crichton39567892017-08-28 09:55:44 -0700108 // not actually a test case
109 "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" => false,
Michael Layzell53fc31a2017-06-07 09:21:53 -0400110 _ => true,
111 }
112}
113
Alex Crichton86374772017-07-07 20:39:28 -0700114pub fn clone_rust() {
David Tolnayed8716e2017-12-25 21:49:39 -0500115 let result = Command::new("tests/clone.sh").status().unwrap();
Alex Crichton86374772017-07-07 20:39:28 -0700116 println!("result: {}", result);
117 assert!(result.success());
118}