Skip to content

Commit 74cc4d6

Browse files
committed
Tests: Ensure commands execute properly
1 parent 7199693 commit 74cc4d6

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

tests/anonymize.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ fn test_no_terms_and_identicality() {
1414
let mut path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
1515
path.push("target/debug/psbattletools");
1616
let out_dir = PathBuf::from("test-scratch/anonymized");
17-
Command::new(&path)
17+
let output = Command::new(&path)
1818
.arg("anonymize")
1919
.arg(&*TEST_ROOT_DIR)
2020
.arg("-o")
2121
.arg(&out_dir)
2222
.output()
2323
.expect("Failed to execute command");
24+
assert!(output.status.success(), "command failed");
2425

2526
let mut out_file_1 = out_dir.clone();
2627
out_file_1.push("1.log.json");

tests/search.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn test_search() {
1919
.arg(&*TEST_ROOT_DIR)
2020
.output()
2121
.expect("Failed to execute command");
22+
assert!(output.status.success(), "command failed");
2223

2324
let output_str = std::str::from_utf8(&output.stdout).unwrap();
2425
assert!(output_str.contains("annika vs. rusthaters (annika won normally)"));
@@ -40,6 +41,7 @@ fn test_search_forfeit() {
4041
.arg(forfeit_arg)
4142
.output()
4243
.expect("Failed to execute command");
44+
assert!(output.status.success(), "command failed");
4345

4446
let output_str = std::str::from_utf8(&output.stdout).unwrap();
4547
assert!(!output_str.contains("annika"));
@@ -64,6 +66,7 @@ fn test_search_wins_only() {
6466
.arg(win_arg)
6567
.output()
6668
.expect("Failed to execute command");
69+
assert!(annika_output.status.success(), "command failed");
6770

6871
let annika_output_str = std::str::from_utf8(&annika_output.stdout).unwrap();
6972
assert!(annika_output_str.contains("annika vs. rusthaters (annika won normally)"));
@@ -77,6 +80,7 @@ fn test_search_wins_only() {
7780
.arg(win_arg)
7881
.output()
7982
.expect("Failed to execute command");
83+
assert!(rust_haters_output.status.success(), "command failed");
8084

8185
let rust_haters_output_str = std::str::from_utf8(&rust_haters_output.stdout).unwrap();
8286
assert!(!rust_haters_output_str.contains("annika"));

tests/statistics.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ fn test_table() {
6060
for subcommand in ["stats", "winrates", "statistics"] {
6161
for table_arg in ["--human-readable", "--pretty"] {
6262
let out_file = ["test-scratch/pretty-", subcommand, table_arg, ".txt"].join("");
63-
Command::new(&path)
63+
let output = Command::new(&path)
6464
.arg(subcommand)
6565
.arg("--pretty")
6666
.arg(&out_file)
6767
.arg(&*TEST_ROOT_DIR)
6868
.output()
6969
.expect("Failed to execute command");
70+
assert!(output.status.success(), "command failed");
71+
7072
assert_eq!(
7173
std::fs::read_to_string(out_file).expect("Couldn't read output file"),
7274
*DESIRED_TABLE_OUTPUT
@@ -83,13 +85,14 @@ fn test_csv() {
8385
path.push("target/debug/psbattletools");
8486
for subcommand in ["stats", "winrates", "statistics"] {
8587
let out_file = ["test-scratch/csv-", subcommand, ".csv"].join("");
86-
Command::new(&path)
88+
let output = Command::new(&path)
8789
.arg(subcommand)
8890
.arg("--csv")
8991
.arg(&out_file)
9092
.arg(&*TEST_ROOT_DIR)
9193
.output()
9294
.expect("Failed to execute command");
95+
assert!(output.status.success(), "command failed");
9396

9497
assert_eq!(
9598
std::fs::read_to_string(out_file).expect("Couldn't read output file"),
@@ -110,6 +113,7 @@ fn test_default_output() {
110113
.arg(&*TEST_ROOT_DIR)
111114
.output()
112115
.expect("Failed to execute command");
116+
assert!(output.status.success(), "command failed");
113117

114118
let output_str = std::str::from_utf8(&output.stdout).unwrap();
115119
assert_eq!(
@@ -134,6 +138,7 @@ fn test_min_elo() {
134138
.arg(&*TEST_ROOT_DIR)
135139
.output()
136140
.expect("Failed to execute command");
141+
assert!(normal_output.status.success(), "command failed");
137142

138143
let normal_output_str = std::str::from_utf8(&normal_output.stdout).unwrap();
139144
assert_eq!(
@@ -148,6 +153,7 @@ fn test_min_elo() {
148153
.arg(&*TEST_ROOT_DIR)
149154
.output()
150155
.expect("Failed to execute command");
156+
assert!(no_output.status.success(), "command failed");
151157

152158
let no_output_str = std::str::from_utf8(&no_output.stdout).unwrap();
153159
assert!(!no_output_str.contains('%'));
@@ -170,6 +176,7 @@ fn test_exclusions() {
170176
.arg(&*TEST_ROOT_DIR)
171177
.output()
172178
.expect("Failed to execute command");
179+
assert!(normal_output.status.success(), "command failed");
173180

174181
let normal_output_str = std::str::from_utf8(&normal_output.stdout).unwrap();
175182
assert_eq!(
@@ -185,6 +192,7 @@ fn test_exclusions() {
185192
.arg(&*TEST_ROOT_DIR)
186193
.output()
187194
.expect("Failed to execute command");
195+
assert!(reduced_output.status.success(), "command failed");
188196

189197
let reduced_output_str = std::str::from_utf8(&reduced_output.stdout).unwrap();
190198
assert!(!reduced_output_str.contains("1000")); // less than 1000 battles

0 commit comments

Comments
 (0)