Improve test cleanup by using scopeguard.

This commit is contained in:
Kiyomichi Kosaka
2022-12-21 14:00:01 +00:00
parent 35517b2849
commit de13dd6a7b
7 changed files with 18 additions and 19 deletions
+1
View File
@@ -21,3 +21,4 @@ base64 = "0.20.0"
rpassword = "7.2.0" rpassword = "7.2.0"
shlex = "1.1.0" shlex = "1.1.0"
shellexpand = "3.0.0" shellexpand = "3.0.0"
scopeguard = "1.1.0"
+2 -2
View File
@@ -1,5 +1,5 @@
#[macro_use] #[macro_use] extern crate lazy_static;
extern crate lazy_static; #[macro_use(defer)] extern crate scopeguard;
mod lk; mod lk;
mod parser; mod parser;
+15 -8
View File
@@ -323,16 +323,23 @@ mod tests {
writeln!(writer, "#!/bin/sh\ncat >test_pb_out").expect("write"); writeln!(writer, "#!/bin/sh\ncat >test_pb_out").expect("write");
} }
#[allow(unused_must_use)] fn clear_test_files() {
{ #[allow(unused_must_use)]
std::fs::remove_file("test_history"); {
std::fs::remove_file("test_init"); std::fs::remove_file("test_history");
std::fs::remove_file("test_dump"); std::fs::remove_file("test_init");
std::fs::remove_file("test_correct"); std::fs::remove_file("test_dump");
std::fs::remove_file("test_pb"); std::fs::remove_file("test_correct");
std::fs::remove_file("test_pb_out"); std::fs::remove_file("test_pb");
std::fs::remove_file("test_pb_out");
}
} }
defer! {
clear_test_files();
}
clear_test_files();
create_init(); create_init();
create_pb(); create_pb();
-3
View File
@@ -1,3 +0,0 @@
add t1 R 99 2022-10-10
add t2 R 99 2022-10-10 test ^t1
add t3 R 99 2022-10-10 aoeu ^t2
-3
View File
@@ -1,3 +0,0 @@
add t1 r 99 2022-10-10
add t2 r 99 2022-10-10 test ^t1
add t3 r 99 2022-10-10 ^t2 aoeu
-2
View File
@@ -1,2 +0,0 @@
#!/bin/sh
cat >test_pb_out
-1
View File
@@ -1 +0,0 @@
fief gild sits can un very