Skip to content

Commit 01e7b68

Browse files
committed
fixed tests/made more robust
1 parent d9aa393 commit 01e7b68

3 files changed

Lines changed: 26 additions & 29 deletions

File tree

tests/common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ pub fn cargo_bundle_bin() -> PathBuf {
99
project_root().join("target/debug/cargo-bundle")
1010
}
1111

12+
#[cfg(test)]
13+
#[allow(dead_code)] // Used in tests
14+
pub fn parse_bundle_paths(stdout: &str) -> Vec<PathBuf> {
15+
stdout
16+
.lines()
17+
.filter(|line| line.starts_with(" "))
18+
.map(|line| PathBuf::from(line.trim()))
19+
.collect()
20+
}
21+
1222
/// Places a valid-enough binary at `target/debug/examples/<name>` so that
1323
/// cargo-bundle (running with CARGO_BUNDLE_SKIP_BUILD) has something to package.
1424
pub fn setup_example_binary(name: &str) {

tests/goodbye.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,21 @@ fn deb() {
5555
String::from_utf8_lossy(&output.stderr)
5656
);
5757

58-
let arch = if cfg!(target_arch = "x86_64") {
59-
"amd64"
60-
} else if cfg!(target_arch = "aarch64") {
61-
"arm64"
62-
} else {
63-
"amd64"
64-
};
65-
66-
let deb_path = root.join(format!(
67-
"target/debug/examples/bundle/deb/goodbye_0.9.1_{arch}.deb"
68-
));
58+
let bundle_paths = common::parse_bundle_paths(&String::from_utf8_lossy(&output.stdout));
59+
assert_eq!(bundle_paths.len(), 1, "Expected exactly one bundle path");
60+
let deb_path = &bundle_paths[0];
6961
assert!(
7062
deb_path.exists(),
7163
"Debian package not found at {:?}",
7264
deb_path
7365
);
7466

7567
// The 128x128 PNG should have been placed in the hicolor icon tree.
76-
let icon_path = root.join(format!(
77-
"target/debug/examples/bundle/deb/goodbye_0.9.1_{arch}/data/usr/share/icons/hicolor/128x128/apps/goodbye.png"
78-
));
68+
let package_dir = deb_path
69+
.parent()
70+
.unwrap()
71+
.join(deb_path.file_stem().unwrap());
72+
let icon_path = package_dir.join("data/usr/share/icons/hicolor/128x128/apps/goodbye.png");
7973
assert!(
8074
icon_path.exists(),
8175
"PNG icon not found in deb data at {:?}",

tests/hello.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ fn osx() {
3636
}
3737

3838
#[test]
39-
#[cfg(target_os = "linux")]
4039
fn deb() {
4140
common::setup_example_binary("hello");
4241

@@ -55,27 +54,21 @@ fn deb() {
5554
String::from_utf8_lossy(&output.stderr)
5655
);
5756

58-
let arch = if cfg!(target_arch = "x86_64") {
59-
"amd64"
60-
} else if cfg!(target_arch = "aarch64") {
61-
"arm64"
62-
} else {
63-
"amd64"
64-
};
65-
66-
let deb_path = root.join(format!(
67-
"target/debug/examples/bundle/deb/hello_0.9.1_{arch}.deb"
68-
));
57+
let bundle_paths = common::parse_bundle_paths(&String::from_utf8_lossy(&output.stdout));
58+
assert_eq!(bundle_paths.len(), 1, "Expected exactly one bundle path");
59+
let deb_path = &bundle_paths[0];
6960
assert!(
7061
deb_path.exists(),
7162
"Debian package not found at {:?}",
7263
deb_path
7364
);
7465

7566
// SVG should be copied to the scalable hicolor directory.
76-
let svg_path = root.join(format!(
77-
"target/debug/examples/bundle/deb/hello_0.9.1_{arch}/data/usr/share/icons/hicolor/scalable/apps/hello.svg"
78-
));
67+
let package_dir = deb_path
68+
.parent()
69+
.unwrap()
70+
.join(deb_path.file_stem().unwrap());
71+
let svg_path = package_dir.join("data/usr/share/icons/hicolor/scalable/apps/hello.svg");
7972
assert!(
8073
svg_path.exists(),
8174
"SVG icon not found in deb data at {:?}",

0 commit comments

Comments
 (0)