Skip to content

Commit

Permalink
Auto merge of #13098 - epage:snap, r=weihanglo
Browse files Browse the repository at this point in the history
test(mdman): Switch to snapbox

Working with #13090 is the motivation

Benefits
- We use it elsewhere
- We don't have to bake in our own snapshotting solution
- It is more obvious how to update the snapshots
  • Loading branch information
bors committed Dec 1, 2023
2 parents aa6e46e + 96f8517 commit f023d05
Show file tree
Hide file tree
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
Expand Up @@ -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.4.0"
pulldown-cmark = { version = "0.9.3", default-features = false }
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion crates/mdman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}

Expand Down
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());
}
}
}
Expand Down

0 comments on commit f023d05

Please sign in to comment.