mirror of
https://github.com/sharkdp/bat.git
synced 2024-12-22 06:20:44 +01:00
Add simple integration tests
This commit is contained in:
parent
d2d01b9fe8
commit
1891e194b5
64
Cargo.lock
generated
64
Cargo.lock
generated
@ -22,6 +22,17 @@ dependencies = [
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"escargot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.11"
|
||||
@ -47,6 +58,7 @@ version = "0.7.1"
|
||||
dependencies = [
|
||||
"ansi_colours 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"assert_cmd 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -148,6 +160,11 @@ dependencies = [
|
||||
"memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "difference"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "directories"
|
||||
version = "1.0.2"
|
||||
@ -219,6 +236,15 @@ name = "error-chain"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "escargot"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.3"
|
||||
@ -459,6 +485,29 @@ dependencies = [
|
||||
"xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.20"
|
||||
@ -604,6 +653,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
name = "serde"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
@ -728,6 +780,11 @@ dependencies = [
|
||||
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "treeline"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ucd-util"
|
||||
version = "0.1.1"
|
||||
@ -874,6 +931,7 @@ dependencies = [
|
||||
"checksum aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "68f56c7353e5a9547cbd76ed90f7bb5ffc3ba09d4ea9bd1d8c06c8b1142eeb5a"
|
||||
"checksum ansi_colours 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0f302a81afc6a7f4350c04f0ba7cfab529cc009bca3324b3fb5764e6add8b6"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum assert_cmd 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d5db841dcfb4f172f34ec968f71c4a88e69f5421fb33e0daac6bfe4372317526"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
|
||||
"checksum bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f2fb9e29e72fd6bc12071533d5dc7664cb01480c59406f656d7ac25c7bd8ff7"
|
||||
@ -886,6 +944,7 @@ dependencies = [
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd48adf136733979b49e15bc3b4c43cc0d3c85ece7bd08e6daa414c6fcb13e6"
|
||||
"checksum content_inspector 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f15b971ded7c58a746a1c7441c358800337e08f869f75ddd825672984563fafc"
|
||||
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
"checksum directories 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72d337a64190607d4fcca2cb78982c5dd57f4916e19696b48a575fa746b6cb0f"
|
||||
"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
|
||||
"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
|
||||
@ -895,6 +954,7 @@ dependencies = [
|
||||
"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
|
||||
"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
|
||||
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
|
||||
"checksum escargot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19db1f7e74438642a5018cdf263bb1325b2e792f02dd0a3ca6d6c0f0d7b1d5a5"
|
||||
"checksum flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4af030962d89d62aa52cd9492083b1cd9b2d1a77764878102a6c0f86b4d5444d"
|
||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||
@ -925,6 +985,9 @@ dependencies = [
|
||||
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
|
||||
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
|
||||
"checksum plist 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c7316832d9ac5da02786bdc89a3faf0ca07070212b388766e969078fd593edc"
|
||||
"checksum predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa984b7cd021a0bf5315bcce4c4ae61d2a535db2a8d288fc7578638690a7b7c3"
|
||||
"checksum predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178"
|
||||
"checksum predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124"
|
||||
"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5"
|
||||
@ -958,6 +1021,7 @@ dependencies = [
|
||||
"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
|
||||
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
|
||||
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
|
||||
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
|
||||
"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25"
|
||||
|
@ -47,6 +47,7 @@ features = []
|
||||
|
||||
[dev-dependencies]
|
||||
tempdir = "0.3"
|
||||
assert_cmd = "0.10.1"
|
||||
|
||||
[build-dependencies]
|
||||
clap = "2.32"
|
||||
|
4
tests/examples/multiline.txt
Normal file
4
tests/examples/multiline.txt
Normal file
@ -0,0 +1,4 @@
|
||||
line 1
|
||||
line 2
|
||||
line 3
|
||||
line 4
|
0
tests/examples/sub_directory/dummy.txt
Normal file
0
tests/examples/sub_directory/dummy.txt
Normal file
1
tests/examples/test.txt
Normal file
1
tests/examples/test.txt
Normal file
@ -0,0 +1 @@
|
||||
hello world
|
104
tests/integration_tests.rs
Normal file
104
tests/integration_tests.rs
Normal file
@ -0,0 +1,104 @@
|
||||
extern crate assert_cmd;
|
||||
|
||||
use assert_cmd::prelude::*;
|
||||
use std::process::Command;
|
||||
|
||||
fn bat() -> Command {
|
||||
let mut cmd = Command::main_binary().unwrap();
|
||||
cmd.current_dir("tests/examples");
|
||||
cmd
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
bat()
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("hello world\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stdin() {
|
||||
bat()
|
||||
.with_stdin()
|
||||
.buffer("foo\nbar\n")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("foo\nbar\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concatenate() {
|
||||
bat()
|
||||
.arg("test.txt")
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("hello world\nhello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concatenate_stdin() {
|
||||
bat()
|
||||
.arg("test.txt")
|
||||
.arg("-")
|
||||
.arg("test.txt")
|
||||
.with_stdin()
|
||||
.buffer("stdin\n")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("hello world\nstdin\nhello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_numbers() {
|
||||
bat()
|
||||
.arg("multiline.txt")
|
||||
.arg("--style=numbers")
|
||||
.arg("--decorations=always")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_range_2_3() {
|
||||
bat()
|
||||
.arg("multiline.txt")
|
||||
.arg("--line-range=2:3")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("line 2\nline 3\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_range_first_two() {
|
||||
bat()
|
||||
.arg("multiline.txt")
|
||||
.arg("--line-range=:2")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("line 1\nline 2\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_range_last_3() {
|
||||
bat()
|
||||
.arg("multiline.txt")
|
||||
.arg("--line-range=2:")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("line 2\nline 3\nline 4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fail_non_existing() {
|
||||
bat().arg("non-existing-file").assert().failure();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fail_directory() {
|
||||
bat().arg("sub_directory").assert().failure();
|
||||
}
|
41
tests/snapshot_tests.rs
Normal file
41
tests/snapshot_tests.rs
Normal file
@ -0,0 +1,41 @@
|
||||
mod tester;
|
||||
|
||||
use tester::BatTester;
|
||||
|
||||
macro_rules! snapshot_tests {
|
||||
($($test_name: ident: $style: expr => [wrap: $wrap:expr, tabs: $tabs:expr],)*) => {
|
||||
$(
|
||||
#[test]
|
||||
fn $test_name() {
|
||||
let bat_tester = BatTester::new();
|
||||
bat_tester.test_snapshot(stringify!($test_name), $style, $tabs, $wrap);
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
snapshot_tests! {
|
||||
changes: "changes" => [wrap: false, tabs: 8],
|
||||
grid: "grid" => [wrap: false, tabs: 8],
|
||||
header: "header" => [wrap: false, tabs: 8],
|
||||
numbers: "numbers" => [wrap: false, tabs: 8],
|
||||
changes_grid: "changes,grid" => [wrap: false, tabs: 8],
|
||||
changes_header: "changes,header" => [wrap: false, tabs: 8],
|
||||
changes_numbers: "changes,numbers" => [wrap: false, tabs: 8],
|
||||
grid_header: "grid,header" => [wrap: false, tabs: 8],
|
||||
grid_numbers: "grid,numbers" => [wrap: false, tabs: 8],
|
||||
header_numbers: "header,numbers" => [wrap: false, tabs: 8],
|
||||
changes_grid_header: "changes,grid,header" => [wrap: false, tabs: 8],
|
||||
changes_grid_numbers: "changes,grid,numbers" => [wrap: false, tabs: 8],
|
||||
changes_header_numbers: "changes,header,numbers" => [wrap: false, tabs: 8],
|
||||
grid_header_numbers: "grid,header,numbers" => [wrap: false, tabs: 8],
|
||||
changes_grid_header_numbers: "changes,grid,header,numbers" => [wrap: false, tabs: 8],
|
||||
full: "full" => [wrap: false, tabs: 8],
|
||||
plain: "plain" => [wrap: false, tabs: 0],
|
||||
tabs_passthrough_wrapped: "full" => [wrap: true, tabs: 0],
|
||||
tabs_4_wrapped: "full" => [wrap: true, tabs: 4],
|
||||
tabs_8_wrapped: "full" => [wrap: true, tabs: 8],
|
||||
tabs_passthrough: "full" => [wrap: false, tabs: 0],
|
||||
tabs_4: "full" => [wrap: false, tabs: 4],
|
||||
tabs_8: "full" => [wrap: false, tabs: 8],
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
mod tester;
|
||||
|
||||
mod snapshot {
|
||||
use tester::BatTester;
|
||||
|
||||
macro_rules! snapshot_tests {
|
||||
($($test_name: ident: $style: expr => [wrap: $wrap:expr, tabs: $tabs:expr],)*) => {
|
||||
$(
|
||||
#[test]
|
||||
fn $test_name() {
|
||||
let bat_tester = BatTester::new();
|
||||
bat_tester.test_snapshot(stringify!($test_name), $style, $tabs, $wrap);
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
snapshot_tests! {
|
||||
changes: "changes" => [wrap: false, tabs: 8],
|
||||
grid: "grid" => [wrap: false, tabs: 8],
|
||||
header: "header" => [wrap: false, tabs: 8],
|
||||
numbers: "numbers" => [wrap: false, tabs: 8],
|
||||
changes_grid: "changes,grid" => [wrap: false, tabs: 8],
|
||||
changes_header: "changes,header" => [wrap: false, tabs: 8],
|
||||
changes_numbers: "changes,numbers" => [wrap: false, tabs: 8],
|
||||
grid_header: "grid,header" => [wrap: false, tabs: 8],
|
||||
grid_numbers: "grid,numbers" => [wrap: false, tabs: 8],
|
||||
header_numbers: "header,numbers" => [wrap: false, tabs: 8],
|
||||
changes_grid_header: "changes,grid,header" => [wrap: false, tabs: 8],
|
||||
changes_grid_numbers: "changes,grid,numbers" => [wrap: false, tabs: 8],
|
||||
changes_header_numbers: "changes,header,numbers" => [wrap: false, tabs: 8],
|
||||
grid_header_numbers: "grid,header,numbers" => [wrap: false, tabs: 8],
|
||||
changes_grid_header_numbers: "changes,grid,header,numbers" => [wrap: false, tabs: 8],
|
||||
full: "full" => [wrap: false, tabs: 8],
|
||||
plain: "plain" => [wrap: false, tabs: 0],
|
||||
tabs_passthrough_wrapped: "full" => [wrap: true, tabs: 0],
|
||||
tabs_4_wrapped: "full" => [wrap: true, tabs: 4],
|
||||
tabs_8_wrapped: "full" => [wrap: true, tabs: 8],
|
||||
tabs_passthrough: "full" => [wrap: false, tabs: 0],
|
||||
tabs_4: "full" => [wrap: false, tabs: 4],
|
||||
tabs_8: "full" => [wrap: false, tabs: 8],
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user