From 3ab9f4ad7fa44cb20c0a13ae69f76ee13e4f53d2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Sep 2018 18:42:59 +0300 Subject: Add fuzz failures dir --- crates/libsyntax2/tests/test/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'crates/libsyntax2/tests/test/main.rs') diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index 596f32216..014faa2c6 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs @@ -12,7 +12,7 @@ use std::{ use test_utils::extract_range; use libsyntax2::{ File, AtomEdit, - utils::dump_tree, + utils::{dump_tree, check_fuzz_invariants}, }; #[test] @@ -31,6 +31,13 @@ fn parser_tests() { }) } +#[test] +fn parser_fuzz_tests() { + for (_, text) in collect_tests(&["parser/fuzz-failures"]) { + check_fuzz_invariants(&text) + } +} + #[test] fn reparse_test() { fn do_check(before: &str, replace_with: &str) { @@ -88,8 +95,7 @@ pub fn dir_tests(paths: &[&str], f: F) where F: Fn(&str) -> String, { - for path in collect_tests(paths) { - let input_code = read_text(&path); + for (path, input_code) in collect_tests(paths) { let parse_tree = f(&input_code); let path = path.with_extension("txt"); if !path.exists() { @@ -128,13 +134,17 @@ fn assert_equal_text(expected: &str, actual: &str, path: &Path) { assert_eq_text!(expected, actual, "file: {}", pretty_path.display()); } -fn collect_tests(paths: &[&str]) -> Vec { +fn collect_tests(paths: &[&str]) -> Vec<(PathBuf, String)> { paths .iter() .flat_map(|path| { let path = test_data_dir().join(path); test_from_dir(&path).into_iter() }) + .map(|path| { + let text = read_text(&path); + (path, text) + }) .collect() } -- cgit v1.2.3