diff --git a/tests/snapshot_tests.rs b/tests/snapshot_tests.rs index 8abb8414..14c3eee1 100644 --- a/tests/snapshot_tests.rs +++ b/tests/snapshot_tests.rs @@ -7,7 +7,7 @@ macro_rules! snapshot_tests { $( #[test] fn $test_name() { - let bat_tester = BatTester::new(); + let bat_tester = BatTester::default(); bat_tester.test_snapshot(stringify!($test_name), $style); } )* diff --git a/tests/tester.rs b/tests/tester.rs index 9c52459f..8a1a0f3b 100644 --- a/tests/tester.rs +++ b/tests/tester.rs @@ -19,23 +19,6 @@ pub struct BatTester { } impl BatTester { - pub fn new() -> Self { - let temp_dir = create_sample_directory().expect("sample directory"); - - let root = env::current_exe() - .expect("tests executable") - .parent() - .expect("tests executable directory") - .parent() - .expect("bat executable directory") - .to_path_buf(); - - let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" }; - let exe = root.join(exe_name); - - BatTester { temp_dir, exe } - } - pub fn test_snapshot(&self, name: &str, style: &str) { let output = Command::new(&self.exe) .current_dir(self.temp_dir.path()) @@ -66,6 +49,25 @@ impl BatTester { } } +impl Default for BatTester { + fn default() -> Self { + let temp_dir = create_sample_directory().expect("sample directory"); + + let root = env::current_exe() + .expect("tests executable") + .parent() + .expect("tests executable directory") + .parent() + .expect("bat executable directory") + .to_path_buf(); + + let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" }; + let exe = root.join(exe_name); + + BatTester { temp_dir, exe } + } +} + fn create_sample_directory() -> Result { // Create temp directory and initialize repository let temp_dir = TempDir::new("bat-tests").expect("Temp directory");