mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
graphlog: use insta
for tests
It's much easier to update the tests with `insta`. It also presents you with the bad output including real newlines (a diff, actually), so we can remove the `println!()` calls we had in order to get readable output without escaped newlines.
This commit is contained in:
parent
6483aeefea
commit
866539f977
4 changed files with 214 additions and 302 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -646,12 +646,6 @@ dependencies = [
|
|||
"hashbrown 0.11.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indoc"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05a0bd019339e5d968b37855180087b7b9d512c5046fbd244cf8c95687927d6e"
|
||||
|
||||
[[package]]
|
||||
name = "insta"
|
||||
version = "1.14.0"
|
||||
|
@ -741,7 +735,6 @@ dependencies = [
|
|||
"dirs",
|
||||
"git2",
|
||||
"hex",
|
||||
"indoc",
|
||||
"insta",
|
||||
"itertools",
|
||||
"jujutsu-lib",
|
||||
|
@ -771,6 +764,7 @@ dependencies = [
|
|||
"config",
|
||||
"git2",
|
||||
"hex",
|
||||
"insta",
|
||||
"itertools",
|
||||
"maplit",
|
||||
"num_cpus",
|
||||
|
|
|
@ -44,7 +44,6 @@ criterion = "0.3.5"
|
|||
dirs = "4.0.0"
|
||||
git2 = "0.14.2"
|
||||
hex = "0.4.3"
|
||||
indoc = "1.0.6"
|
||||
itertools = "0.10.3"
|
||||
jujutsu-lib = { version = "=0.4.0", path = "lib"}
|
||||
maplit = "1.0.2"
|
||||
|
|
|
@ -42,6 +42,7 @@ zstd = "0.11.1"
|
|||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.5.0"
|
||||
insta = "1.14.0"
|
||||
num_cpus = "1.13.1"
|
||||
test-case = "2.0.2"
|
||||
|
||||
|
|
170
src/graphlog.rs
170
src/graphlog.rs
|
@ -319,8 +319,6 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use indoc::indoc;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
@ -329,8 +327,9 @@ mod tests {
|
|||
let mut graph = AsciiGraphDrawer::new(&mut buffer);
|
||||
graph.add_node(&1, &[], b"@", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(String::from_utf8_lossy(&buffer), "@ node 1\n");
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@ node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -342,18 +341,13 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"@", b"many\nlines\nof\ntext\n")?;
|
||||
graph.add_node(&1, &[], b"o", b"single line")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@ many
|
||||
| lines
|
||||
| of
|
||||
| text
|
||||
o single line
|
||||
"
|
||||
}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -371,10 +365,7 @@ mod tests {
|
|||
graph.add_node(&1, &[], b"o", b"single line")?;
|
||||
|
||||
// A final newline is ignored but all other newlines are respected.
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@
|
||||
|
|
||||
| many
|
||||
|
@ -387,9 +378,7 @@ mod tests {
|
|||
|
|
||||
|
|
||||
o single line
|
||||
"
|
||||
}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -402,15 +391,11 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@ node 3
|
||||
o node 2
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -427,10 +412,7 @@ mod tests {
|
|||
graph.add_node(&2, &[], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 7
|
||||
| o node 6
|
||||
o | node 5
|
||||
|
@ -438,8 +420,7 @@ mod tests {
|
|||
@ | node 3
|
||||
| o node 2
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -452,18 +433,14 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[Edge::missing()], b"@", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 3
|
||||
~
|
||||
o node 2
|
||||
~
|
||||
@ node 1
|
||||
~
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -477,17 +454,13 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 4
|
||||
| o node 3
|
||||
o | node 2
|
||||
~/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -501,17 +474,13 @@ mod tests {
|
|||
graph.add_node(&2, &[], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 4
|
||||
| o node 3
|
||||
o | node 2
|
||||
/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -525,17 +494,13 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 4
|
||||
| o node 3
|
||||
| o node 2
|
||||
| ~
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -553,18 +518,14 @@ mod tests {
|
|||
)?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 3
|
||||
| o node 2
|
||||
| ~ with
|
||||
| long
|
||||
| description
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -578,18 +539,14 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@ node 4
|
||||
| o node 3
|
||||
|/
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -609,10 +566,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 10
|
||||
| o node 9
|
||||
| | o node 8
|
||||
|
@ -625,8 +579,7 @@ mod tests {
|
|||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -641,10 +594,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 5
|
||||
| o node 4
|
||||
| | o node 3
|
||||
|
@ -653,8 +603,7 @@ mod tests {
|
|||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -671,10 +620,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 7
|
||||
| o node 6
|
||||
| | o node 5
|
||||
|
@ -686,8 +632,7 @@ mod tests {
|
|||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -703,10 +648,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 6
|
||||
| o node 5
|
||||
| | o node 4
|
||||
|
@ -716,8 +658,7 @@ mod tests {
|
|||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -742,10 +683,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[Edge::missing()], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@---. node 5
|
||||
|\ \ \ more
|
||||
| | | | text
|
||||
|
@ -757,8 +695,8 @@ mod tests {
|
|||
| ~
|
||||
o node 1
|
||||
~
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -780,10 +718,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 8
|
||||
| o node 7
|
||||
| | o node 6
|
||||
|
@ -800,8 +735,7 @@ mod tests {
|
|||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -822,10 +756,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 6
|
||||
o-. node 5
|
||||
|\ \
|
||||
|
@ -835,8 +766,7 @@ mod tests {
|
|||
o | node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -866,10 +796,7 @@ mod tests {
|
|||
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 10
|
||||
| o node 9
|
||||
| | o node 8
|
||||
|
@ -888,8 +815,7 @@ mod tests {
|
|||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -910,18 +836,14 @@ mod tests {
|
|||
b"node 1\nwith\nmany\nlines\nof\ntext",
|
||||
)?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@---. node 1
|
||||
|\ \ \ with
|
||||
| | | ~ many
|
||||
| | ~ lines
|
||||
| ~ of
|
||||
~ text
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -944,10 +866,7 @@ mod tests {
|
|||
)?;
|
||||
graph.add_node(&1, &[], b"o", b"node 1")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&buffer));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&buffer),
|
||||
indoc! {r"
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 3
|
||||
| o---. node 2
|
||||
| |\ \ \ with
|
||||
|
@ -956,8 +875,7 @@ mod tests {
|
|||
|/ / of
|
||||
|/ text
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue