Skip to content

Commit 4114429

Browse files
test: remove committed .png files and generate into temp dir
There's not much point in committing them (and having to keep them up to date would be unnecessary hassle). The rendering is done with resvg anyway.
1 parent edc2e1f commit 4114429

15 files changed

+19
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ regex = "1.12.2"
5555
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
5656
assert_cmd = "2.1.1"
5757
libtest-mimic = "0.8.1"
58+
tempfile = "3"
5859

5960
[dev-dependencies]
6061
wasm-bindgen-test = "0.3"

tests/cli.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::path::PathBuf;
77
use assert_cmd::cargo::cargo_bin_cmd;
88
#[cfg(not(target_arch = "wasm32"))]
99
use libtest_mimic::Failed;
10+
#[cfg(not(target_arch = "wasm32"))]
11+
use tempfile::TempDir;
1012

1113
#[cfg(target_arch = "wasm32")]
1214
fn main() {}
@@ -48,10 +50,7 @@ fn main() {
4850
}),
4951
libtest_mimic::Trial::test(format!("png_{stem}"), {
5052
let in_path = in_path.clone();
51-
let out_path = manifest_dir
52-
.join("tests/output/png")
53-
.join(format!("{stem}.png"));
54-
move || smoke_test_png(in_path, out_path)
53+
move || smoke_test_png(in_path)
5554
}),
5655
]
5756
})
@@ -87,14 +86,15 @@ fn smoke_test_svg(in_path: PathBuf, out_path: PathBuf) -> Result<(), Failed> {
8786
}
8887

8988
#[cfg(not(target_arch = "wasm32"))]
90-
fn smoke_test_png(in_path: PathBuf, out_path: PathBuf) -> Result<(), Failed> {
91-
if out_path.exists() {
92-
fs::remove_file(&out_path)?;
93-
}
89+
fn smoke_test_png(in_path: PathBuf) -> Result<(), Failed> {
90+
let temp_dir = TempDir::new().expect("create temp dir");
91+
92+
let stem = in_path.file_stem().unwrap().to_str().unwrap();
93+
let out_path = temp_dir.path().join(format!("{stem}.png"));
9494

9595
let mut cmd = cargo_bin_cmd!("oxdraw");
9696
cmd.arg("--input")
97-
.arg(in_path)
97+
.arg(&in_path)
9898
.arg("--output")
9999
.arg(&out_path)
100100
.arg("--output-format")
@@ -103,10 +103,13 @@ fn smoke_test_png(in_path: PathBuf, out_path: PathBuf) -> Result<(), Failed> {
103103
cmd.assert().success();
104104

105105
let png_bytes = fs::read(&out_path)?;
106-
assert!(
107-
png_bytes.starts_with(b"\x89PNG\r\n\x1a\n"),
108-
"{} output should begin with the PNG magic header",
109-
out_path.display()
110-
);
106+
let starts_with_header = png_bytes.starts_with(b"\x89PNG\r\n\x1a\n");
107+
if !starts_with_header {
108+
let _ = temp_dir.keep();
109+
panic!(
110+
"{} output should begin with the PNG magic header",
111+
out_path.display()
112+
);
113+
}
111114
Ok(())
112115
}

tests/output/png/conditional.png

-3.91 MB
Binary file not shown.

tests/output/png/failure_modes.png

-2.5 MB
Binary file not shown.

tests/output/png/flow.png

-1.16 MB
Binary file not shown.
-6.4 MB
Binary file not shown.

tests/output/png/html_breaks.png

-1.37 MB
Binary file not shown.

tests/output/png/image_node.png

-3.18 MB
Binary file not shown.
-1.74 MB
Binary file not shown.

0 commit comments

Comments
 (0)