Use BatTester::default instead of BatTester::new

This commit is contained in:
sharkdp 2021-01-09 19:15:39 +01:00 committed by David Peter
parent 19b8c53c46
commit 73d14f4655
2 changed files with 20 additions and 18 deletions

View File

@ -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);
}
)*

View File

@ -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");