blob: ee5eee471d47f8a535daf18b746961ef1b4fea6c [file] [log] [blame]
David Tolnay55535012018-01-05 16:39:23 -08001// 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 Tolnayc7a5d3d2017-06-04 12:11:05 -07009#![allow(dead_code)]
10
Nika Layzella2a1a4a2017-11-19 11:33:17 -050011extern crate syntax;
David Tolnay51382052017-12-27 13:46:21 -050012extern crate walkdir;
Michael Layzell53fc31a2017-06-07 09:21:53 -040013
David Tolnayee97dbf2017-11-19 14:24:38 -080014use std;
Michael Layzell53fc31a2017-06-07 09:21:53 -040015use std::env;
Alex Crichton86374772017-07-07 20:39:28 -070016use std::process::Command;
Michael Layzell53fc31a2017-06-07 09:21:53 -040017
David Tolnayc7a5d3d2017-06-04 12:11:05 -070018use self::walkdir::DirEntry;
19
Michael Layzell53fc31a2017-06-07 09:21:53 -040020pub mod parse;
21pub mod respan;
22
23pub 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 Tolnay51382052017-12-27 13:46:21 -050026 let min_stack_value: usize = min_stack_value
27 .parse()
Michael Layzell53fc31a2017-06-07 09:21:53 -040028 .expect("RUST_MIN_STACK env var should be set since some tests require it.");
David Tolnay3cede942017-12-26 12:29:24 -050029 assert!(min_stack_value >= 16_000_000);
Michael Layzell53fc31a2017-06-07 09:21:53 -040030}
31
32/// Read the `ABORT_AFTER_FAILURE` environment variable, and parse it.
David Tolnayee97dbf2017-11-19 14:24:38 -080033pub 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 Layzell53fc31a2017-06-07 09:21:53 -040037 }
Michael Layzell53fc31a2017-06-07 09:21:53 -040038}
39
40pub 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 Tolnay51382052017-12-27 13:46:21 -050055 if path_string.starts_with("tests/rust/src/test/parse-fail")
56 || path_string.starts_with("tests/rust/src/test/compile-fail")
57 {
Michael Layzell53fc31a2017-06-07 09:21:53 -040058 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" |
David Tolnay8701a5c2017-12-28 23:31:10 -0500102 // Deprecated placement syntax
103 "tests/rust/src/test/run-pass/new-box-syntax.rs" |
104 // Deprecated placement syntax
105 "tests/rust/src/test/run-pass/placement-in-syntax.rs" |
Alex Crichton39567892017-08-28 09:55:44 -0700106 // not actually a test case
107 "tests/rust/src/test/run-pass/auxiliary/macro-include-items-expr.rs" => false,
Michael Layzell53fc31a2017-06-07 09:21:53 -0400108 _ => true,
109 }
110}
111
Alex Crichton86374772017-07-07 20:39:28 -0700112pub fn clone_rust() {
David Tolnayed8716e2017-12-25 21:49:39 -0500113 let result = Command::new("tests/clone.sh").status().unwrap();
Alex Crichton86374772017-07-07 20:39:28 -0700114 println!("result: {}", result);
115 assert!(result.success());
116}