mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 10:11:07 +00:00
Use BatTester::default instead of BatTester::new
This commit is contained in:
parent
19b8c53c46
commit
73d14f4655
@ -7,7 +7,7 @@ macro_rules! snapshot_tests {
|
|||||||
$(
|
$(
|
||||||
#[test]
|
#[test]
|
||||||
fn $test_name() {
|
fn $test_name() {
|
||||||
let bat_tester = BatTester::new();
|
let bat_tester = BatTester::default();
|
||||||
bat_tester.test_snapshot(stringify!($test_name), $style);
|
bat_tester.test_snapshot(stringify!($test_name), $style);
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
@ -19,23 +19,6 @@ pub struct BatTester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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) {
|
pub fn test_snapshot(&self, name: &str, style: &str) {
|
||||||
let output = Command::new(&self.exe)
|
let output = Command::new(&self.exe)
|
||||||
.current_dir(self.temp_dir.path())
|
.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> {
|
fn create_sample_directory() -> Result<TempDir, git2::Error> {
|
||||||
// Create temp directory and initialize repository
|
// Create temp directory and initialize repository
|
||||||
let temp_dir = TempDir::new("bat-tests").expect("Temp directory");
|
let temp_dir = TempDir::new("bat-tests").expect("Temp directory");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user