aboutsummaryrefslogtreecommitdiff
path: root/tests/testutils/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testutils/src')
-rw-r--r--tests/testutils/src/lib.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs
index 43b806541..7c481156f 100644
--- a/tests/testutils/src/lib.rs
+++ b/tests/testutils/src/lib.rs
@@ -1,8 +1,9 @@
1extern crate difference; 1extern crate difference;
2extern crate file;
3 2
4use std::fs::read_dir; 3use std::{
5use std::path::{Path, PathBuf}; 4 fs,
5 path::{Path, PathBuf}
6};
6 7
7use difference::Changeset; 8use difference::Changeset;
8 9
@@ -18,7 +19,7 @@ use difference::Changeset;
18/// 19///
19/// so this should always be correct. 20/// so this should always be correct.
20fn read_text(path: &Path) -> String { 21fn read_text(path: &Path) -> String {
21 file::get_text(path).unwrap().replace("\r\n", "\n") 22 fs::read_to_string(path).unwrap().replace("\r\n", "\n")
22} 23}
23 24
24pub fn dir_tests<F>(paths: &[&str], f: F) 25pub fn dir_tests<F>(paths: &[&str], f: F)
@@ -33,7 +34,7 @@ where
33 println!("\nfile: {}", path.display()); 34 println!("\nfile: {}", path.display());
34 println!("No .txt file with expected result, creating...\n"); 35 println!("No .txt file with expected result, creating...\n");
35 println!("{}\n{}", input_code, parse_tree); 36 println!("{}\n{}", input_code, parse_tree);
36 file::put_text(&path, parse_tree).unwrap(); 37 fs::write(&path, parse_tree).unwrap();
37 panic!("No expected result") 38 panic!("No expected result")
38 } 39 }
39 let expected = read_text(&path); 40 let expected = read_text(&path);
@@ -61,7 +62,7 @@ fn collect_tests(paths: &[&str]) -> Vec<PathBuf> {
61 62
62fn test_from_dir(dir: &Path) -> Vec<PathBuf> { 63fn test_from_dir(dir: &Path) -> Vec<PathBuf> {
63 let mut acc = Vec::new(); 64 let mut acc = Vec::new();
64 for file in read_dir(&dir).unwrap() { 65 for file in fs::read_dir(&dir).unwrap() {
65 let file = file.unwrap(); 66 let file = file.unwrap();
66 let path = file.path(); 67 let path = file.path();
67 if path.extension().unwrap_or_default() == "rs" { 68 if path.extension().unwrap_or_default() == "rs" {
@@ -80,12 +81,12 @@ fn print_difference(expected: &str, actual: &str, path: &Path) {
80 if expected.trim() == actual.trim() { 81 if expected.trim() == actual.trim() {
81 println!("whitespace difference, rewriting"); 82 println!("whitespace difference, rewriting");
82 println!("file: {}\n", path.display()); 83 println!("file: {}\n", path.display());
83 file::put_text(path, actual).unwrap(); 84 fs::write(path, actual).unwrap();
84 return; 85 return;
85 } 86 }
86 if REWRITE { 87 if REWRITE {
87 println!("rewriting {}", path.display()); 88 println!("rewriting {}", path.display());
88 file::put_text(path, actual).unwrap(); 89 fs::write(path, actual).unwrap();
89 return; 90 return;
90 } 91 }
91 let changeset = Changeset::new(actual, expected, "\n"); 92 let changeset = Changeset::new(actual, expected, "\n");