Skip to content

Commit f82a5dc

Browse files
committed
♻️ Use shared test helpers in option_cd tests
Replace local create_test_archive and get_archive_entry_names with the shared implementations from utils/archive.
1 parent e4e902c commit f82a5dc

1 file changed

Lines changed: 4 additions & 33 deletions

File tree

cli/tests/cli/stdio/option_cd.rs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,10 @@
1-
use crate::utils::{archive::for_each_entry, setup};
1+
use crate::utils::{
2+
archive::{create_test_archive, get_archive_entry_names},
3+
setup,
4+
};
25
use assert_cmd::cargo::cargo_bin_cmd;
3-
use pna::{Archive, EntryBuilder, WriteOptions};
46
use std::collections::HashSet;
57
use std::fs;
6-
use std::io::Write;
7-
use std::path::Path;
8-
9-
fn create_test_archive(path: &Path, entries: &[(&str, &str)]) {
10-
if let Some(parent) = path.parent() {
11-
fs::create_dir_all(parent).unwrap();
12-
}
13-
let file = fs::File::create(path).unwrap();
14-
let mut writer = Archive::write_header(file).unwrap();
15-
for (name, contents) in entries {
16-
writer
17-
.add_entry({
18-
let mut builder =
19-
EntryBuilder::new_file((*name).into(), WriteOptions::builder().build())
20-
.unwrap();
21-
builder.write_all(contents.as_bytes()).unwrap();
22-
builder.build().unwrap()
23-
})
24-
.unwrap();
25-
}
26-
writer.finalize().unwrap();
27-
}
28-
29-
fn get_archive_entry_names(path: &Path) -> Vec<String> {
30-
let mut names = Vec::new();
31-
for_each_entry(path, |entry| {
32-
names.push(entry.header().path().to_string());
33-
})
34-
.unwrap();
35-
names
36-
}
378

389
/// Precondition: Archive source.pna contains file a.txt. Directory sub/ contains b.txt.
3910
/// Action: Create with `@source.pna -C sub b.txt` -- archive inclusion before -C.

0 commit comments

Comments
 (0)