Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mdman): Switch to snapbox
Browse files Browse the repository at this point in the history
- We use it elsewhere
- We don't have to bake our own snapshotting solution
- It is more obvious how to update the snapshots
epage committed Dec 1, 2023
1 parent b97cffe commit eaeecd7
Showing 5 changed files with 7 additions and 42 deletions.
24 changes: 1 addition & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -69,7 +69,6 @@ pasetors = { version = "0.6.7", features = ["v3", "paserk", "std", "serde"] }
pathdiff = "0.2"
percent-encoding = "2.3"
pkg-config = "0.3.27"
pretty_assertions = "1.4.0"
proptest = "1.3.1"
pulldown-cmark = { version = "0.9.3", default-features = false }
rand = "0.8.5"
2 changes: 1 addition & 1 deletion crates/mdman/Cargo.toml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ serde_json.workspace = true
url.workspace = true

[dev-dependencies]
pretty_assertions.workspace = true
snapbox.workspace = true

[lints]
workspace = true
16 changes: 2 additions & 14 deletions crates/mdman/tests/compare.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
//! Compares input to expected output.
//!
//! Use the MDMAN_BLESS environment variable to automatically update the
//! expected output.
#![allow(clippy::disallowed_methods)]
use std::path::PathBuf;

use mdman::{Format, ManMap};
use pretty_assertions::assert_eq;
use std::path::PathBuf;
use url::Url;

fn run(name: &str) {
@@ -27,14 +22,7 @@ fn run(name: &str) {
name,
format.extension(section)
);
if std::env::var("MDMAN_BLESS").is_ok() {
std::fs::write(&expected_path, result).unwrap();
} else {
let expected = std::fs::read_to_string(&expected_path).unwrap();
// Fix if Windows checked out with autocrlf.
let expected = expected.replace("\r\n", "\n");
assert_eq!(expected, result);
}
snapbox::assert_eq_path(expected_path, result);
}
}

6 changes: 3 additions & 3 deletions crates/mdman/tests/invalid.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! Tests for errors and invalid input.
use mdman::{Format, ManMap};
use pretty_assertions::assert_eq;
use std::path::PathBuf;

use mdman::{Format, ManMap};

fn run(name: &str, expected_error: &str) {
let input = PathBuf::from(format!("tests/invalid/{}", name));
match mdman::convert(&input, Format::Man, None, ManMap::new()) {
Ok(_) => {
panic!("expected {} to fail", name);
}
Err(e) => {
assert_eq!(expected_error, e.to_string());
snapbox::assert_eq(expected_error, e.to_string());
}
}
}

0 comments on commit eaeecd7

Please sign in to comment.