mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 10:07:28 +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"
|
||||
|
||||
|
|
506
src/graphlog.rs
506
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"
|
||||
@ many
|
||||
| lines
|
||||
| of
|
||||
| text
|
||||
o single line
|
||||
"
|
||||
}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@ many
|
||||
| lines
|
||||
| of
|
||||
| text
|
||||
o single line
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -371,25 +365,20 @@ 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"
|
||||
@
|
||||
|
|
||||
| many
|
||||
|
|
||||
| lines
|
||||
|
|
||||
| of
|
||||
|
|
||||
| text
|
||||
|
|
||||
|
|
||||
o single line
|
||||
"
|
||||
}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@
|
||||
|
|
||||
| many
|
||||
|
|
||||
| lines
|
||||
|
|
||||
| of
|
||||
|
|
||||
| text
|
||||
|
|
||||
|
|
||||
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"
|
||||
@ node 3
|
||||
o node 2
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@ node 3
|
||||
o node 2
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -427,19 +412,15 @@ 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"
|
||||
o node 7
|
||||
| o node 6
|
||||
o | node 5
|
||||
| o node 4
|
||||
@ | node 3
|
||||
| o node 2
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 7
|
||||
| o node 6
|
||||
o | node 5
|
||||
| o node 4
|
||||
@ | 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"
|
||||
o node 3
|
||||
~
|
||||
o node 2
|
||||
~
|
||||
@ node 1
|
||||
~
|
||||
"}
|
||||
);
|
||||
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"
|
||||
o node 4
|
||||
| o node 3
|
||||
o | node 2
|
||||
~/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
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"
|
||||
o node 4
|
||||
| o node 3
|
||||
o | node 2
|
||||
/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
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"
|
||||
o node 4
|
||||
| o node 3
|
||||
| o node 2
|
||||
| ~
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
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"
|
||||
o node 3
|
||||
| o node 2
|
||||
| ~ with
|
||||
| long
|
||||
| description
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
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"
|
||||
@ node 4
|
||||
| o node 3
|
||||
|/
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@ node 4
|
||||
| o node 3
|
||||
|/
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -609,24 +566,20 @@ 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"
|
||||
o node 10
|
||||
| o node 9
|
||||
| | o node 8
|
||||
o | | node 7
|
||||
| o | node 6
|
||||
| | o node 5
|
||||
o | | node 4
|
||||
| o | node 3
|
||||
|/ /
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 10
|
||||
| o node 9
|
||||
| | o node 8
|
||||
o | | node 7
|
||||
| o | node 6
|
||||
| | o node 5
|
||||
o | | node 4
|
||||
| o | node 3
|
||||
|/ /
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -641,20 +594,16 @@ 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"
|
||||
o node 5
|
||||
| o node 4
|
||||
| | o node 3
|
||||
| |/
|
||||
|/|
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 5
|
||||
| o node 4
|
||||
| | o node 3
|
||||
| |/
|
||||
|/|
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -671,23 +620,19 @@ 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"
|
||||
o node 7
|
||||
| o node 6
|
||||
| | o node 5
|
||||
| | | o node 4
|
||||
| |_|/
|
||||
|/| |
|
||||
| o | node 3
|
||||
|/ /
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 7
|
||||
| o node 6
|
||||
| | o node 5
|
||||
| | | o node 4
|
||||
| |_|/
|
||||
|/| |
|
||||
| o | node 3
|
||||
|/ /
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -703,21 +648,17 @@ 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"
|
||||
o node 6
|
||||
| o node 5
|
||||
| | o node 4
|
||||
o | | node 3
|
||||
| |/
|
||||
|/|
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 6
|
||||
| o node 5
|
||||
| | o node 4
|
||||
o | | node 3
|
||||
| |/
|
||||
|/|
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -742,23 +683,20 @@ 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"
|
||||
@---. node 5
|
||||
|\ \ \ more
|
||||
| | | | text
|
||||
| | | o node 4
|
||||
| | | ~
|
||||
| | o node 3
|
||||
| | ~
|
||||
| o node 2
|
||||
| ~
|
||||
o node 1
|
||||
~
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@---. node 5
|
||||
|\ \ \ more
|
||||
| | | | text
|
||||
| | | o node 4
|
||||
| | | ~
|
||||
| | o node 3
|
||||
| | ~
|
||||
| o node 2
|
||||
| ~
|
||||
o node 1
|
||||
~
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -780,28 +718,24 @@ 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"
|
||||
o node 8
|
||||
| o node 7
|
||||
| | o node 6
|
||||
| | | with
|
||||
| | | some
|
||||
| | | more
|
||||
| | | lines
|
||||
| o | node 5
|
||||
| |\ \
|
||||
| o | | node 4
|
||||
|/ / /
|
||||
| o | node 3
|
||||
|/ /
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 8
|
||||
| o node 7
|
||||
| | o node 6
|
||||
| | | with
|
||||
| | | some
|
||||
| | | more
|
||||
| | | lines
|
||||
| o | node 5
|
||||
| |\ \
|
||||
| o | | node 4
|
||||
|/ / /
|
||||
| o | node 3
|
||||
|/ /
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -822,21 +756,17 @@ 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"
|
||||
o node 6
|
||||
o-. node 5
|
||||
|\ \
|
||||
| | o node 4
|
||||
| o | node 3
|
||||
| |/
|
||||
o | node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 6
|
||||
o-. node 5
|
||||
|\ \
|
||||
| | o node 4
|
||||
| o | node 3
|
||||
| |/
|
||||
o | node 2
|
||||
|/
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -866,30 +796,26 @@ 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"
|
||||
o node 10
|
||||
| o node 9
|
||||
| | o node 8
|
||||
| | \
|
||||
| | \
|
||||
| o---. | node 7
|
||||
| |\ \ \ \
|
||||
| o | | | | node 6
|
||||
|/ / / / /
|
||||
| o | | | node 5
|
||||
|/ / / /
|
||||
| o | | node 4
|
||||
|/ / /
|
||||
| o | node 3
|
||||
|/ /
|
||||
| o node 2
|
||||
|/
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 10
|
||||
| o node 9
|
||||
| | o node 8
|
||||
| | \
|
||||
| | \
|
||||
| o---. | node 7
|
||||
| |\ \ \ \
|
||||
| o | | | | node 6
|
||||
|/ / / / /
|
||||
| o | | | node 5
|
||||
|/ / / /
|
||||
| o | | node 4
|
||||
|/ / /
|
||||
| o | node 3
|
||||
|/ /
|
||||
| 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"
|
||||
@---. node 1
|
||||
|\ \ \ with
|
||||
| | | ~ many
|
||||
| | ~ lines
|
||||
| ~ of
|
||||
~ text
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
@---. node 1
|
||||
|\ \ \ with
|
||||
| | | ~ many
|
||||
| | ~ lines
|
||||
| ~ of
|
||||
~ text
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -944,20 +866,16 @@ 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"
|
||||
o node 3
|
||||
| o---. node 2
|
||||
| |\ \ \ with
|
||||
| | : ~/ many
|
||||
| ~/ / lines
|
||||
|/ / of
|
||||
|/ text
|
||||
o node 1
|
||||
"}
|
||||
);
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
|
||||
o node 3
|
||||
| o---. node 2
|
||||
| |\ \ \ with
|
||||
| | : ~/ many
|
||||
| ~/ / lines
|
||||
|/ / of
|
||||
|/ text
|
||||
o node 1
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue