forked from pwinckles/bagr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_tests.rs
52 lines (43 loc) · 1.32 KB
/
cli_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::fs;
use std::path::{Path, PathBuf};
#[test]
fn bag_cli_tests() {
// have to setup the manifest-encoding test here because git for windows hates newlines in paths
setup_encoding_test();
trycmd::TestCases::new().case("tests/cmd/bag/*.toml");
}
#[test]
fn rebag_cli_tests() {
trycmd::TestCases::new().case("tests/cmd/rebag/*.toml");
}
fn setup_encoding_test() {
let in_base = base_path().join("bag").join("manifest-encoding.in");
setup_encoding_files(in_base);
let out_base = base_path()
.join("bag")
.join("manifest-encoding.out")
.join("data");
setup_encoding_files(out_base);
}
fn setup_encoding_files(path: PathBuf) {
write_file(
&path.join("dir\r\nwith%25everything%0D%0A").join("file.txt"),
"complex name\n",
);
write_file(&path.join("test\nlf.txt"), "file with lf\n");
write_file(&path.join("test\rcr.txt"), "file with cr\n");
write_file(&path.join("test%20file.txt"), "file with %\n");
}
fn base_path() -> PathBuf {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("tests");
path.push("cmd");
path
}
fn create_dir_all(path: &Path) {
fs::create_dir_all(path).unwrap()
}
fn write_file(path: &Path, content: &str) {
create_dir_all(path.parent().unwrap());
fs::write(path, content).unwrap();
}