David Tolnay | 5553501 | 2018-01-05 16:39:23 -0800 | [diff] [blame] | 1 | // Copyright 2018 Syn Developers |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 8 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 9 | #![allow(dead_code)] |
| 10 | |
Nika Layzell | a2a1a4a | 2017-11-19 11:33:17 -0500 | [diff] [blame] | 11 | extern crate syntax; |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 12 | extern crate walkdir; |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 13 | |
David Tolnay | ee97dbf | 2017-11-19 14:24:38 -0800 | [diff] [blame] | 14 | use std; |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 15 | use std::env; |
Alex Crichton | 8637477 | 2017-07-07 20:39:28 -0700 | [diff] [blame] | 16 | use std::process::Command; |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 17 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 18 | use self::walkdir::DirEntry; |
| 19 | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 20 | pub mod parse; |
| 21 | pub mod respan; |
| 22 | |
| 23 | pub fn check_min_stack() { |
| 24 | let min_stack_value = env::var("RUST_MIN_STACK") |
| 25 | .expect("RUST_MIN_STACK env var should be set since some tests require it."); |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 26 | let min_stack_value: usize = min_stack_value |
| 27 | .parse() |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 28 | .expect("RUST_MIN_STACK env var should be set since some tests require it."); |
David Tolnay | 3cede94 | 2017-12-26 12:29:24 -0500 | [diff] [blame] | 29 | assert!(min_stack_value >= 16_000_000); |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /// Read the `ABORT_AFTER_FAILURE` environment variable, and parse it. |
David Tolnay | ee97dbf | 2017-11-19 14:24:38 -0800 | [diff] [blame] | 33 | pub fn abort_after() -> usize { |
| 34 | match env::var("ABORT_AFTER_FAILURE") { |
| 35 | Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"), |
| 36 | Err(_) => std::usize::MAX, |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 37 | } |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | pub fn base_dir_filter(entry: &DirEntry) -> bool { |
| 41 | let path = entry.path(); |
| 42 | if path.is_dir() { |
| 43 | return true; // otherwise walkdir does not visit the files |
| 44 | } |
| 45 | if path.extension().map(|e| e != "rs").unwrap_or(true) { |
| 46 | return false; |
| 47 | } |
| 48 | let path_string = path.to_string_lossy(); |
| 49 | let path_string = if cfg!(windows) { |
| 50 | path_string.replace('\\', "/").into() |
| 51 | } else { |
| 52 | path_string |
| 53 | }; |
| 54 | // TODO assert that parsing fails on the parse-fail cases |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 55 | if path_string.starts_with("tests/rust/src/test/parse-fail") |
| 56 | || path_string.starts_with("tests/rust/src/test/compile-fail") |
| 57 | { |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 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 Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 71 | // |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 72 | // { #![foo] } |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 73 | "tests/rust/src/test/pretty/stmt_expr_attributes.rs" | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 74 | // TODO better support for attributes |
| 75 | "tests/rust/src/test/run-pass/cfg_stmt_expr.rs" | |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 76 | // TODO better support for attributes |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 77 | // |
| 78 | // impl Foo { #![a] } |
Michael Layzell | 53fc31a | 2017-06-07 09:21:53 -0400 | [diff] [blame] | 79 | "tests/rust/src/test/run-pass/inner-attrs-on-impl.rs" | |
| 80 | // TODO better support for attributes |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 81 | "tests/rust/src/test/run-pass/item-attributes.rs" | |
David Tolnay | b0d2141 | 2017-12-19 21:11:47 -0800 | [diff] [blame] | 82 | // TODO feature(use_nested_groups) |
| 83 | // |
| 84 | // use a::{B, D::{self, *, g::H}}; |
| 85 | "tests/rust/src/test/run-pass/use-nested-groups.rs" | |
David Tolnay | 8701a5c | 2017-12-28 23:31:10 -0500 | [diff] [blame] | 86 | // Deprecated placement syntax |
| 87 | "tests/rust/src/test/run-pass/new-box-syntax.rs" | |
| 88 | // Deprecated placement syntax |
| 89 | "tests/rust/src/test/run-pass/placement-in-syntax.rs" | |
David Tolnay | 5dec63d | 2018-01-18 23:36:12 -0800 | [diff] [blame^] | 90 | // TODO feature(extern_in_paths) |
| 91 | // |
| 92 | // use extern::xcrate; |
| 93 | "tests/rust/src/test/run-pass/rfc-2126-extern-absolute-paths/extern.rs" | |
Alex Crichton | 3956789 | 2017-08-28 09:55:44 -0700 | [diff] [blame] | 94 | // not actually a test case |
| 95 | "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] | 96 | _ => true, |
| 97 | } |
| 98 | } |
| 99 | |
Alex Crichton | 8637477 | 2017-07-07 20:39:28 -0700 | [diff] [blame] | 100 | pub fn clone_rust() { |
David Tolnay | ed8716e | 2017-12-25 21:49:39 -0500 | [diff] [blame] | 101 | let result = Command::new("tests/clone.sh").status().unwrap(); |
Alex Crichton | 8637477 | 2017-07-07 20:39:28 -0700 | [diff] [blame] | 102 | println!("result: {}", result); |
| 103 | assert!(result.success()); |
| 104 | } |