Skip to content

Commit

Permalink
Update similar, switch to patience diff and add timeout (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Feb 27, 2021
1 parent fd7cb13 commit 02b1c88
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ All notable changes to insta and cargo-insta are documented here.

* Added support for u128/i128. (#169)
* Normalize newlines to unix before before asserting. (#172)
* Switch diffing to patience. (#173)

## 1.6.3

Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -48,3 +48,6 @@ globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
uuid = "0.8.1"
similar = { version = "1.3.0", features = ["inline"] }

[dev-dependencies]
similar-asserts = "1.1.0"
1 change: 1 addition & 0 deletions src/redaction.rs
Expand Up @@ -469,6 +469,7 @@ impl<'a> Selector<'a> {

#[test]
fn test_range_checks() {
use similar_asserts::assert_eq;
assert_eq!(PathItem::Index(0, 10).range_check(None, Some(-1)), true);
assert_eq!(PathItem::Index(9, 10).range_check(None, Some(-1)), false);
assert_eq!(PathItem::Index(0, 10).range_check(Some(1), Some(-1)), false);
Expand Down
10 changes: 8 additions & 2 deletions src/runtime.rs
Expand Up @@ -9,9 +9,10 @@ use std::process::{Command, Stdio};
use std::str;
use std::sync::Mutex;
use std::thread;
use std::time::Duration;

use lazy_static::lazy_static;
use similar::{ChangeTag, TextDiff};
use similar::{Algorithm, ChangeTag, TextDiff};

use serde::Deserialize;

Expand Down Expand Up @@ -208,7 +209,10 @@ pub fn get_cargo_workspace(manifest_dir: &str) -> &Path {

fn print_changeset(old: &str, new: &str, expr: Option<&str>) {
let width = term_width();
let diff = TextDiff::from_lines(old, new);
let diff = TextDiff::configure()
.algorithm(Algorithm::Patience)
.timeout(Duration::from_millis(500))
.diff_lines(old, new);

if let Some(expr) = expr {
println!("{:─^1$}", "", width,);
Expand Down Expand Up @@ -642,6 +646,7 @@ fn min_indentation(snapshot: &str) -> usize {

#[test]
fn test_min_indentation() {
use similar_asserts::assert_eq;
let t = r#"
1
2
Expand Down Expand Up @@ -709,6 +714,7 @@ fn normalize_inline_snapshot(snapshot: &str) -> String {

#[test]
fn test_normalize_inline_snapshot() {
use similar_asserts::assert_eq;
// here we do exact matching (rather than `assert_snapshot`)
// to ensure we're not incorporating the modifications this library makes
let t = r#"
Expand Down
1 change: 1 addition & 0 deletions src/snapshot.rs
Expand Up @@ -333,6 +333,7 @@ impl PartialEq for SnapshotContents {

#[test]
fn test_snapshot_contents() {
use similar_asserts::assert_eq;
let snapshot_contents = SnapshotContents("testing".to_string());
assert_eq!(snapshot_contents.to_inline(0), r#""testing""#);

Expand Down
4 changes: 3 additions & 1 deletion tests/test_clash_detection.rs
@@ -1,6 +1,8 @@
use std::env;
use std::thread;

use similar_asserts::assert_eq;

#[test]
fn test_clash_detection() {
let old_update_value = env::var("INSTA_UPDATE");
Expand Down Expand Up @@ -42,6 +44,6 @@ fn test_clash_detection() {
values.sort();
assert_eq!(&values[..], &vec![
"Insta snapshot name clash detected between \'foo_always_missing\' and \'test_foo_always_missing\' in \'test_clash_detection\'. Rename one function.",
"snapshot assertion for \'foo_always_missing\' failed in line 14",
"snapshot assertion for \'foo_always_missing\' failed in line 16",
][..]);
}
2 changes: 2 additions & 0 deletions tests/test_redaction.rs
Expand Up @@ -6,6 +6,8 @@ use insta::{
};
use serde::Serialize;

use similar_asserts::assert_eq;

#[test]
fn test_selector_parser() {
macro_rules! assert_selector_snapshot {
Expand Down

0 comments on commit 02b1c88

Please sign in to comment.