Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(fixtures): Move to snapbox with SVGs #86

Merged
merged 1 commit into from Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
422 changes: 402 additions & 20 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Expand Up @@ -32,12 +32,17 @@ criterion = "0.5.1"
difference = "2.0.0"
glob = "0.3.1"
serde = { version = "1.0.197", features = ["derive"] }
snapbox = { version = "0.5.8", features = ["diff", "harness", "path", "term-svg"] }
toml = "0.5.11"

[[bench]]
name = "simple"
harness = false

[[test]]
name = "fixtures"
harness = false

[features]
default = []
testing-colors = []
63 changes: 0 additions & 63 deletions tests/diff/mod.rs

This file was deleted.

File renamed without changes.
33 changes: 33 additions & 0 deletions tests/fixtures/main.rs
@@ -0,0 +1,33 @@
mod deserialize;

use crate::deserialize::Fixture;
use annotate_snippets::{Renderer, Snippet};
use snapbox::data::DataFormat;
use snapbox::Data;
use std::error::Error;

fn main() {
#[cfg(not(windows))]
epage marked this conversation as resolved.
Show resolved Hide resolved
snapbox::harness::Harness::new("tests/fixtures/", setup, test)
.select(["*/*.toml"])
.action_env("SNAPSHOTS")
.test();
}

fn setup(input_path: std::path::PathBuf) -> snapbox::harness::Case {
let name = input_path.file_name().unwrap().to_str().unwrap().to_owned();
let expected = input_path.with_extension("svg");
snapbox::harness::Case {
name,
fixture: input_path,
expected,
}
}

fn test(input_path: &std::path::Path) -> Result<Data, Box<dyn Error>> {
let src = std::fs::read_to_string(input_path)?;
let (renderer, snippet): (Renderer, Snippet<'_>) =
toml::from_str(&src).map(|a: Fixture| (a.renderer.into(), a.snippet.into()))?;
let actual = renderer.render(snippet).to_string();
Ok(Data::from(actual).coerce_to(DataFormat::TermSvg))
}
35 changes: 35 additions & 0 deletions tests/fixtures/no-color/issue_52.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions tests/fixtures/no-color/issue_52.txt

This file was deleted.

45 changes: 45 additions & 0 deletions tests/fixtures/no-color/issue_9.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 0 additions & 12 deletions tests/fixtures/no-color/issue_9.txt

This file was deleted.

49 changes: 49 additions & 0 deletions tests/fixtures/no-color/multiline_annotation.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions tests/fixtures/no-color/multiline_annotation.txt

This file was deleted.

39 changes: 39 additions & 0 deletions tests/fixtures/no-color/multiline_annotation2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions tests/fixtures/no-color/multiline_annotation2.txt

This file was deleted.

39 changes: 39 additions & 0 deletions tests/fixtures/no-color/multiline_annotation3.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions tests/fixtures/no-color/multiline_annotation3.txt

This file was deleted.