2018-10-10 20:56:56 +00:00
|
|
|
extern crate assert_cmd;
|
2018-11-02 17:33:06 +00:00
|
|
|
extern crate escargot;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2018-10-10 20:56:56 +00:00
|
|
|
|
|
|
|
use assert_cmd::prelude::*;
|
2018-11-02 17:33:06 +00:00
|
|
|
use escargot::CargoRun;
|
2018-10-10 20:56:56 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
2018-11-02 17:33:06 +00:00
|
|
|
lazy_static! {
|
|
|
|
static ref CARGO_RUN: CargoRun = escargot::CargoBuild::new()
|
|
|
|
.bin("bat")
|
|
|
|
.current_release()
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2018-11-04 09:46:56 +00:00
|
|
|
fn bat_with_config() -> Command {
|
2018-11-02 17:33:06 +00:00
|
|
|
let mut cmd = CARGO_RUN.command();
|
2018-10-10 20:56:56 +00:00
|
|
|
cmd.current_dir("tests/examples");
|
2018-10-17 18:44:15 +00:00
|
|
|
cmd.env_remove("PAGER");
|
|
|
|
cmd.env_remove("BAT_PAGER");
|
2018-11-04 09:46:56 +00:00
|
|
|
cmd.env_remove("BAT_CONFIG_PATH");
|
2018-11-04 09:50:28 +00:00
|
|
|
cmd.env_remove("BAT_STYLE");
|
|
|
|
cmd.env_remove("BAT_THEME");
|
|
|
|
cmd.env_remove("BAT_TABS");
|
2018-11-04 09:46:56 +00:00
|
|
|
cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bat() -> Command {
|
|
|
|
let mut cmd = bat_with_config();
|
|
|
|
cmd.arg("--no-config");
|
2018-10-10 20:56:56 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2019-02-08 03:27:48 +00:00
|
|
|
#[test]
|
|
|
|
fn concatenate_empty_first() {
|
|
|
|
bat()
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("hello world\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn concatenate_empty_last() {
|
|
|
|
bat()
|
|
|
|
.arg("test.txt")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("hello world\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn concatenate_empty_both() {
|
|
|
|
bat()
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn concatenate_empty_between() {
|
|
|
|
bat()
|
|
|
|
.arg("test.txt")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("hello world\nhello world\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn concatenate_empty_first_and_last() {
|
|
|
|
bat()
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("test.txt")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("hello world\n");
|
|
|
|
}
|
|
|
|
|
2019-02-10 07:52:38 +00:00
|
|
|
#[test]
|
|
|
|
fn concatenate_single_line() {
|
|
|
|
bat()
|
|
|
|
.arg("single-line.txt")
|
|
|
|
.arg("single-line.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("Single LineSingle Line");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn concatenate_single_line_empty() {
|
|
|
|
bat()
|
|
|
|
.arg("single-line.txt")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("single-line.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("Single LineSingle Line");
|
|
|
|
}
|
|
|
|
|
2018-10-10 20:56:56 +00:00
|
|
|
#[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");
|
|
|
|
}
|
|
|
|
|
2018-10-19 22:10:10 +00:00
|
|
|
#[test]
|
|
|
|
fn line_range_multiple() {
|
|
|
|
bat()
|
|
|
|
.arg("multiline.txt")
|
|
|
|
.arg("--line-range=1:2")
|
|
|
|
.arg("--line-range=4:4")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("line 1\nline 2\nline 4\n");
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:27:04 +00:00
|
|
|
#[test]
|
|
|
|
fn tabs_numbers() {
|
|
|
|
bat()
|
|
|
|
.arg("tabs.txt")
|
|
|
|
.arg("--tabs=4")
|
|
|
|
.arg("--style=numbers")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-10-19 00:55:50 +00:00
|
|
|
.stdout(
|
|
|
|
" 1 1 2 3 4
|
2018-10-18 12:35:10 +00:00
|
|
|
2 1 ?
|
|
|
|
3 22 ?
|
|
|
|
4 333 ?
|
|
|
|
5 4444 ?
|
|
|
|
6 55555 ?
|
|
|
|
7 666666 ?
|
|
|
|
8 7777777 ?
|
|
|
|
9 88888888 ?
|
2018-10-19 00:55:50 +00:00
|
|
|
",
|
|
|
|
);
|
2018-10-18 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
2018-10-14 14:22:59 +00:00
|
|
|
#[test]
|
|
|
|
fn tabs_passthrough_wrapped() {
|
2018-10-15 15:22:23 +00:00
|
|
|
bat()
|
|
|
|
.arg("tabs.txt")
|
|
|
|
.arg("--tabs=0")
|
|
|
|
.arg("--style=plain")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-10-19 00:55:50 +00:00
|
|
|
.stdout(
|
|
|
|
" 1 2 3 4
|
2018-10-15 15:22:23 +00:00
|
|
|
1 ?
|
|
|
|
22 ?
|
|
|
|
333 ?
|
|
|
|
4444 ?
|
|
|
|
55555 ?
|
|
|
|
666666 ?
|
|
|
|
7777777 ?
|
|
|
|
88888888 ?
|
2018-10-19 00:55:50 +00:00
|
|
|
",
|
|
|
|
);
|
2018-10-14 14:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn tabs_4_wrapped() {
|
2018-10-15 15:22:23 +00:00
|
|
|
bat()
|
|
|
|
.arg("tabs.txt")
|
|
|
|
.arg("--tabs=4")
|
|
|
|
.arg("--style=plain")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-10-19 00:55:50 +00:00
|
|
|
.stdout(
|
|
|
|
" 1 2 3 4
|
2018-10-15 15:22:23 +00:00
|
|
|
1 ?
|
|
|
|
22 ?
|
|
|
|
333 ?
|
|
|
|
4444 ?
|
|
|
|
55555 ?
|
|
|
|
666666 ?
|
|
|
|
7777777 ?
|
|
|
|
88888888 ?
|
2018-10-19 00:55:50 +00:00
|
|
|
",
|
|
|
|
);
|
2018-10-14 14:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn tabs_8_wrapped() {
|
2018-10-15 15:22:23 +00:00
|
|
|
bat()
|
|
|
|
.arg("tabs.txt")
|
|
|
|
.arg("--tabs=8")
|
|
|
|
.arg("--style=plain")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-10-19 00:55:50 +00:00
|
|
|
.stdout(
|
|
|
|
" 1 2 3 4
|
2018-10-15 15:22:23 +00:00
|
|
|
1 ?
|
|
|
|
22 ?
|
|
|
|
333 ?
|
|
|
|
4444 ?
|
|
|
|
55555 ?
|
|
|
|
666666 ?
|
|
|
|
7777777 ?
|
|
|
|
88888888 ?
|
2018-10-19 00:55:50 +00:00
|
|
|
",
|
|
|
|
);
|
2018-10-14 14:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn tabs_passthrough() {
|
2018-10-15 15:22:23 +00:00
|
|
|
bat()
|
|
|
|
.arg("tabs.txt")
|
|
|
|
.arg("--tabs=0")
|
|
|
|
.arg("--style=plain")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-10-19 00:55:50 +00:00
|
|
|
.stdout(
|
|
|
|
" 1 2 3 4
|
2018-10-15 15:22:23 +00:00
|
|
|
1 ?
|
|
|
|
22 ?
|
|
|
|
333 ?
|
|
|
|
4444 ?
|
|
|
|
55555 ?
|
|
|
|
666666 ?
|
|
|
|
7777777 ?
|
|
|
|
88888888 ?
|
2018-10-19 00:55:50 +00:00
|
|
|
",
|
|
|
|
);
|
2018-10-14 14:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn tabs_4() {
|
2018-10-15 15:22:23 +00:00
|
|
|
bat()
|
|
|
|
.arg("tabs.txt")
|
|
|
|
.arg("--tabs=4")
|
|
|
|
.arg("--style=plain")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-10-19 00:55:50 +00:00
|
|
|
.stdout(
|
|
|
|
" 1 2 3 4
|
2018-10-15 15:22:23 +00:00
|
|
|
1 ?
|
|
|
|
22 ?
|
|
|
|
333 ?
|
|
|
|
4444 ?
|
|
|
|
55555 ?
|
|
|
|
666666 ?
|
|
|
|
7777777 ?
|
|
|
|
88888888 ?
|
2018-10-19 00:55:50 +00:00
|
|
|
",
|
|
|
|
);
|
2018-10-14 14:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn tabs_8() {
|
2018-10-15 15:22:23 +00:00
|
|
|
bat()
|
|
|
|
.arg("tabs.txt")
|
|
|
|
.arg("--tabs=8")
|
|
|
|
.arg("--style=plain")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-10-19 00:55:50 +00:00
|
|
|
.stdout(
|
|
|
|
" 1 2 3 4
|
2018-10-15 15:22:23 +00:00
|
|
|
1 ?
|
|
|
|
22 ?
|
|
|
|
333 ?
|
|
|
|
4444 ?
|
|
|
|
55555 ?
|
|
|
|
666666 ?
|
|
|
|
7777777 ?
|
|
|
|
88888888 ?
|
2018-10-19 00:55:50 +00:00
|
|
|
",
|
|
|
|
);
|
2018-10-14 14:22:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 20:56:56 +00:00
|
|
|
#[test]
|
|
|
|
fn fail_non_existing() {
|
|
|
|
bat().arg("non-existing-file").assert().failure();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fail_directory() {
|
|
|
|
bat().arg("sub_directory").assert().failure();
|
|
|
|
}
|
2018-10-11 19:54:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_not_exit_directory() {
|
|
|
|
bat()
|
|
|
|
.arg("sub_directory")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.stdout("hello world\n")
|
|
|
|
.failure();
|
|
|
|
}
|
2018-10-17 18:44:15 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pager_basic() {
|
|
|
|
bat()
|
|
|
|
.env("PAGER", "echo pager-output")
|
|
|
|
.arg("--paging=always")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("pager-output\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pager_overwrite() {
|
|
|
|
bat()
|
|
|
|
.env("PAGER", "echo other-pager")
|
|
|
|
.env("BAT_PAGER", "echo pager-output")
|
|
|
|
.arg("--paging=always")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("pager-output\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pager_disable() {
|
|
|
|
bat()
|
|
|
|
.env("PAGER", "echo other-pager")
|
|
|
|
.env("BAT_PAGER", "")
|
|
|
|
.arg("--paging=always")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("hello world\n");
|
|
|
|
}
|
2018-11-01 15:48:56 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_location_test() {
|
2018-11-04 09:46:56 +00:00
|
|
|
bat_with_config()
|
2018-11-01 15:48:56 +00:00
|
|
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
|
|
|
.arg("--config-file")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("bat.conf\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-11-04 09:56:31 +00:00
|
|
|
fn config_read_arguments_from_file() {
|
2018-11-04 09:46:56 +00:00
|
|
|
bat_with_config()
|
2018-11-01 15:48:56 +00:00
|
|
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
2018-11-04 09:56:31 +00:00
|
|
|
.stdout("dummy-pager-from-config\n");
|
2018-11-01 15:48:56 +00:00
|
|
|
}
|
2019-02-10 08:19:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn utf16() {
|
|
|
|
// The output will be converted to UTF-8 with a leading UTF-8 BOM
|
|
|
|
bat()
|
|
|
|
.arg("--plain")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.arg("test_UTF-16LE.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());
|
|
|
|
}
|
2019-05-10 19:02:08 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_print_file_named_cache() {
|
2019-08-31 12:13:19 +00:00
|
|
|
bat_with_config()
|
2019-05-10 19:02:08 +00:00
|
|
|
.arg("cache")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("test\n")
|
|
|
|
.stderr("");
|
|
|
|
}
|
|
|
|
|
2019-09-21 07:10:12 +00:00
|
|
|
#[test]
|
|
|
|
fn can_print_file_named_cache_with_additional_argument() {
|
|
|
|
bat_with_config()
|
|
|
|
.arg("cache")
|
|
|
|
.arg("test.txt")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("test\nhello world\n")
|
|
|
|
.stderr("");
|
|
|
|
}
|
|
|
|
|
2019-08-31 12:13:19 +00:00
|
|
|
#[test]
|
|
|
|
fn can_print_file_starting_with_cache() {
|
|
|
|
bat_with_config()
|
|
|
|
.arg("cache.c")
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("test\n")
|
|
|
|
.stderr("");
|
|
|
|
}
|
|
|
|
|
2019-05-10 19:02:08 +00:00
|
|
|
#[test]
|
|
|
|
fn does_not_print_unwanted_file_named_cache() {
|
|
|
|
bat_with_config().arg("cach").assert().failure();
|
|
|
|
}
|
2019-08-31 10:46:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn snip() {
|
|
|
|
bat()
|
|
|
|
.arg("multiline.txt")
|
|
|
|
.arg("--style=numbers,snip")
|
|
|
|
.arg("--decorations=always")
|
|
|
|
.arg("--line-range=1:2")
|
|
|
|
.arg("--line-range=4:")
|
2019-08-31 11:01:36 +00:00
|
|
|
.arg("--terminal-width=80")
|
2019-08-31 10:46:03 +00:00
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout(
|
|
|
|
" 1 line 1
|
|
|
|
2 line 2
|
|
|
|
...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
|
|
|
|
4 line 4
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}
|