diff options
author | Lawrence Chou <lawrencechou1024@gmail.com> | 2018-10-15 23:22:23 +0800 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2018-10-19 21:04:46 +0200 |
commit | 58198d070070c4cf0f6c9dbac43481b8d7b445c7 (patch) | |
tree | 0ebe453f516134044df0c24603745840b6544146 | |
parent | afc5aacb28563bbe0019a922d536660a14279da6 (diff) |
rewrite 6 snapshot tests as integration test
-rw-r--r-- | tests/examples/tabs.txt | 10 | ||||
-rw-r--r-- | tests/integration_tests.rs | 127 | ||||
-rw-r--r-- | tests/snapshots/output/tabs_4.snapshot.txt | 40 | ||||
-rw-r--r-- | tests/snapshots/output/tabs_4_wrapped.snapshot.txt | 40 | ||||
-rw-r--r-- | tests/snapshots/output/tabs_8.snapshot.txt | 40 | ||||
-rw-r--r-- | tests/snapshots/output/tabs_8_wrapped.snapshot.txt | 40 | ||||
-rw-r--r-- | tests/snapshots/output/tabs_passthrough.snapshot.txt | 40 | ||||
-rw-r--r-- | tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt | 40 |
8 files changed, 124 insertions, 253 deletions
diff --git a/tests/examples/tabs.txt b/tests/examples/tabs.txt new file mode 100644 index 00000000..ba3da432 --- /dev/null +++ b/tests/examples/tabs.txt @@ -0,0 +1,10 @@ + + 1 2 3 4 +1 ? +22 ? +333 ? +4444 ? +55555 ? +666666 ? +7777777 ? +88888888 ? diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index c1af27fc..278c2bac 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,10 +1,7 @@ extern crate assert_cmd; -mod tester; - use assert_cmd::prelude::*; use std::process::Command; -use tester::BatTester; fn bat() -> Command { let mut cmd = Command::main_binary().unwrap(); @@ -15,10 +12,6 @@ fn bat() -> Command { cmd } -fn tester() -> BatTester { - BatTester::new() -} - #[test] fn basic() { bat() @@ -105,32 +98,140 @@ fn line_range_last_3() { #[test] fn tabs_passthrough_wrapped() { - tester().test_snapshot("tabs_passthrough_wrapped", "full", 0, true); + bat() + .arg("tabs.txt") + .arg("--tabs=0") + .arg("--wrap=character") + .arg("--style=plain") + .arg("--decorations=always") + .assert() + .success() + .stdout(" + 1 2 3 4 +1 ? +22 ? +333 ? +4444 ? +55555 ? +666666 ? +7777777 ? +88888888 ? +"); } #[test] fn tabs_4_wrapped() { - tester().test_snapshot("tabs_4_wrapped", "full", 4, true); + bat() + .arg("tabs.txt") + .arg("--tabs=4") + .arg("--wrap=character") + .arg("--style=plain") + .arg("--decorations=always") + .assert() + .success() + .stdout(" + 1 2 3 4 +1 ? +22 ? +333 ? +4444 ? +55555 ? +666666 ? +7777777 ? +88888888 ? +"); } #[test] fn tabs_8_wrapped() { - tester().test_snapshot("tabs_8_wrapped", "full", 8, true); + bat() + .arg("tabs.txt") + .arg("--tabs=8") + .arg("--wrap=character") + .arg("--style=plain") + .arg("--decorations=always") + .assert() + .success() + .stdout(" + 1 2 3 4 +1 ? +22 ? +333 ? +4444 ? +55555 ? +666666 ? +7777777 ? +88888888 ? +"); } #[test] fn tabs_passthrough() { - tester().test_snapshot("tabs_passthrough", "full", 0, false); + bat() + .arg("tabs.txt") + .arg("--tabs=0") + .arg("--wrap=never") + .arg("--style=plain") + .arg("--decorations=always") + .assert() + .success() + .stdout(" + 1 2 3 4 +1 ? +22 ? +333 ? +4444 ? +55555 ? +666666 ? +7777777 ? +88888888 ? +"); } #[test] fn tabs_4() { - tester().test_snapshot("tabs_4", "full", 4, false); + bat() + .arg("tabs.txt") + .arg("--tabs=4") + .arg("--wrap=never") + .arg("--style=plain") + .arg("--decorations=always") + .assert() + .success() + .stdout(" + 1 2 3 4 +1 ? +22 ? +333 ? +4444 ? +55555 ? +666666 ? +7777777 ? +88888888 ? +"); } #[test] fn tabs_8() { - tester().test_snapshot("tabs_8", "full", 8, false); + bat() + .arg("tabs.txt") + .arg("--tabs=8") + .arg("--wrap=never") + .arg("--style=plain") + .arg("--decorations=always") + .assert() + .success() + .stdout(" + 1 2 3 4 +1 ? +22 ? +333 ? +4444 ? +55555 ? +666666 ? +7777777 ? +88888888 ? +"); } #[test] diff --git a/tests/snapshots/output/tabs_4.snapshot.txt b/tests/snapshots/output/tabs_4.snapshot.txt deleted file mode 100644 index 87689c7b..00000000 --- a/tests/snapshots/output/tabs_4.snapshot.txt +++ /dev/null @@ -1,40 +0,0 @@ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: sample.rs -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ struct Rectangle { - 2 │ width: u32, - 3 │ height: u32, - 4 │ } - 5 │ - 6 _ │ fn main() { - 7 │ let rect1 = Rectangle { width: 30, height: 50 }; - 8 │ - 9 │ println!( - 10 ~ │ "The perimeter of the rectangle is {} pixels.", - 11 ~ │ perimeter(&rect1) - 12 │ ); - 13 + │ println!(r#"This line contains invalid utf8: "�����"#; - 14 │ } - 15 │ - 16 │ fn area(rectangle: &Rectangle) -> u32 { - 17 │ rectangle.width * rectangle.height - 18 │ } - 19 │ - 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { - 21 + │ (rectangle.width + rectangle.height) * 2 - 22 + │ } - 23 + │ - 24 │ // Tab alignment: - 25 │ /* - 26 │ Indent - 27 │ 1 2 3 4 - 28 │ 1 ? - 29 │ 22 ? - 30 │ 333 ? - 31 │ 4444 ? - 32 │ 55555 ? - 33 │ 666666 ? - 34 │ 7777777 ? - 35 │ 88888888 ? - 36 ~ │ */ -───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/tabs_4_wrapped.snapshot.txt b/tests/snapshots/output/tabs_4_wrapped.snapshot.txt deleted file mode 100644 index 87689c7b..00000000 --- a/tests/snapshots/output/tabs_4_wrapped.snapshot.txt +++ /dev/null @@ -1,40 +0,0 @@ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: sample.rs -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ struct Rectangle { - 2 │ width: u32, - 3 │ height: u32, - 4 │ } - 5 │ - 6 _ │ fn main() { - 7 │ let rect1 = Rectangle { width: 30, height: 50 }; - 8 │ - 9 │ println!( - 10 ~ │ "The perimeter of the rectangle is {} pixels.", - 11 ~ │ perimeter(&rect1) - 12 │ ); - 13 + │ println!(r#"This line contains invalid utf8: "�����"#; - 14 │ } - 15 │ - 16 │ fn area(rectangle: &Rectangle) -> u32 { - 17 │ rectangle.width * rectangle.height - 18 │ } - 19 │ - 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { - 21 + │ (rectangle.width + rectangle.height) * 2 - 22 + │ } - 23 + │ - 24 │ // Tab alignment: - 25 │ /* - 26 │ Indent - 27 │ 1 2 3 4 - 28 │ 1 ? - 29 │ 22 ? - 30 │ 333 ? - 31 │ 4444 ? - 32 │ 55555 ? - 33 │ 666666 ? - 34 │ 7777777 ? - 35 │ 88888888 ? - 36 ~ │ */ -───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/tabs_8.snapshot.txt b/tests/snapshots/output/tabs_8.snapshot.txt deleted file mode 100644 index 221306da..00000000 --- a/tests/snapshots/output/tabs_8.snapshot.txt +++ /dev/null @@ -1,40 +0,0 @@ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: sample.rs -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ struct Rectangle { - 2 │ width: u32, - 3 │ height: u32, - 4 │ } - 5 │ - 6 _ │ fn main() { - 7 │ let rect1 = Rectangle { width: 30, height: 50 }; - 8 │ - 9 │ println!( - 10 ~ │ "The perimeter of the rectangle is {} pixels.", - 11 ~ │ perimeter(&rect1) - 12 │ ); - 13 + │ println!(r#"This line contains invalid utf8: "�����"#; - 14 │ } - 15 │ - 16 │ fn area(rectangle: &Rectangle) -> u32 { - 17 │ rectangle.width * rectangle.height - 18 │ } - 19 │ - 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { - 21 + │ (rectangle.width + rectangle.height) * 2 - 22 + │ } - 23 + │ - 24 │ // Tab alignment: - 25 │ /* - 26 │ Indent - 27 │ 1 2 3 4 - 28 │ 1 ? - 29 │ 22 ? - 30 │ 333 ? - 31 │ 4444 ? - 32 │ 55555 ? - 33 │ 666666 ? - 34 │ 7777777 ? - 35 │ 88888888 ? - 36 ~ │ */ -───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/tabs_8_wrapped.snapshot.txt b/tests/snapshots/output/tabs_8_wrapped.snapshot.txt deleted file mode 100644 index 221306da..00000000 --- a/tests/snapshots/output/tabs_8_wrapped.snapshot.txt +++ /dev/null @@ -1,40 +0,0 @@ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: sample.rs -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ struct Rectangle { - 2 │ width: u32, - 3 │ height: u32, - 4 │ } - 5 │ - 6 _ │ fn main() { - 7 │ let rect1 = Rectangle { width: 30, height: 50 }; - 8 │ - 9 │ println!( - 10 ~ │ "The perimeter of the rectangle is {} pixels.", - 11 ~ │ perimeter(&rect1) - 12 │ ); - 13 + │ println!(r#"This line contains invalid utf8: "�����"#; - 14 │ } - 15 │ - 16 │ fn area(rectangle: &Rectangle) -> u32 { - 17 │ rectangle.width * rectangle.height - 18 │ } - 19 │ - 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { - 21 + │ (rectangle.width + rectangle.height) * 2 - 22 + │ } - 23 + │ - 24 │ // Tab alignment: - 25 │ /* - 26 │ Indent - 27 │ 1 2 3 4 - 28 │ 1 ? - 29 │ 22 ? - 30 │ 333 ? - 31 │ 4444 ? - 32 │ 55555 ? - 33 │ 666666 ? - 34 │ 7777777 ? - 35 │ 88888888 ? - 36 ~ │ */ -───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/tabs_passthrough.snapshot.txt b/tests/snapshots/output/tabs_passthrough.snapshot.txt deleted file mode 100644 index 3ad018a1..00000000 --- a/tests/snapshots/output/tabs_passthrough.snapshot.txt +++ /dev/null @@ -1,40 +0,0 @@ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: sample.rs -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ struct Rectangle { - 2 │ width: u32, - 3 │ height: u32, - 4 │ } - 5 │ - 6 _ │ fn main() { - 7 │ let rect1 = Rectangle { width: 30, height: 50 }; - 8 │ - 9 │ println!( - 10 ~ │ "The perimeter of the rectangle is {} pixels.", - 11 ~ │ perimeter(&rect1) - 12 │ ); - 13 + │ println!(r#"This line contains invalid utf8: "�����"#; - 14 │ } - 15 │ - 16 │ fn area(rectangle: &Rectangle) -> u32 { - 17 │ rectangle.width * rectangle.height - 18 │ } - 19 │ - 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { - 21 + │ (rectangle.width + rectangle.height) * 2 - 22 + │ } - 23 + │ - 24 │ // Tab alignment: - 25 │ /* - 26 │ Indent - 27 │ 1 2 3 4 - 28 │ 1 ? - 29 │ 22 ? - 30 │ 333 ? - 31 │ 4444 ? - 32 │ 55555 ? - 33 │ 666666 ? - 34 │ 7777777 ? - 35 │ 88888888 ? - 36 ~ │ */ -───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt b/tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt deleted file mode 100644 index 3ad018a1..00000000 --- a/tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt +++ /dev/null @@ -1,40 +0,0 @@ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: sample.rs -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ struct Rectangle { - 2 │ width: u32, - 3 │ height: u32, - 4 │ } - 5 │ - 6 _ │ fn main() { - 7 │ let rect1 = Rectangle { width: 30, height: 50 }; - 8 │ - 9 │ println!( - 10 ~ │ "The perimeter of the rectangle is {} pixels.", - 11 ~ │ perimeter(&rect1) - 12 │ ); - 13 + │ println!(r#"This line contains invalid utf8: "�����"#; - 14 │ } - 15 │ - 16 │ fn area(rectangle: &Rectangle) -> u32 { - 17 │ rectangle.width * rectangle.height - 18 │ } - 19 │ - 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { - 21 + │ (rectangle.width + rectangle.height) * 2 - 22 + │ } - 23 + │ - 24 │ // Tab alignment: - 25 │ /* - 26 │ Indent - 27 │ 1 2 3 4 - 28 │ 1 ? - 29 │ 22 ? - 30 │ 333 ? - 31 │ 4444 ? - 32 │ 55555 ? - 33 │ 666666 ? - 34 │ 7777777 ? - 35 │ 88888888 ? - 36 ~ │ */ -───────┴──────────────────────────────────────────────────────────────────────── |