Skip to content

Commit 027c95b

Browse files
authored
Merge pull request #86 from Muscraft/use-snapbox-for-testing
refactor(fixtures): Move to snapbox with SVGs
2 parents e9b445c + ad80183 commit 027c95b

28 files changed

+867
-227
lines changed

Cargo.lock

+402-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ criterion = "0.5.1"
3232
difference = "2.0.0"
3333
glob = "0.3.1"
3434
serde = { version = "1.0.197", features = ["derive"] }
35+
snapbox = { version = "0.5.8", features = ["diff", "harness", "path", "term-svg"] }
3536
toml = "0.5.11"
3637

3738
[[bench]]
3839
name = "simple"
3940
harness = false
4041

42+
[[test]]
43+
name = "fixtures"
44+
harness = false
45+
4146
[features]
4247
default = []
4348
testing-colors = []

tests/diff/mod.rs

-63
This file was deleted.
File renamed without changes.

tests/fixtures/main.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
mod deserialize;
2+
3+
use crate::deserialize::Fixture;
4+
use annotate_snippets::{Renderer, Snippet};
5+
use snapbox::data::DataFormat;
6+
use snapbox::Data;
7+
use std::error::Error;
8+
9+
fn main() {
10+
#[cfg(not(windows))]
11+
snapbox::harness::Harness::new("tests/fixtures/", setup, test)
12+
.select(["*/*.toml"])
13+
.action_env("SNAPSHOTS")
14+
.test();
15+
}
16+
17+
fn setup(input_path: std::path::PathBuf) -> snapbox::harness::Case {
18+
let name = input_path.file_name().unwrap().to_str().unwrap().to_owned();
19+
let expected = input_path.with_extension("svg");
20+
snapbox::harness::Case {
21+
name,
22+
fixture: input_path,
23+
expected,
24+
}
25+
}
26+
27+
fn test(input_path: &std::path::Path) -> Result<Data, Box<dyn Error>> {
28+
let src = std::fs::read_to_string(input_path)?;
29+
let (renderer, snippet): (Renderer, Snippet<'_>) =
30+
toml::from_str(&src).map(|a: Fixture| (a.renderer.into(), a.snippet.into()))?;
31+
let actual = renderer.render(snippet).to_string();
32+
Ok(Data::from(actual).coerce_to(DataFormat::TermSvg))
33+
}

tests/fixtures/no-color/issue_52.svg

+35
Loading

tests/fixtures/no-color/issue_52.txt

-7
This file was deleted.

tests/fixtures/no-color/issue_9.svg

+45
Loading

tests/fixtures/no-color/issue_9.txt

-12
This file was deleted.
Loading

tests/fixtures/no-color/multiline_annotation.txt

-14
This file was deleted.
Loading

tests/fixtures/no-color/multiline_annotation2.txt

-9
This file was deleted.
Loading

tests/fixtures/no-color/multiline_annotation3.txt

-9
This file was deleted.

0 commit comments

Comments
 (0)