2020-11-08 22:24:14 +01:00
|
|
|
|
use assert_cmd::assert::OutputAssertExt;
|
|
|
|
|
use assert_cmd::cargo::CommandCargoExt;
|
2020-09-20 20:47:21 +02:00
|
|
|
|
use predicates::{prelude::predicate, str::PredicateStrExt};
|
2020-11-08 22:24:14 +01:00
|
|
|
|
use std::fs::File;
|
2020-05-13 11:51:49 +02:00
|
|
|
|
use std::path::Path;
|
2020-11-08 22:24:14 +01:00
|
|
|
|
use std::process::{Command, Stdio};
|
2020-05-13 11:51:49 +02:00
|
|
|
|
use std::str::from_utf8;
|
|
|
|
|
|
|
|
|
|
const EXAMPLES_DIR: &str = "tests/examples";
|
2018-11-02 18:33:06 +01:00
|
|
|
|
|
2020-11-08 22:24:14 +01:00
|
|
|
|
fn bat_as_std() -> Command {
|
2020-03-07 00:01:35 +01:00
|
|
|
|
let mut cmd = Command::cargo_bin("bat").unwrap();
|
2018-10-10 22:56:56 +02:00
|
|
|
|
cmd.current_dir("tests/examples");
|
2018-10-17 20:44:15 +02:00
|
|
|
|
cmd.env_remove("PAGER");
|
|
|
|
|
cmd.env_remove("BAT_PAGER");
|
2018-11-04 10:46:56 +01:00
|
|
|
|
cmd.env_remove("BAT_CONFIG_PATH");
|
2018-11-04 10:50:28 +01:00
|
|
|
|
cmd.env_remove("BAT_STYLE");
|
|
|
|
|
cmd.env_remove("BAT_THEME");
|
|
|
|
|
cmd.env_remove("BAT_TABS");
|
2018-11-04 10:46:56 +01:00
|
|
|
|
cmd
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 22:24:14 +01:00
|
|
|
|
fn bat_with_config() -> assert_cmd::Command {
|
|
|
|
|
assert_cmd::Command::from_std(bat_as_std())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn bat() -> assert_cmd::Command {
|
2018-11-04 10:46:56 +01:00
|
|
|
|
let mut cmd = bat_with_config();
|
|
|
|
|
cmd.arg("--no-config");
|
2018-10-10 22:56:56 +02:00
|
|
|
|
cmd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn basic() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn stdin() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-03-07 00:01:35 +01:00
|
|
|
|
.write_stdin("foo\nbar\n")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("foo\nbar\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\nhello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_stdin() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("-")
|
|
|
|
|
.arg("test.txt")
|
2020-03-07 00:01:35 +01:00
|
|
|
|
.write_stdin("stdin\n")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\nstdin\nhello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 04:27:48 +01:00
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_first() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_last() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("empty.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_both() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("empty.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_between() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\nhello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_first_and_last() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("empty.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-08 04:27:48 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 08:52:38 +01:00
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_single_line() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-10 08:52:38 +01:00
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.arg("single-line.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-10 08:52:38 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single LineSingle Line");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_single_line_empty() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-10 08:52:38 +01:00
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("single-line.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-10 08:52:38 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single LineSingle Line");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 22:56:56 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn line_numbers() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--style=numbers")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn line_range_2_3() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=2:3")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 2\nline 3\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn line_range_first_two() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=:2")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 1\nline 2\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn line_range_last_3() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=2:")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-10 22:56:56 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 2\nline 3\nline 4\n");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-20 00:10:10 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn line_range_multiple() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-20 00:10:10 +02:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=1:2")
|
|
|
|
|
.arg("--line-range=4:4")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-20 00:10:10 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 1\nline 2\nline 4\n");
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 22:24:14 +01:00
|
|
|
|
#[test]
|
|
|
|
|
fn basic_io_cycle() {
|
|
|
|
|
let file_out = Stdio::from(File::open("tests/examples/cycle.txt").unwrap());
|
|
|
|
|
bat_as_std()
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("cycle.txt")
|
|
|
|
|
.stdout(file_out)
|
|
|
|
|
.assert()
|
|
|
|
|
.failure();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn stdin_to_stdout_cycle() {
|
|
|
|
|
let file_out = Stdio::from(File::open("tests/examples/cycle.txt").unwrap());
|
|
|
|
|
let file_in = Stdio::from(File::open("tests/examples/cycle.txt").unwrap());
|
|
|
|
|
bat_as_std()
|
|
|
|
|
.stdin(file_in)
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("-")
|
|
|
|
|
.stdout(file_out)
|
|
|
|
|
.assert()
|
|
|
|
|
.failure();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 14:27:04 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_numbers() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-18 14:27:04 +02:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=4")
|
|
|
|
|
.arg("--style=numbers")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-18 14:27:04 +02:00
|
|
|
|
.success()
|
2018-10-19 02:55:50 +02:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 1 2 3 4
|
2018-10-18 14:35:10 +02:00
|
|
|
|
2 1 ?
|
|
|
|
|
3 22 ?
|
|
|
|
|
4 333 ?
|
|
|
|
|
5 4444 ?
|
|
|
|
|
6 55555 ?
|
|
|
|
|
7 666666 ?
|
|
|
|
|
8 7777777 ?
|
|
|
|
|
9 88888888 ?
|
2018-10-19 02:55:50 +02:00
|
|
|
|
",
|
|
|
|
|
);
|
2018-10-18 14:27:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-14 16:22:59 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_passthrough_wrapped() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=0")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.success()
|
2018-10-19 02:55:50 +02:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 2 3 4
|
2018-10-15 17:22:23 +02:00
|
|
|
|
1 ?
|
|
|
|
|
22 ?
|
|
|
|
|
333 ?
|
|
|
|
|
4444 ?
|
|
|
|
|
55555 ?
|
|
|
|
|
666666 ?
|
|
|
|
|
7777777 ?
|
|
|
|
|
88888888 ?
|
2018-10-19 02:55:50 +02:00
|
|
|
|
",
|
|
|
|
|
);
|
2018-10-14 16:22:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_4_wrapped() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=4")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.success()
|
2018-10-19 02:55:50 +02:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 2 3 4
|
2018-10-15 17:22:23 +02:00
|
|
|
|
1 ?
|
|
|
|
|
22 ?
|
|
|
|
|
333 ?
|
|
|
|
|
4444 ?
|
|
|
|
|
55555 ?
|
|
|
|
|
666666 ?
|
|
|
|
|
7777777 ?
|
|
|
|
|
88888888 ?
|
2018-10-19 02:55:50 +02:00
|
|
|
|
",
|
|
|
|
|
);
|
2018-10-14 16:22:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_8_wrapped() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=8")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.success()
|
2018-10-19 02:55:50 +02:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 2 3 4
|
2018-10-15 17:22:23 +02:00
|
|
|
|
1 ?
|
|
|
|
|
22 ?
|
|
|
|
|
333 ?
|
|
|
|
|
4444 ?
|
|
|
|
|
55555 ?
|
|
|
|
|
666666 ?
|
|
|
|
|
7777777 ?
|
|
|
|
|
88888888 ?
|
2018-10-19 02:55:50 +02:00
|
|
|
|
",
|
|
|
|
|
);
|
2018-10-14 16:22:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_passthrough() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=0")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.success()
|
2018-10-19 02:55:50 +02:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 2 3 4
|
2018-10-15 17:22:23 +02:00
|
|
|
|
1 ?
|
|
|
|
|
22 ?
|
|
|
|
|
333 ?
|
|
|
|
|
4444 ?
|
|
|
|
|
55555 ?
|
|
|
|
|
666666 ?
|
|
|
|
|
7777777 ?
|
|
|
|
|
88888888 ?
|
2018-10-19 02:55:50 +02:00
|
|
|
|
",
|
|
|
|
|
);
|
2018-10-14 16:22:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_4() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=4")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.success()
|
2018-10-19 02:55:50 +02:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 2 3 4
|
2018-10-15 17:22:23 +02:00
|
|
|
|
1 ?
|
|
|
|
|
22 ?
|
|
|
|
|
333 ?
|
|
|
|
|
4444 ?
|
|
|
|
|
55555 ?
|
|
|
|
|
666666 ?
|
|
|
|
|
7777777 ?
|
|
|
|
|
88888888 ?
|
2018-10-19 02:55:50 +02:00
|
|
|
|
",
|
|
|
|
|
);
|
2018-10-14 16:22:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_8() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=8")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-15 17:22:23 +02:00
|
|
|
|
.success()
|
2018-10-19 02:55:50 +02:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 2 3 4
|
2018-10-15 17:22:23 +02:00
|
|
|
|
1 ?
|
|
|
|
|
22 ?
|
|
|
|
|
333 ?
|
|
|
|
|
4444 ?
|
|
|
|
|
55555 ?
|
|
|
|
|
666666 ?
|
|
|
|
|
7777777 ?
|
|
|
|
|
88888888 ?
|
2018-10-19 02:55:50 +02:00
|
|
|
|
",
|
|
|
|
|
);
|
2018-10-14 16:22:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 22:56:56 +02: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 21:54:19 +02:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn do_not_exit_directory() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2018-10-11 21:54:19 +02:00
|
|
|
|
.arg("sub_directory")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-11 21:54:19 +02:00
|
|
|
|
.stdout("hello world\n")
|
|
|
|
|
.failure();
|
|
|
|
|
}
|
2018-10-17 20:44:15 +02:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pager_basic() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-05-28 05:30:51 +02:00
|
|
|
|
.env("PAGER", "echo pager-output")
|
2018-10-17 20:44:15 +02:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-17 20:44:15 +02:00
|
|
|
|
.success()
|
2020-05-28 16:43:51 +02:00
|
|
|
|
.stdout(predicate::eq("pager-output\n").normalize());
|
2018-10-17 20:44:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pager_overwrite() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-05-28 05:30:51 +02:00
|
|
|
|
.env("PAGER", "echo other-pager")
|
|
|
|
|
.env("BAT_PAGER", "echo pager-output")
|
2018-10-17 20:44:15 +02:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-17 20:44:15 +02:00
|
|
|
|
.success()
|
2020-05-28 16:43:51 +02:00
|
|
|
|
.stdout(predicate::eq("pager-output\n").normalize());
|
2018-10-17 20:44:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pager_disable() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-05-28 05:30:51 +02:00
|
|
|
|
.env("PAGER", "echo other-pager")
|
2018-10-17 20:44:15 +02:00
|
|
|
|
.env("BAT_PAGER", "")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-10-17 20:44:15 +02:00
|
|
|
|
.success()
|
2020-05-28 16:43:51 +02:00
|
|
|
|
.stdout(predicate::eq("hello world\n").normalize());
|
2018-10-17 20:44:15 +02:00
|
|
|
|
}
|
2018-11-01 16:48:56 +01:00
|
|
|
|
|
2020-10-25 10:13:57 +01:00
|
|
|
|
#[test]
|
|
|
|
|
fn pager_value_bat() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--pager=bat")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.failure();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 21:41:50 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn alias_pager_disable() {
|
|
|
|
|
bat()
|
|
|
|
|
.env("PAGER", "echo other-pager")
|
|
|
|
|
.arg("-P")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(predicate::eq("hello world\n").normalize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn alias_pager_disable_long_overrides_short() {
|
|
|
|
|
bat()
|
|
|
|
|
.env("PAGER", "echo pager-output")
|
|
|
|
|
.arg("-P")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(predicate::eq("pager-output\n").normalize());
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 16:48:56 +01:00
|
|
|
|
#[test]
|
|
|
|
|
fn config_location_test() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat_with_config()
|
2018-11-01 16:48:56 +01:00
|
|
|
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
|
|
|
|
.arg("--config-file")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-11-01 16:48:56 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("bat.conf\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-11-04 10:56:31 +01:00
|
|
|
|
fn config_read_arguments_from_file() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat_with_config()
|
2018-11-01 16:48:56 +01:00
|
|
|
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2018-11-01 16:48:56 +01:00
|
|
|
|
.success()
|
2020-05-28 16:43:51 +02:00
|
|
|
|
.stdout(predicate::eq("dummy-pager-from-config\n").normalize());
|
2018-11-01 16:48:56 +01:00
|
|
|
|
}
|
2019-02-10 09:19:38 +01:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn utf16() {
|
|
|
|
|
// The output will be converted to UTF-8 with a leading UTF-8 BOM
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-02-10 09:19:38 +01:00
|
|
|
|
.arg("--plain")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("test_UTF-16LE.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-02-10 09:19:38 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());
|
|
|
|
|
}
|
2019-05-10 21:02:08 +02:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn can_print_file_named_cache() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat_with_config()
|
2019-05-10 21:02:08 +02:00
|
|
|
|
.arg("cache")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-05-10 21:02:08 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("test\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-21 09:10:12 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn can_print_file_named_cache_with_additional_argument() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat_with_config()
|
2019-09-21 09:10:12 +02:00
|
|
|
|
.arg("cache")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-09-21 09:10:12 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("test\nhello world\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-31 14:13:19 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn can_print_file_starting_with_cache() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat_with_config()
|
2019-08-31 14:13:19 +02:00
|
|
|
|
.arg("cache.c")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-08-31 14:13:19 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("test\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 21:02:08 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn does_not_print_unwanted_file_named_cache() {
|
|
|
|
|
bat_with_config().arg("cach").assert().failure();
|
|
|
|
|
}
|
2019-08-31 12:46:03 +02:00
|
|
|
|
|
2020-02-01 10:49:29 +01:00
|
|
|
|
#[test]
|
|
|
|
|
fn unicode_wrap() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat_with_config()
|
2020-02-01 10:49:29 +01:00
|
|
|
|
.arg("unicode-wrap.txt")
|
|
|
|
|
.arg("--style=numbers,snip")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--terminal-width=40")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-02-01 10:49:29 +01:00
|
|
|
|
.success()
|
2020-02-28 10:27:06 +01:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 ビタミンA ビタミンD ビタミンE ビ
|
2020-02-28 03:42:44 +01:00
|
|
|
|
タミンK ビタミンB1 ビタミンB2 ナ
|
|
|
|
|
イアシン パントテン酸 ビタミンB6
|
|
|
|
|
ビタミンB12 葉酸 ビオチン ビタ
|
|
|
|
|
ミンC
|
2020-02-01 10:49:29 +01:00
|
|
|
|
2
|
2020-02-28 03:42:44 +01:00
|
|
|
|
3 고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이
|
2020-02-01 10:49:29 +01:00
|
|
|
|
4
|
2020-02-28 03:42:44 +01:00
|
|
|
|
5 1 บวก 2 บวก 3 บวก 4 บวก 5 บวก 6 บวก
|
|
|
|
|
7 บวก 8 บวก 9 บวก 10 บวก 11 บวก 12
|
|
|
|
|
บวก 13 บวก 14 บวก 15 บวก 16 บวก 17
|
|
|
|
|
บวก 18 บวก 19 บวก 20
|
2020-02-01 10:49:29 +01:00
|
|
|
|
6
|
2020-02-28 03:42:44 +01:00
|
|
|
|
7 Бельгия Болгария Чехия Дания Герман
|
|
|
|
|
ия Эстония Ирландия Греция Испания
|
|
|
|
|
Франция Хорватия Италия Кипр Латвия
|
|
|
|
|
Литва Люксембург Венгрия Мальта Ни
|
|
|
|
|
дерланды Австрия Польша Португалия
|
|
|
|
|
Румыния Словения Словакия Финляндия
|
|
|
|
|
Швеция Великобритания
|
2020-02-28 10:27:06 +01:00
|
|
|
|
",
|
|
|
|
|
);
|
2020-02-01 10:49:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-31 12:46:03 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn snip() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2019-08-31 12:46:03 +02:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--style=numbers,snip")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--line-range=1:2")
|
|
|
|
|
.arg("--line-range=4:")
|
2019-08-31 13:01:36 +02:00
|
|
|
|
.arg("--terminal-width=80")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2019-08-31 12:46:03 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout(
|
|
|
|
|
" 1 line 1
|
|
|
|
|
2 line 2
|
|
|
|
|
...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
|
|
|
|
|
4 line 4
|
|
|
|
|
",
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-02-28 00:09:01 +01:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn empty_file_leads_to_empty_output_with_grid_enabled() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-02-28 00:09:01 +01:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("--style=grid")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--terminal-width=80")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-02-28 00:09:01 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("");
|
|
|
|
|
}
|
2020-03-20 03:46:19 +01:00
|
|
|
|
|
2020-10-06 17:57:47 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn empty_file_leads_to_empty_output_with_rule_enabled() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("--style=rule")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--terminal-width=80")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("");
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-20 03:46:19 +01:00
|
|
|
|
#[test]
|
|
|
|
|
fn filename_basic() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_binary() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.arg("test.binary")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo <BINARY>\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_stdin() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("-")
|
|
|
|
|
.write_stdin("stdin\n")
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_stdin_binary() {
|
|
|
|
|
let vec = vec![0; 1];
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat_with_config()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.write_stdin(vec)
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-03-20 03:46:19 +01:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo <BINARY>\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
2020-03-25 01:26:00 +01:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_multiple_ok() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-03-25 01:26:00 +01:00
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("--file-name=foo")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.arg("--file-name=bar")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-03-25 01:26:00 +01:00
|
|
|
|
.success()
|
2020-05-12 02:57:51 +02:00
|
|
|
|
.stdout("File: foo\n\nFile: bar\n")
|
2020-03-25 01:26:00 +01:00
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_multiple_err() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("--file-name=foo")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.failure();
|
|
|
|
|
}
|
2020-04-21 09:59:17 +02:00
|
|
|
|
|
2020-05-12 02:57:51 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn header_padding() {
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-05-12 02:57:51 +02:00
|
|
|
|
.arg("--decorations=always")
|
2020-05-12 16:06:58 +02:00
|
|
|
|
.arg("--style=header")
|
2020-05-12 02:57:51 +02:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("single-line.txt")
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-05-12 16:06:58 +02:00
|
|
|
|
.stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n")
|
2020-05-12 02:57:51 +02:00
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 10:59:14 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn header_padding_rule() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header,rule")
|
|
|
|
|
.arg("--terminal-width=80")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.stdout(
|
|
|
|
|
"File: test.txt
|
|
|
|
|
hello world
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
File: single-line.txt
|
|
|
|
|
Single Line
|
|
|
|
|
",
|
|
|
|
|
)
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 10:02:08 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn grid_overrides_rule() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=grid,rule")
|
|
|
|
|
.arg("--terminal-width=80")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.stdout(
|
|
|
|
|
"\
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
hello world
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
Single Line
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
",
|
|
|
|
|
)
|
|
|
|
|
.stderr("\x1b[33m[bat warning]\x1b[0m: Style 'rule' is a subset of style 'grid', 'rule' will not be visible.\n");
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 14:09:05 +02:00
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
#[test]
|
|
|
|
|
fn file_with_invalid_utf8_filename() {
|
|
|
|
|
use std::ffi::OsStr;
|
2020-04-21 16:02:28 +02:00
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::io::Write;
|
2020-04-21 14:09:05 +02:00
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
|
|
2020-04-21 16:02:28 +02:00
|
|
|
|
use tempdir::TempDir;
|
|
|
|
|
|
|
|
|
|
let tmp_dir = TempDir::new("bat_test").expect("can create temporary directory");
|
|
|
|
|
let file_path = tmp_dir
|
|
|
|
|
.path()
|
|
|
|
|
.join(OsStr::from_bytes(b"test-invalid-utf8-\xC3(.rs"));
|
|
|
|
|
{
|
|
|
|
|
let mut file = File::create(&file_path).expect("can create temporary file");
|
|
|
|
|
writeln!(file, "dummy content").expect("can write to file");
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-01 23:50:24 +02:00
|
|
|
|
bat()
|
2020-04-21 16:02:28 +02:00
|
|
|
|
.arg(file_path.as_os_str())
|
2020-06-01 23:50:24 +02:00
|
|
|
|
.assert()
|
2020-04-21 16:02:28 +02:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("dummy content\n");
|
2020-04-21 14:09:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 09:59:17 +02:00
|
|
|
|
#[test]
|
|
|
|
|
fn do_not_panic_regression_tests() {
|
|
|
|
|
for filename in &[
|
|
|
|
|
"issue_28.md",
|
|
|
|
|
"issue_190.md",
|
|
|
|
|
"issue_314.hs",
|
|
|
|
|
"issue_914.rb",
|
|
|
|
|
"issue_915.vue",
|
|
|
|
|
] {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--color=always")
|
|
|
|
|
.arg(&format!("regression_tests/{}", filename))
|
|
|
|
|
.assert()
|
|
|
|
|
.success();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-13 11:51:49 +02:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn do_not_detect_different_syntax_for_stdin_and_files() {
|
|
|
|
|
let file = "regression_tests/issue_985.js";
|
|
|
|
|
|
2020-05-15 21:29:01 +02:00
|
|
|
|
let cmd_for_file = bat()
|
2020-05-13 11:51:49 +02:00
|
|
|
|
.arg("--color=always")
|
|
|
|
|
.arg("--map-syntax=*.js:Markdown")
|
|
|
|
|
.arg(&format!("--file-name={}", file))
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg(file)
|
|
|
|
|
.assert()
|
2020-05-15 21:29:01 +02:00
|
|
|
|
.success();
|
2020-05-13 11:51:49 +02:00
|
|
|
|
|
2020-05-15 21:29:01 +02:00
|
|
|
|
let cmd_for_stdin = bat()
|
2020-05-13 11:51:49 +02:00
|
|
|
|
.arg("--color=always")
|
|
|
|
|
.arg("--map-syntax=*.js:Markdown")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg(&format!("--file-name={}", file))
|
|
|
|
|
.pipe_stdin(Path::new(EXAMPLES_DIR).join(file))
|
|
|
|
|
.unwrap()
|
|
|
|
|
.assert()
|
2020-05-15 21:29:01 +02:00
|
|
|
|
.success();
|
2020-05-13 11:51:49 +02:00
|
|
|
|
|
|
|
|
|
assert_eq!(
|
2020-05-15 21:29:01 +02:00
|
|
|
|
from_utf8(&cmd_for_file.get_output().stdout).expect("output is valid utf-8"),
|
|
|
|
|
from_utf8(&cmd_for_stdin.get_output().stdout).expect("output is valid utf-8")
|
2020-05-13 11:51:49 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-20 17:00:32 +02:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn show_all_mode() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--show-all")
|
|
|
|
|
.arg("nonprintable.txt")
|
|
|
|
|
.assert()
|
2020-07-06 22:44:19 +02:00
|
|
|
|
.stdout("hello·world␊\n├──┤␍␀␇␈␛")
|
2020-06-20 17:00:32 +02:00
|
|
|
|
.stderr("");
|
|
|
|
|
}
|