aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2019-06-30 11:54:14 -0700
committerDavid Tolnay <dtolnay@gmail.com>2019-06-30 12:02:52 -0700
commit4d156fd9d664a1e4f44672fc7556f3d3c97136cc (patch)
treefd4198856ddccb5e7df113ae34836c5a284c6792
parent49a674c76e19c41a26210b47f72ddad1e425ff34 (diff)
downloadsyn-4d156fd9d664a1e4f44672fc7556f3d3c97136cc.tar.gz
Module for rust-lang/rust repo related functions
-rw-r--r--benches/file.rs11
-rw-r--r--benches/rust.rs13
-rw-r--r--tests/common/mod.rs58
-rw-r--r--tests/repo/mod.rs54
-rw-r--r--tests/test_precedence.rs6
-rw-r--r--tests/test_round_trip.rs6
6 files changed, 70 insertions, 78 deletions
diff --git a/benches/file.rs b/benches/file.rs
index 24d303d0..08ecd909 100644
--- a/benches/file.rs
+++ b/benches/file.rs
@@ -1,16 +1,11 @@
// $ cargo bench --features full --bench file
-#![recursion_limit = "256"]
#![feature(rustc_private, test)]
extern crate test;
-#[macro_use]
-#[path = "../tests/macros/mod.rs"]
-mod macros;
-
-#[path = "../tests/common/mod.rs"]
-mod common;
+#[path = "../tests/repo/mod.rs"]
+pub mod repo;
use proc_macro2::TokenStream;
use std::fs;
@@ -21,7 +16,7 @@ const FILE: &str = "tests/rust/src/libcore/str/mod.rs";
#[bench]
fn parse_file(b: &mut Bencher) {
- common::clone_rust();
+ repo::clone_rust();
let content = fs::read_to_string(FILE).unwrap();
let tokens = TokenStream::from_str(&content).unwrap();
b.iter(|| syn::parse2::<syn::File>(tokens.clone()));
diff --git a/benches/rust.rs b/benches/rust.rs
index c82598aa..05c4e608 100644
--- a/benches/rust.rs
+++ b/benches/rust.rs
@@ -1,18 +1,13 @@
// $ cargo bench --features full --bench rust
-#![recursion_limit = "256"]
#![feature(rustc_private)]
extern crate rustc_data_structures;
extern crate syntax;
extern crate syntax_pos;
-#[macro_use]
-#[path = "../tests/macros/mod.rs"]
-mod macros;
-
-#[path = "../tests/common/mod.rs"]
-mod common;
+#[path = "../tests/repo/mod.rs"]
+mod repo;
use proc_macro2::TokenStream;
use rustc_data_structures::sync::Lrc;
@@ -69,7 +64,7 @@ fn exec(mut codepath: impl FnMut(&str) -> Result<(), ()>) -> Duration {
walkdir::WalkDir::new("tests/rust/src")
.into_iter()
- .filter_entry(common::base_dir_filter)
+ .filter_entry(repo::base_dir_filter)
.for_each(|entry| {
let entry = entry.unwrap();
let path = entry.path();
@@ -90,7 +85,7 @@ fn exec(mut codepath: impl FnMut(&str) -> Result<(), ()>) -> Duration {
}
fn main() {
- common::clone_rust();
+ repo::clone_rust();
macro_rules! testcases {
($($name:ident,)*) => {
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 84b317a4..8b784bee 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,13 +1,6 @@
#![allow(dead_code)]
-extern crate syntax;
-extern crate walkdir;
-
-use std;
use std::env;
-use std::process::Command;
-
-use self::walkdir::DirEntry;
pub mod eq;
pub mod parse;
@@ -16,55 +9,6 @@ pub mod parse;
pub fn abort_after() -> usize {
match env::var("ABORT_AFTER_FAILURE") {
Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"),
- Err(_) => std::usize::MAX,
- }
-}
-
-pub fn base_dir_filter(entry: &DirEntry) -> bool {
- let path = entry.path();
- if path.is_dir() {
- return true; // otherwise walkdir does not visit the files
- }
- if path.extension().map(|e| e != "rs").unwrap_or(true) {
- return false;
- }
- let path_string = path.to_string_lossy();
- let path_string = if cfg!(windows) {
- path_string.replace('\\', "/").into()
- } else {
- path_string
- };
- // TODO assert that parsing fails on the parse-fail cases
- if path_string.starts_with("tests/rust/src/test/parse-fail")
- || path_string.starts_with("tests/rust/src/test/compile-fail")
- || path_string.starts_with("tests/rust/src/test/rustfix")
- {
- return false;
+ Err(_) => usize::max_value(),
}
-
- if path_string.starts_with("tests/rust/src/test/ui") {
- let stderr_path = path.with_extension("stderr");
- if stderr_path.exists() {
- // Expected to fail in some way
- return false;
- }
- }
-
- match path_string.as_ref() {
- // Deprecated placement syntax
- "tests/rust/src/test/run-pass/new-box-syntax.rs" |
- "tests/rust/src/test/ui/obsolete-in-place/bad.rs" |
- // 2015-style dyn that libsyntax rejects
- "tests/rust/src/test/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs" |
- // not actually test cases
- "tests/rust/src/test/run-pass/macros/auxiliary/macro-comma-support.rs" |
- "tests/rust/src/test/run-pass/macros/auxiliary/macro-include-items-expr.rs" |
- "tests/rust/src/test/ui/issues/auxiliary/issue-21146-inc.rs" => false,
- _ => true,
- }
-}
-
-pub fn clone_rust() {
- let result = Command::new("tests/clone.sh").status().unwrap();
- assert!(result.success());
}
diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs
new file mode 100644
index 00000000..6247bdb3
--- /dev/null
+++ b/tests/repo/mod.rs
@@ -0,0 +1,54 @@
+extern crate walkdir;
+
+use std::process::Command;
+
+use self::walkdir::DirEntry;
+
+pub fn base_dir_filter(entry: &DirEntry) -> bool {
+ let path = entry.path();
+ if path.is_dir() {
+ return true; // otherwise walkdir does not visit the files
+ }
+ if path.extension().map(|e| e != "rs").unwrap_or(true) {
+ return false;
+ }
+ let path_string = path.to_string_lossy();
+ let path_string = if cfg!(windows) {
+ path_string.replace('\\', "/").into()
+ } else {
+ path_string
+ };
+ // TODO assert that parsing fails on the parse-fail cases
+ if path_string.starts_with("tests/rust/src/test/parse-fail")
+ || path_string.starts_with("tests/rust/src/test/compile-fail")
+ || path_string.starts_with("tests/rust/src/test/rustfix")
+ {
+ return false;
+ }
+
+ if path_string.starts_with("tests/rust/src/test/ui") {
+ let stderr_path = path.with_extension("stderr");
+ if stderr_path.exists() {
+ // Expected to fail in some way
+ return false;
+ }
+ }
+
+ match path_string.as_ref() {
+ // Deprecated placement syntax
+ "tests/rust/src/test/run-pass/new-box-syntax.rs" |
+ "tests/rust/src/test/ui/obsolete-in-place/bad.rs" |
+ // 2015-style dyn that libsyntax rejects
+ "tests/rust/src/test/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs" |
+ // not actually test cases
+ "tests/rust/src/test/run-pass/macros/auxiliary/macro-comma-support.rs" |
+ "tests/rust/src/test/run-pass/macros/auxiliary/macro-include-items-expr.rs" |
+ "tests/rust/src/test/ui/issues/auxiliary/issue-21146-inc.rs" => false,
+ _ => true,
+ }
+}
+
+pub fn clone_rust() {
+ let result = Command::new("tests/clone.sh").status().unwrap();
+ assert!(result.success());
+}
diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs
index 30de381c..4774c284 100644
--- a/tests/test_precedence.rs
+++ b/tests/test_precedence.rs
@@ -49,6 +49,8 @@ mod macros;
#[allow(dead_code)]
mod common;
+mod repo;
+
/// Test some pre-set expressions chosen by us.
#[test]
fn test_simple_precedence() {
@@ -91,7 +93,7 @@ fn test_simple_precedence() {
#[test]
#[cfg_attr(target_os = "windows", ignore = "requires nix .sh")]
fn test_rustc_precedence() {
- common::clone_rust();
+ repo::clone_rust();
let abort_after = common::abort_after();
if abort_after == 0 {
panic!("Skipping all precedence tests");
@@ -106,7 +108,7 @@ fn test_rustc_precedence() {
WalkDir::new("tests/rust")
.sort_by(|a, b| a.file_name().cmp(b.file_name()))
.into_iter()
- .filter_entry(common::base_dir_filter)
+ .filter_entry(repo::base_dir_filter)
.collect::<Result<Vec<DirEntry>, walkdir::Error>>()
.unwrap()
.into_par_iter()
diff --git a/tests/test_round_trip.rs b/tests/test_round_trip.rs
index eeadd6cd..2fc9cecd 100644
--- a/tests/test_round_trip.rs
+++ b/tests/test_round_trip.rs
@@ -33,12 +33,14 @@ mod macros;
#[allow(dead_code)]
mod common;
+mod repo;
+
use common::eq::SpanlessEq;
#[test]
#[cfg_attr(target_os = "windows", ignore = "requires nix .sh")]
fn test_round_trip() {
- common::clone_rust();
+ repo::clone_rust();
let abort_after = common::abort_after();
if abort_after == 0 {
panic!("Skipping all round_trip tests");
@@ -49,7 +51,7 @@ fn test_round_trip() {
WalkDir::new("tests/rust")
.sort_by(|a, b| a.file_name().cmp(b.file_name()))
.into_iter()
- .filter_entry(common::base_dir_filter)
+ .filter_entry(repo::base_dir_filter)
.collect::<Result<Vec<DirEntry>, walkdir::Error>>()
.unwrap()
.into_par_iter()