diff options
author | sharkdp <davidpeter@web.de> | 2021-01-09 19:15:39 +0100 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2021-01-09 19:43:39 +0100 |
commit | 73d14f4655780a4eba0f0664fb7d1e094d885a90 (patch) | |
tree | 2285c1b5fbac8525941cb5839567fec6ce91fa8f | |
parent | 19b8c53c46922b9c6bbd620bb01fd688778c728d (diff) |
Use BatTester::default instead of BatTester::new
-rw-r--r-- | tests/snapshot_tests.rs | 2 | ||||
-rw-r--r-- | tests/tester.rs | 36 |
2 files changed, 20 insertions, 18 deletions
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<TempDir, git2::Error> { // Create temp directory and initialize repository let temp_dir = TempDir::new("bat-tests").expect("Temp directory"); |