on master help sign in
Use BatTester::default instead of BatTester::new
73d14f4sharkdp
tests/snapshot_tests.rs+1−1
@@ -7,7 +7,7 @@ macro_rules! snapshot_tests {
7 $(
7 $(
8 #[test]
8 #[test]
9 fn $test_name() {
9 fn $test_name() {
10− let bat_tester = BatTester::new();
10+ let bat_tester = BatTester::default();
11 bat_tester.test_snapshot(stringify!($test_name), $style);
11 bat_tester.test_snapshot(stringify!($test_name), $style);
12 }
12 }
13 )*
13 )*
tests/tester.rs+19−17
@@ -19,23 +19,6 @@ pub struct BatTester {
19}
19}
20
20
21impl BatTester {
21impl BatTester {
22− pub fn new() -> Self {
23− let temp_dir = create_sample_directory().expect("sample directory");
24−
25− let root = env::current_exe()
26− .expect("tests executable")
27− .parent()
28− .expect("tests executable directory")
29− .parent()
30− .expect("bat executable directory")
31− .to_path_buf();
32−
33− let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" };
34− let exe = root.join(exe_name);
35−
36− BatTester { temp_dir, exe }
37− }
38−
39 pub fn test_snapshot(&self, name: &str, style: &str) {
22 pub fn test_snapshot(&self, name: &str, style: &str) {
40 let output = Command::new(&self.exe)
23 let output = Command::new(&self.exe)
41 .current_dir(self.temp_dir.path())
24 .current_dir(self.temp_dir.path())
@@ -66,6 +49,25 @@ impl BatTester {
66 }
49 }
67}
50}
68
51
52+impl Default for BatTester {
53+ fn default() -> Self {
54+ let temp_dir = create_sample_directory().expect("sample directory");
55+
56+ let root = env::current_exe()
57+ .expect("tests executable")
58+ .parent()
59+ .expect("tests executable directory")
60+ .parent()
61+ .expect("bat executable directory")
62+ .to_path_buf();
63+
64+ let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" };
65+ let exe = root.join(exe_name);
66+
67+ BatTester { temp_dir, exe }
68+ }
69+}
70+
69fn create_sample_directory() -> Result<TempDir, git2::Error> {
71fn create_sample_directory() -> Result<TempDir, git2::Error> {
70 // Create temp directory and initialize repository
72 // Create temp directory and initialize repository
71 let temp_dir = TempDir::new("bat-tests").expect("Temp directory");
73 let temp_dir = TempDir::new("bat-tests").expect("Temp directory");