Skip to content

Commit 4b031b2

Browse files
committed
✅ Add found flag to chmod tests to prevent vacuous assertions
All 35 for_each_entry calls that match entries by path now track whether the target entry was actually found, preventing tests from silently passing when the target entry is missing from the archive.
1 parent 5aeb6a0 commit 4b031b2

13 files changed

Lines changed: 105 additions & 0 deletions

cli/tests/cli/chmod/edge_cases.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ fn chmod_edge_set_no_permissions() {
3636
.execute()
3737
.unwrap();
3838

39+
let mut found = false;
3940
archive::for_each_entry("chmod_edge_000.pna", |entry| {
4041
if entry.header().path() == ENTRY_PATH {
42+
found = true;
4143
let perm = entry
4244
.metadata()
4345
.permission()
@@ -50,6 +52,7 @@ fn chmod_edge_set_no_permissions() {
5052
}
5153
})
5254
.unwrap();
55+
assert!(found, "target entry not found in archive");
5356
}
5457

5558
/// Precondition: An archive contains a file with permission 0o000 (---------).
@@ -83,8 +86,10 @@ fn chmod_edge_set_full_permissions() {
8386
.execute()
8487
.unwrap();
8588

89+
let mut found = false;
8690
archive::for_each_entry("chmod_edge_777.pna", |entry| {
8791
if entry.header().path() == ENTRY_PATH {
92+
found = true;
8893
let perm = entry
8994
.metadata()
9095
.permission()
@@ -97,6 +102,7 @@ fn chmod_edge_set_full_permissions() {
97102
}
98103
})
99104
.unwrap();
105+
assert!(found, "target entry not found in archive");
100106
}
101107

102108
/// Precondition: An archive contains a file with permission 0o644 (rw-r--r--).
@@ -130,8 +136,10 @@ fn chmod_edge_idempotent_operation() {
130136
.execute()
131137
.unwrap();
132138

139+
let mut found = false;
133140
archive::for_each_entry("chmod_edge_idem.pna", |entry| {
134141
if entry.header().path() == ENTRY_PATH {
142+
found = true;
135143
let perm = entry
136144
.metadata()
137145
.permission()
@@ -144,6 +152,7 @@ fn chmod_edge_idempotent_operation() {
144152
}
145153
})
146154
.unwrap();
155+
assert!(found, "target entry not found in archive");
147156
}
148157

149158
/// Precondition: An archive contains a file with permission 0o755 (rwxr-xr-x).
@@ -177,8 +186,10 @@ fn chmod_edge_symbolic_clear_all() {
177186
.execute()
178187
.unwrap();
179188

189+
let mut found = false;
180190
archive::for_each_entry("chmod_edge_clear.pna", |entry| {
181191
if entry.header().path() == ENTRY_PATH {
192+
found = true;
182193
let perm = entry
183194
.metadata()
184195
.permission()
@@ -191,6 +202,7 @@ fn chmod_edge_symbolic_clear_all() {
191202
}
192203
})
193204
.unwrap();
205+
assert!(found, "target entry not found in archive");
194206
}
195207

196208
/// Precondition: An archive contains a file with permission 0o000 (---------).
@@ -224,8 +236,10 @@ fn chmod_edge_symbolic_full_permissions() {
224236
.execute()
225237
.unwrap();
226238

239+
let mut found = false;
227240
archive::for_each_entry("chmod_edge_full.pna", |entry| {
228241
if entry.header().path() == ENTRY_PATH {
242+
found = true;
229243
let perm = entry
230244
.metadata()
231245
.permission()
@@ -238,6 +252,7 @@ fn chmod_edge_symbolic_full_permissions() {
238252
}
239253
})
240254
.unwrap();
255+
assert!(found, "target entry not found in archive");
241256
}
242257

243258
/// Precondition: An archive contains a file with permission 0o755 (rwxr-xr-x).
@@ -272,8 +287,10 @@ fn chmod_edge_idempotent_add_execute() {
272287
.execute()
273288
.unwrap();
274289

290+
let mut found = false;
275291
archive::for_each_entry("chmod_edge_idem_x.pna", |entry| {
276292
if entry.header().path() == ENTRY_PATH {
293+
found = true;
277294
let perm = entry
278295
.metadata()
279296
.permission()
@@ -286,6 +303,7 @@ fn chmod_edge_idempotent_add_execute() {
286303
}
287304
})
288305
.unwrap();
306+
assert!(found, "target entry not found in archive");
289307
}
290308

291309
/// Precondition: An archive contains a file with permission 0o644 (rw-r--r--).
@@ -320,8 +338,10 @@ fn chmod_edge_idempotent_remove_execute() {
320338
.execute()
321339
.unwrap();
322340

341+
let mut found = false;
323342
archive::for_each_entry("chmod_edge_idem_no_x.pna", |entry| {
324343
if entry.header().path() == ENTRY_PATH {
344+
found = true;
325345
let perm = entry
326346
.metadata()
327347
.permission()
@@ -334,4 +354,5 @@ fn chmod_edge_idempotent_remove_execute() {
334354
}
335355
})
336356
.unwrap();
357+
assert!(found, "target entry not found in archive");
337358
}

cli/tests/cli/chmod/glob_pattern.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ fn chmod_verify_archive_metadata() {
237237
.execute()
238238
.unwrap();
239239

240+
let mut found = false;
240241
archive::for_each_entry("chmod_verify_meta.pna", |entry| {
241242
if entry.header().path() == "test.txt" {
243+
found = true;
242244
let perm = entry
243245
.metadata()
244246
.permission()
@@ -251,4 +253,5 @@ fn chmod_verify_archive_metadata() {
251253
}
252254
})
253255
.unwrap();
256+
assert!(found, "target entry not found in archive");
254257
}

cli/tests/cli/chmod/keep_solid.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ fn chmod_keep_solid() {
3838
.execute()
3939
.unwrap();
4040

41+
let mut found = false;
4142
archive::for_each_entry("chmod_keep_solid.pna", |entry| {
4243
if entry.header().path() == ENTRY_PATH {
44+
found = true;
4345
let perm = entry
4446
.metadata()
4547
.permission()
@@ -52,4 +54,5 @@ fn chmod_keep_solid() {
5254
}
5355
})
5456
.unwrap();
57+
assert!(found, "target entry not found in archive");
5558
}

cli/tests/cli/chmod/multiple_clauses.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ fn chmod_multiple_clauses_standard_754() {
3636
.execute()
3737
.unwrap();
3838

39+
let mut found = false;
3940
archive::for_each_entry("chmod_multi_754.pna", |entry| {
4041
if entry.header().path() == ENTRY_PATH {
42+
found = true;
4143
let perm = entry
4244
.metadata()
4345
.permission()
@@ -50,6 +52,7 @@ fn chmod_multiple_clauses_standard_754() {
5052
}
5153
})
5254
.unwrap();
55+
assert!(found, "target entry not found in archive");
5356
}
5457

5558
/// Precondition: An archive contains a file with permission 0o777 (rwxrwxrwx).
@@ -83,8 +86,10 @@ fn chmod_multiple_clauses_restrictive() {
8386
.execute()
8487
.unwrap();
8588

89+
let mut found = false;
8690
archive::for_each_entry("chmod_multi_640.pna", |entry| {
8791
if entry.header().path() == ENTRY_PATH {
92+
found = true;
8893
let perm = entry
8994
.metadata()
9095
.permission()
@@ -97,6 +102,7 @@ fn chmod_multiple_clauses_restrictive() {
97102
}
98103
})
99104
.unwrap();
105+
assert!(found, "target entry not found in archive");
100106
}
101107

102108
/// Precondition: An archive contains a file with permission 0o644 (rw-r--r--).
@@ -130,8 +136,10 @@ fn chmod_multiple_clauses_mixed_operations() {
130136
.execute()
131137
.unwrap();
132138

139+
let mut found = false;
133140
archive::for_each_entry("chmod_multi_mixed.pna", |entry| {
134141
if entry.header().path() == ENTRY_PATH {
142+
found = true;
135143
let perm = entry
136144
.metadata()
137145
.permission()
@@ -144,6 +152,7 @@ fn chmod_multiple_clauses_mixed_operations() {
144152
}
145153
})
146154
.unwrap();
155+
assert!(found, "target entry not found in archive");
147156
}
148157

149158
/// Precondition: An archive contains a file with permission 0o777 (rwxrwxrwx).
@@ -177,8 +186,10 @@ fn chmod_multiple_clauses_combined_targets() {
177186
.execute()
178187
.unwrap();
179188

189+
let mut found = false;
180190
archive::for_each_entry("chmod_multi_combined.pna", |entry| {
181191
if entry.header().path() == ENTRY_PATH {
192+
found = true;
182193
let perm = entry
183194
.metadata()
184195
.permission()
@@ -191,4 +202,5 @@ fn chmod_multiple_clauses_combined_targets() {
191202
}
192203
})
193204
.unwrap();
205+
assert!(found, "target entry not found in archive");
194206
}

cli/tests/cli/chmod/numeric.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ fn chmod_numeric_mode() {
3636
.execute()
3737
.unwrap();
3838

39+
let mut found = false;
3940
archive::for_each_entry("chmod_numeric.pna", |entry| {
4041
if entry.header().path() == ENTRY_PATH {
42+
found = true;
4143
let perm = entry
4244
.metadata()
4345
.permission()
@@ -50,4 +52,5 @@ fn chmod_numeric_mode() {
5052
}
5153
})
5254
.unwrap();
55+
assert!(found, "target entry not found in archive");
5356
}

cli/tests/cli/chmod/password.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ fn chmod_with_password() {
4141
.execute()
4242
.unwrap();
4343

44+
let mut found = false;
4445
archive::for_each_entry_with_password("chmod_password.pna", Some(PASSWORD), |entry| {
4546
if entry.header().path() == ENTRY_PATH {
47+
found = true;
4648
let perm = entry
4749
.metadata()
4850
.permission()
@@ -55,4 +57,5 @@ fn chmod_with_password() {
5557
}
5658
})
5759
.unwrap();
60+
assert!(found, "target entry not found in archive");
5861
}

cli/tests/cli/chmod/password_file.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ fn chmod_with_password_file() {
4545
.execute()
4646
.unwrap();
4747

48+
let mut found = false;
4849
archive::for_each_entry_with_password("chmod_password_file.pna", Some(PASSWORD), |entry| {
4950
if entry.header().path() == ENTRY_PATH {
51+
found = true;
5052
let perm = entry
5153
.metadata()
5254
.permission()
@@ -59,4 +61,5 @@ fn chmod_with_password_file() {
5961
}
6062
})
6163
.unwrap();
64+
assert!(found, "target entry not found in archive");
6265
}

cli/tests/cli/chmod/symbolic_all.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ fn chmod_symbolic_all_implicit_add_execute() {
3737
.execute()
3838
.unwrap();
3939

40+
let mut found = false;
4041
archive::for_each_entry("chmod_sym_all_add_x.pna", |entry| {
4142
if entry.header().path() == ENTRY_PATH {
43+
found = true;
4244
let perm = entry
4345
.metadata()
4446
.permission()
@@ -51,6 +53,7 @@ fn chmod_symbolic_all_implicit_add_execute() {
5153
}
5254
})
5355
.unwrap();
56+
assert!(found, "target entry not found in archive");
5457
}
5558

5659
/// Precondition: An archive contains a file with permission 0o666 (rw-rw-rw-).
@@ -84,8 +87,10 @@ fn chmod_symbolic_all_explicit_add_execute() {
8487
.execute()
8588
.unwrap();
8689

90+
let mut found = false;
8791
archive::for_each_entry("chmod_sym_a_add_x.pna", |entry| {
8892
if entry.header().path() == ENTRY_PATH {
93+
found = true;
8994
let perm = entry
9095
.metadata()
9196
.permission()
@@ -98,6 +103,7 @@ fn chmod_symbolic_all_explicit_add_execute() {
98103
}
99104
})
100105
.unwrap();
106+
assert!(found, "target entry not found in archive");
101107
}
102108

103109
/// Precondition: An archive contains a file with permission 0o777 (rwxrwxrwx).
@@ -131,8 +137,10 @@ fn chmod_symbolic_all_remove_write() {
131137
.execute()
132138
.unwrap();
133139

140+
let mut found = false;
134141
archive::for_each_entry("chmod_sym_a_rm_w.pna", |entry| {
135142
if entry.header().path() == ENTRY_PATH {
143+
found = true;
136144
let perm = entry
137145
.metadata()
138146
.permission()
@@ -145,6 +153,7 @@ fn chmod_symbolic_all_remove_write() {
145153
}
146154
})
147155
.unwrap();
156+
assert!(found, "target entry not found in archive");
148157
}
149158

150159
/// Precondition: An archive contains a file with permission 0o000 (---------).
@@ -179,8 +188,10 @@ fn chmod_symbolic_all_set_readwrite() {
179188
.execute()
180189
.unwrap();
181190

191+
let mut found = false;
182192
archive::for_each_entry("chmod_sym_all_set_rw.pna", |entry| {
183193
if entry.header().path() == ENTRY_PATH {
194+
found = true;
184195
let perm = entry
185196
.metadata()
186197
.permission()
@@ -193,4 +204,5 @@ fn chmod_symbolic_all_set_readwrite() {
193204
}
194205
})
195206
.unwrap();
207+
assert!(found, "target entry not found in archive");
196208
}

0 commit comments

Comments
 (0)