2021-01-05 09:54:14 +00:00
|
|
|
|
use assert_cmd::cargo::CommandCargoExt;
|
2020-09-20 18:47:21 +00:00
|
|
|
|
use predicates::{prelude::predicate, str::PredicateStrExt};
|
2021-01-04 14:45:56 +00:00
|
|
|
|
use serial_test::serial;
|
2021-01-10 13:05:39 +00:00
|
|
|
|
use std::path::Path;
|
2021-02-27 14:33:13 +00:00
|
|
|
|
use std::process::Command;
|
2020-05-13 09:51:49 +00:00
|
|
|
|
use std::str::from_utf8;
|
2021-02-28 15:56:16 +00:00
|
|
|
|
use tempfile::tempdir;
|
2021-01-06 21:09:22 +00:00
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
2021-02-27 14:33:13 +00:00
|
|
|
|
mod unix {
|
|
|
|
|
pub use std::fs::File;
|
|
|
|
|
pub use std::io::{self, Write};
|
|
|
|
|
pub use std::os::unix::io::FromRawFd;
|
|
|
|
|
pub use std::path::PathBuf;
|
|
|
|
|
pub use std::process::Stdio;
|
|
|
|
|
pub use std::thread;
|
|
|
|
|
pub use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
pub use assert_cmd::assert::OutputAssertExt;
|
|
|
|
|
pub use nix::pty::{openpty, OpenptyResult};
|
|
|
|
|
pub use wait_timeout::ChildExt;
|
|
|
|
|
|
|
|
|
|
pub const SAFE_CHILD_PROCESS_CREATION_TIME: Duration = Duration::from_millis(100);
|
|
|
|
|
pub const CHILD_WAIT_TIMEOUT: Duration = Duration::from_secs(15);
|
|
|
|
|
}
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
use unix::*;
|
2020-05-13 09:51:49 +00:00
|
|
|
|
|
2021-01-10 13:05:39 +00:00
|
|
|
|
mod utils;
|
|
|
|
|
use utils::mocked_pagers;
|
|
|
|
|
|
2020-05-13 09:51:49 +00:00
|
|
|
|
const EXAMPLES_DIR: &str = "tests/examples";
|
2021-01-06 19:09:01 +00:00
|
|
|
|
|
2021-02-27 14:33:13 +00:00
|
|
|
|
fn bat_raw_command_with_config() -> Command {
|
2020-03-06 23:01:35 +00:00
|
|
|
|
let mut cmd = Command::cargo_bin("bat").unwrap();
|
2018-10-10 20:56:56 +00:00
|
|
|
|
cmd.current_dir("tests/examples");
|
2021-09-06 19:37:02 +00:00
|
|
|
|
cmd.env_remove("BAT_CACHE_PATH");
|
|
|
|
|
cmd.env_remove("BAT_CONFIG_DIR");
|
2018-11-04 09:46:56 +00:00
|
|
|
|
cmd.env_remove("BAT_CONFIG_PATH");
|
2021-09-06 19:37:02 +00:00
|
|
|
|
cmd.env_remove("BAT_OPTS");
|
|
|
|
|
cmd.env_remove("BAT_PAGER");
|
2018-11-04 09:50:28 +00:00
|
|
|
|
cmd.env_remove("BAT_STYLE");
|
|
|
|
|
cmd.env_remove("BAT_TABS");
|
2021-09-06 19:37:02 +00:00
|
|
|
|
cmd.env_remove("BAT_THEME");
|
|
|
|
|
cmd.env_remove("COLORTERM");
|
|
|
|
|
cmd.env_remove("NO_COLOR");
|
|
|
|
|
cmd.env_remove("PAGER");
|
2018-11-04 09:46:56 +00:00
|
|
|
|
cmd
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 14:33:13 +00:00
|
|
|
|
fn bat_raw_command() -> Command {
|
|
|
|
|
let mut cmd = bat_raw_command_with_config();
|
|
|
|
|
cmd.arg("--no-config");
|
|
|
|
|
cmd
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 09:54:14 +00:00
|
|
|
|
fn bat_with_config() -> assert_cmd::Command {
|
2021-02-27 14:33:13 +00:00
|
|
|
|
assert_cmd::Command::from_std(bat_raw_command_with_config())
|
2021-01-05 09:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn bat() -> assert_cmd::Command {
|
2021-02-27 14:33:13 +00:00
|
|
|
|
assert_cmd::Command::from_std(bat_raw_command())
|
2018-10-10 20:56:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn basic() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn stdin() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-03-06 23:01:35 +00:00
|
|
|
|
.write_stdin("foo\nbar\n")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("foo\nbar\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\nhello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_stdin() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("-")
|
|
|
|
|
.arg("test.txt")
|
2020-03-06 23:01:35 +00:00
|
|
|
|
.write_stdin("stdin\n")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\nstdin\nhello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 03:27:48 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_first() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_last() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("empty.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_both() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("empty.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_between() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\nhello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_empty_first_and_last() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("empty.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-08 03:27:48 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("hello world\n");
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 07:52:38 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_single_line() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-10 07:52:38 +00:00
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.arg("single-line.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-10 07:52:38 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single LineSingle Line");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn concatenate_single_line_empty() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-10 07:52:38 +00:00
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("single-line.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-10 07:52:38 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single LineSingle Line");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 20:56:56 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn line_numbers() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--style=numbers")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00: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 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=2:3")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 2\nline 3\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn line_range_first_two() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=:2")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 1\nline 2\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn line_range_last_3() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=2:")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-10 20:56:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 2\nline 3\nline 4\n");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 22:10:10 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn line_range_multiple() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-19 22:10:10 +00:00
|
|
|
|
.arg("multiline.txt")
|
|
|
|
|
.arg("--line-range=1:2")
|
|
|
|
|
.arg("--line-range=4:4")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-19 22:10:10 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("line 1\nline 2\nline 4\n");
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 14:33:13 +00:00
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
fn setup_temp_file(content: &[u8]) -> io::Result<(PathBuf, tempfile::TempDir)> {
|
|
|
|
|
let dir = tempfile::tempdir().expect("Couldn't create tempdir");
|
|
|
|
|
let path = dir.path().join("temp_file");
|
|
|
|
|
File::create(&path)?.write_all(content)?;
|
|
|
|
|
Ok((path, dir))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn basic_io_cycle() -> io::Result<()> {
|
|
|
|
|
let (filename, dir) = setup_temp_file(b"I am not empty")?;
|
|
|
|
|
|
|
|
|
|
let file_out = Stdio::from(File::create(&filename)?);
|
|
|
|
|
let res = bat_raw_command()
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg(&filename)
|
|
|
|
|
.stdout(file_out)
|
|
|
|
|
.assert();
|
|
|
|
|
drop(dir);
|
|
|
|
|
res.failure();
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
2021-01-05 09:54:14 +00:00
|
|
|
|
#[test]
|
2021-02-27 14:33:13 +00:00
|
|
|
|
fn first_file_cyclic_is_ok() -> io::Result<()> {
|
|
|
|
|
let (filename, dir) = setup_temp_file(b"I am not empty")?;
|
|
|
|
|
|
|
|
|
|
let file_out = Stdio::from(File::create(&filename)?);
|
|
|
|
|
let res = bat_raw_command()
|
|
|
|
|
.arg(&filename)
|
2021-01-05 09:54:14 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.stdout(file_out)
|
2021-02-27 14:33:13 +00:00
|
|
|
|
.assert();
|
|
|
|
|
drop(dir);
|
|
|
|
|
res.success();
|
|
|
|
|
Ok(())
|
2021-01-05 09:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 14:33:13 +00:00
|
|
|
|
#[cfg(unix)]
|
2021-01-05 09:54:14 +00:00
|
|
|
|
#[test]
|
2021-02-27 14:33:13 +00:00
|
|
|
|
fn empty_file_cycle_is_ok() -> io::Result<()> {
|
|
|
|
|
let (filename, dir) = setup_temp_file(b"I am not empty")?;
|
|
|
|
|
|
|
|
|
|
let file_out = Stdio::from(File::create(&filename)?);
|
|
|
|
|
let res = bat_raw_command()
|
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg(&filename)
|
|
|
|
|
.stdout(file_out)
|
|
|
|
|
.assert();
|
|
|
|
|
drop(dir);
|
|
|
|
|
res.success();
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn stdin_to_stdout_cycle() -> io::Result<()> {
|
|
|
|
|
let (filename, dir) = setup_temp_file(b"I am not empty")?;
|
|
|
|
|
let file_in = Stdio::from(File::open(&filename)?);
|
|
|
|
|
let file_out = Stdio::from(File::create(&filename)?);
|
|
|
|
|
let res = bat_raw_command()
|
2021-01-05 09:54:14 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("-")
|
2021-02-27 14:33:13 +00:00
|
|
|
|
.stdin(file_in)
|
2021-01-05 09:54:14 +00:00
|
|
|
|
.stdout(file_out)
|
2021-02-27 14:33:13 +00:00
|
|
|
|
.assert();
|
|
|
|
|
drop(dir);
|
|
|
|
|
res.failure();
|
|
|
|
|
Ok(())
|
2021-01-05 09:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 09:55:22 +00:00
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn no_args_doesnt_break() {
|
|
|
|
|
// To simulate bat getting started from the shell, a process is created with stdin and stdout
|
|
|
|
|
// as the slave end of a pseudo terminal. Although both point to the same "file", bat should
|
|
|
|
|
// not exit, because in this case it is safe to read and write to the same fd, which is why
|
|
|
|
|
// this test exists.
|
|
|
|
|
let OpenptyResult { master, slave } = openpty(None, None).expect("Couldn't open pty.");
|
|
|
|
|
let mut master = unsafe { File::from_raw_fd(master) };
|
|
|
|
|
let stdin = unsafe { Stdio::from_raw_fd(slave) };
|
|
|
|
|
let stdout = unsafe { Stdio::from_raw_fd(slave) };
|
|
|
|
|
|
|
|
|
|
let mut child = bat_raw_command()
|
|
|
|
|
.stdin(stdin)
|
|
|
|
|
.stdout(stdout)
|
|
|
|
|
.spawn()
|
|
|
|
|
.expect("Failed to start.");
|
|
|
|
|
|
|
|
|
|
// Some time for the child process to start and to make sure, that we can poll the exit status.
|
|
|
|
|
// Although this waiting period is not necessary, it is best to keep it in and be absolutely
|
|
|
|
|
// sure, that the try_wait does not error later.
|
|
|
|
|
thread::sleep(SAFE_CHILD_PROCESS_CREATION_TIME);
|
|
|
|
|
|
|
|
|
|
// The child process should be running and waiting for input,
|
|
|
|
|
// therefore no exit status should be available.
|
|
|
|
|
let exit_status = child
|
|
|
|
|
.try_wait()
|
|
|
|
|
.expect("Error polling exit status, this should never happen.");
|
|
|
|
|
assert!(exit_status.is_none());
|
|
|
|
|
|
|
|
|
|
// Write Ctrl-D (end of transmission) to the pty.
|
|
|
|
|
master
|
|
|
|
|
.write_all(&[0x04])
|
|
|
|
|
.expect("Couldn't write EOT character to master end.");
|
|
|
|
|
|
|
|
|
|
let exit_status = child
|
|
|
|
|
.wait_timeout(CHILD_WAIT_TIMEOUT)
|
|
|
|
|
.expect("Error polling exit status, this should never happen.")
|
|
|
|
|
.expect("Exit status not set, but the child should have exited already.");
|
|
|
|
|
|
|
|
|
|
assert!(exit_status.success());
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 12:27:04 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn tabs_numbers() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-18 12:27:04 +00:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=4")
|
|
|
|
|
.arg("--style=numbers")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-18 12:27:04 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=0")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=4")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=8")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=0")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=4")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.arg("tabs.txt")
|
|
|
|
|
.arg("--tabs=8")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("--decorations=always")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-15 15:22:23 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2018-10-11 19:54:19 +00:00
|
|
|
|
.arg("sub_directory")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-11 19:54:19 +00:00
|
|
|
|
.stdout("hello world\n")
|
|
|
|
|
.failure();
|
|
|
|
|
}
|
2018-10-17 18:44:15 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pager_basic() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-05-28 03:30:51 +00:00
|
|
|
|
.env("PAGER", "echo pager-output")
|
2018-10-17 18:44:15 +00:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-17 18:44:15 +00:00
|
|
|
|
.success()
|
2020-05-28 14:43:51 +00:00
|
|
|
|
.stdout(predicate::eq("pager-output\n").normalize());
|
2018-10-17 18:44:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pager_overwrite() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-05-28 03:30:51 +00:00
|
|
|
|
.env("PAGER", "echo other-pager")
|
|
|
|
|
.env("BAT_PAGER", "echo pager-output")
|
2018-10-17 18:44:15 +00:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-17 18:44:15 +00:00
|
|
|
|
.success()
|
2020-05-28 14:43:51 +00:00
|
|
|
|
.stdout(predicate::eq("pager-output\n").normalize());
|
2018-10-17 18:44:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pager_disable() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-05-28 03:30:51 +00:00
|
|
|
|
.env("PAGER", "echo other-pager")
|
2018-10-17 18:44:15 +00:00
|
|
|
|
.env("BAT_PAGER", "")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-10-17 18:44:15 +00:00
|
|
|
|
.success()
|
2020-05-28 14:43:51 +00:00
|
|
|
|
.stdout(predicate::eq("hello world\n").normalize());
|
2018-10-17 18:44:15 +00:00
|
|
|
|
}
|
2018-11-01 15:48:56 +00:00
|
|
|
|
|
2021-01-10 15:48:13 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn env_var_pager_value_bat() {
|
|
|
|
|
bat()
|
|
|
|
|
.env("PAGER", "bat")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(predicate::eq("hello world\n").normalize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn env_var_bat_pager_value_bat() {
|
|
|
|
|
bat()
|
|
|
|
|
.env("BAT_PAGER", "bat")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.failure()
|
|
|
|
|
.stderr(predicate::str::contains("bat as a pager is disallowed"));
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 09:13:57 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn pager_value_bat() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--pager=bat")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
2021-01-10 15:48:13 +00:00
|
|
|
|
.failure()
|
|
|
|
|
.stderr(predicate::str::contains("bat as a pager is disallowed"));
|
2020-10-25 09:13:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 09:23:13 +00:00
|
|
|
|
/// We shall use less instead of most if PAGER is used since PAGER
|
|
|
|
|
/// is a generic env var
|
2020-11-27 05:47:46 +00:00
|
|
|
|
#[test]
|
2021-01-04 14:45:56 +00:00
|
|
|
|
#[serial] // Because of PATH
|
2021-01-04 09:23:13 +00:00
|
|
|
|
fn pager_most_from_pager_env_var() {
|
2021-01-10 13:05:39 +00:00
|
|
|
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
2021-01-04 16:20:02 +00:00
|
|
|
|
// If the output is not "I am most" then we know 'most' is not used
|
2021-01-04 09:23:13 +00:00
|
|
|
|
bat()
|
2021-01-10 13:05:39 +00:00
|
|
|
|
.env("PAGER", mocked_pagers::from("most"))
|
2021-01-04 09:23:13 +00:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(predicate::eq("hello world\n").normalize());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// If the bat-specific BAT_PAGER is used, obey the wish of the user
|
|
|
|
|
/// and allow 'most'
|
|
|
|
|
#[test]
|
2021-01-04 14:45:56 +00:00
|
|
|
|
#[serial] // Because of PATH
|
2021-01-04 09:23:13 +00:00
|
|
|
|
fn pager_most_from_bat_pager_env_var() {
|
2021-01-10 13:05:39 +00:00
|
|
|
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
2021-01-04 09:23:13 +00:00
|
|
|
|
bat()
|
2021-01-10 13:05:39 +00:00
|
|
|
|
.env("BAT_PAGER", mocked_pagers::from("most"))
|
2021-01-04 09:23:13 +00:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
2021-01-04 16:20:02 +00:00
|
|
|
|
.stdout(predicate::str::contains("I am most"));
|
2021-01-04 09:23:13 +00:00
|
|
|
|
});
|
2020-11-27 05:47:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 09:23:13 +00:00
|
|
|
|
/// Same reasoning with --pager as with BAT_PAGER
|
|
|
|
|
#[test]
|
2021-01-04 14:45:56 +00:00
|
|
|
|
#[serial] // Because of PATH
|
2021-01-04 09:23:13 +00:00
|
|
|
|
fn pager_most_from_pager_arg() {
|
2021-01-10 13:05:39 +00:00
|
|
|
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
2021-01-04 09:23:13 +00:00
|
|
|
|
bat()
|
|
|
|
|
.arg("--paging=always")
|
2021-01-10 13:05:39 +00:00
|
|
|
|
.arg(format!("--pager={}", mocked_pagers::from("most")))
|
2021-01-04 09:23:13 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
2021-01-04 16:20:02 +00:00
|
|
|
|
.stdout(predicate::str::contains("I am most"));
|
2021-01-04 09:23:13 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Make sure the logic for 'most' applies even if an argument is passed
|
2020-11-27 05:47:46 +00:00
|
|
|
|
#[test]
|
2021-01-04 14:45:56 +00:00
|
|
|
|
#[serial] // Because of PATH
|
2020-11-27 05:47:46 +00:00
|
|
|
|
fn pager_most_with_arg() {
|
2021-01-10 13:05:39 +00:00
|
|
|
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
2021-01-04 09:23:13 +00:00
|
|
|
|
bat()
|
2021-01-10 13:05:39 +00:00
|
|
|
|
.env("PAGER", format!("{} -w", mocked_pagers::from("most")))
|
2021-01-04 09:23:13 +00:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(predicate::eq("hello world\n").normalize());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sanity check that 'more' is treated like 'most'
|
|
|
|
|
#[test]
|
2021-01-04 14:45:56 +00:00
|
|
|
|
#[serial] // Because of PATH
|
2021-01-04 09:23:13 +00:00
|
|
|
|
fn pager_more() {
|
2021-01-10 13:05:39 +00:00
|
|
|
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
2021-01-04 09:23:13 +00:00
|
|
|
|
bat()
|
2021-01-10 13:05:39 +00:00
|
|
|
|
.env("PAGER", mocked_pagers::from("more"))
|
2021-01-04 09:23:13 +00:00
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(predicate::eq("hello world\n").normalize());
|
|
|
|
|
});
|
2020-11-27 05:47:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 19:41:50 +00: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());
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 09:14:30 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn pager_failed_to_parse() {
|
|
|
|
|
bat()
|
|
|
|
|
.env("BAT_PAGER", "mismatched-quotes 'a")
|
|
|
|
|
.arg("--paging=always")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.failure()
|
|
|
|
|
.stderr(predicate::str::contains("Could not parse pager command"));
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-07 10:13:12 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn diagnostic_sanity_check() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--diagnostic")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(predicate::str::contains("BAT_PAGER="))
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 15:48:56 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn config_location_test() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat_with_config()
|
2018-11-01 15:48:56 +00:00
|
|
|
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
|
|
|
|
.arg("--config-file")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-11-01 15:48:56 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("bat.conf\n");
|
2021-02-27 11:21:06 +00:00
|
|
|
|
|
|
|
|
|
bat_with_config()
|
|
|
|
|
.env("BAT_CONFIG_PATH", "not-existing.conf")
|
|
|
|
|
.arg("--config-file")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("not-existing.conf\n");
|
2018-11-01 15:48:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 14:05:41 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn config_location_when_generating() {
|
2021-02-28 15:56:16 +00:00
|
|
|
|
let tmp_dir = tempdir().expect("can create temporary directory");
|
|
|
|
|
let tmp_config_path = tmp_dir.path().join("should-be-created.conf");
|
2021-02-28 14:05:41 +00:00
|
|
|
|
|
|
|
|
|
// Create the file with bat
|
|
|
|
|
bat_with_config()
|
|
|
|
|
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
|
|
|
|
|
.arg("--generate-config-file")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
2021-02-28 15:56:16 +00:00
|
|
|
|
.stdout(
|
|
|
|
|
predicate::str::is_match("Success! Config file written to .*should-be-created.conf\n")
|
|
|
|
|
.unwrap(),
|
|
|
|
|
);
|
2021-02-28 14:05:41 +00:00
|
|
|
|
|
|
|
|
|
// Now we expect the file to exist. If it exists, we assume contents are correct
|
|
|
|
|
assert!(tmp_config_path.exists());
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 22:08:13 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn config_location_from_bat_config_dir_variable() {
|
|
|
|
|
bat_with_config()
|
2021-08-14 19:42:34 +00:00
|
|
|
|
.env("BAT_CONFIG_DIR", "conf/")
|
|
|
|
|
.arg("--config-file")
|
2021-08-12 22:08:13 +00:00
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
2021-08-18 11:45:22 +00:00
|
|
|
|
.stdout(predicate::str::is_match("conf/config\n").unwrap());
|
2021-08-12 22:08:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 15:48:56 +00:00
|
|
|
|
#[test]
|
2018-11-04 09:56:31 +00:00
|
|
|
|
fn config_read_arguments_from_file() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat_with_config()
|
2018-11-01 15:48:56 +00:00
|
|
|
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2018-11-01 15:48:56 +00:00
|
|
|
|
.success()
|
2020-05-28 14:43:51 +00:00
|
|
|
|
.stdout(predicate::eq("dummy-pager-from-config\n").normalize());
|
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
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-02-10 08:19:38 +00:00
|
|
|
|
.arg("--plain")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("test_UTF-16LE.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-02-10 08:19:38 +00:00
|
|
|
|
.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() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat_with_config()
|
2019-05-10 19:02:08 +00:00
|
|
|
|
.arg("cache")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-05-10 19:02:08 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("test\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-21 07:10:12 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn can_print_file_named_cache_with_additional_argument() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat_with_config()
|
2019-09-21 07:10:12 +00:00
|
|
|
|
.arg("cache")
|
|
|
|
|
.arg("test.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-09-21 07:10:12 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("test\nhello world\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-31 12:13:19 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn can_print_file_starting_with_cache() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat_with_config()
|
2019-08-31 12:13:19 +00:00
|
|
|
|
.arg("cache.c")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-08-31 12:13:19 +00:00
|
|
|
|
.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
|
|
|
|
|
2021-07-27 18:11:58 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn accepts_no_custom_assets_arg() {
|
|
|
|
|
// Just make sure --no-custom-assets is considered a valid arg
|
|
|
|
|
// Don't bother to actually verify that it works
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--no-custom-assets")
|
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-01 09:49:29 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn unicode_wrap() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat_with_config()
|
2020-02-01 09:49:29 +00:00
|
|
|
|
.arg("unicode-wrap.txt")
|
|
|
|
|
.arg("--style=numbers,snip")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--terminal-width=40")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-02-01 09:49:29 +00:00
|
|
|
|
.success()
|
2020-02-28 09:27:06 +00:00
|
|
|
|
.stdout(
|
|
|
|
|
" 1 ビタミンA ビタミンD ビタミンE ビ
|
2020-02-28 02:42:44 +00:00
|
|
|
|
タミンK ビタミンB1 ビタミンB2 ナ
|
|
|
|
|
イアシン パントテン酸 ビタミンB6
|
|
|
|
|
ビタミンB12 葉酸 ビオチン ビタ
|
|
|
|
|
ミンC
|
2020-02-01 09:49:29 +00:00
|
|
|
|
2
|
2020-02-28 02:42:44 +00:00
|
|
|
|
3 고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이 고양이 고양이 고양이 고양이
|
|
|
|
|
고양이
|
2020-02-01 09:49:29 +00:00
|
|
|
|
4
|
2020-02-28 02:42:44 +00: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 09:49:29 +00:00
|
|
|
|
6
|
2020-02-28 02:42:44 +00:00
|
|
|
|
7 Бельгия Болгария Чехия Дания Герман
|
|
|
|
|
ия Эстония Ирландия Греция Испания
|
|
|
|
|
Франция Хорватия Италия Кипр Латвия
|
|
|
|
|
Литва Люксембург Венгрия Мальта Ни
|
|
|
|
|
дерланды Австрия Польша Португалия
|
|
|
|
|
Румыния Словения Словакия Финляндия
|
|
|
|
|
Швеция Великобритания
|
2020-02-28 09:27:06 +00:00
|
|
|
|
",
|
|
|
|
|
);
|
2020-02-01 09:49:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-31 10:46:03 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn snip() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2019-08-31 10:46:03 +00:00
|
|
|
|
.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")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2019-08-31 10:46:03 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout(
|
|
|
|
|
" 1 line 1
|
|
|
|
|
2 line 2
|
|
|
|
|
...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
|
|
|
|
|
4 line 4
|
|
|
|
|
",
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-02-27 23:09:01 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn empty_file_leads_to_empty_output_with_grid_enabled() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-02-27 23:09:01 +00:00
|
|
|
|
.arg("empty.txt")
|
|
|
|
|
.arg("--style=grid")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--terminal-width=80")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-02-27 23:09:01 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("");
|
|
|
|
|
}
|
2020-03-20 02:46:19 +00:00
|
|
|
|
|
2020-10-06 15:57:47 +00: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 02:46:19 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn filename_basic() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_binary() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.arg("test.binary")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo <BINARY>\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_stdin() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.arg("-r=0:0")
|
|
|
|
|
.arg("-")
|
|
|
|
|
.write_stdin("stdin\n")
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_stdin_binary() {
|
|
|
|
|
let vec = vec![0; 1];
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat_with_config()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=header")
|
|
|
|
|
.write_stdin(vec)
|
|
|
|
|
.arg("--file-name=foo")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-03-20 02:46:19 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("File: foo <BINARY>\n")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
2020-03-25 00:26:00 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn filename_multiple_ok() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-03-25 00:26:00 +00: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 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-03-25 00:26:00 +00:00
|
|
|
|
.success()
|
2020-05-12 00:57:51 +00:00
|
|
|
|
.stdout("File: foo\n\nFile: bar\n")
|
2020-03-25 00:26:00 +00: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 07:59:17 +00:00
|
|
|
|
|
2020-05-12 00:57:51 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn header_padding() {
|
2020-06-01 21:50:24 +00:00
|
|
|
|
bat()
|
2020-05-12 00:57:51 +00:00
|
|
|
|
.arg("--decorations=always")
|
2020-05-12 14:06:58 +00:00
|
|
|
|
.arg("--style=header")
|
2020-05-12 00:57:51 +00:00
|
|
|
|
.arg("test.txt")
|
|
|
|
|
.arg("single-line.txt")
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-05-12 14:06:58 +00:00
|
|
|
|
.stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n")
|
2020-05-12 00:57:51 +00:00
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 08:59:14 +00: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 08:02:08 +00: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 12:09:05 +00:00
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
#[test]
|
|
|
|
|
fn file_with_invalid_utf8_filename() {
|
|
|
|
|
use std::ffi::OsStr;
|
2020-04-21 14:02:28 +00:00
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::io::Write;
|
2020-04-21 12:09:05 +00:00
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
|
|
2021-02-28 15:56:16 +00:00
|
|
|
|
let tmp_dir = tempdir().expect("can create temporary directory");
|
2020-04-21 14:02:28 +00:00
|
|
|
|
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 21:50:24 +00:00
|
|
|
|
bat()
|
2020-04-21 14:02:28 +00:00
|
|
|
|
.arg(file_path.as_os_str())
|
2020-06-01 21:50:24 +00:00
|
|
|
|
.assert()
|
2020-04-21 14:02:28 +00:00
|
|
|
|
.success()
|
|
|
|
|
.stdout("dummy content\n");
|
2020-04-21 12:09:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 07:59:17 +00: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 09:51:49 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn do_not_detect_different_syntax_for_stdin_and_files() {
|
|
|
|
|
let file = "regression_tests/issue_985.js";
|
|
|
|
|
|
2020-05-15 19:29:01 +00:00
|
|
|
|
let cmd_for_file = bat()
|
2020-05-13 09:51:49 +00:00
|
|
|
|
.arg("--color=always")
|
|
|
|
|
.arg("--map-syntax=*.js:Markdown")
|
|
|
|
|
.arg(&format!("--file-name={}", file))
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg(file)
|
|
|
|
|
.assert()
|
2020-05-15 19:29:01 +00:00
|
|
|
|
.success();
|
2020-05-13 09:51:49 +00:00
|
|
|
|
|
2020-05-15 19:29:01 +00:00
|
|
|
|
let cmd_for_stdin = bat()
|
2020-05-13 09:51:49 +00: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 19:29:01 +00:00
|
|
|
|
.success();
|
2020-05-13 09:51:49 +00:00
|
|
|
|
|
|
|
|
|
assert_eq!(
|
2020-05-15 19:29:01 +00: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 09:51:49 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-20 15:00:32 +00:00
|
|
|
|
|
2021-09-16 15:01:12 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn no_first_line_fallback_when_mapping_to_invalid_syntax() {
|
|
|
|
|
let file = "regression_tests/first_line_fallback.invalid-syntax";
|
|
|
|
|
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--color=always")
|
|
|
|
|
.arg("--map-syntax=*.invalid-syntax:InvalidSyntax")
|
|
|
|
|
.arg(&format!("--file-name={}", file))
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg(file)
|
|
|
|
|
.assert()
|
|
|
|
|
.failure()
|
|
|
|
|
.stderr(predicate::str::contains("unknown syntax: 'InvalidSyntax'"));
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-20 15:00:32 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn show_all_mode() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--show-all")
|
|
|
|
|
.arg("nonprintable.txt")
|
|
|
|
|
.assert()
|
2020-07-06 20:44:19 +00:00
|
|
|
|
.stdout("hello·world␊\n├──┤␍␀␇␈␛")
|
2020-06-20 15:00:32 +00:00
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
2020-12-21 07:34:22 +00:00
|
|
|
|
|
2021-08-09 08:54:32 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn no_paging_arg() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--no-paging")
|
|
|
|
|
.arg("--color=never")
|
|
|
|
|
.arg("--decorations=never")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single Line");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn no_paging_short_arg() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("-P")
|
|
|
|
|
.arg("--color=never")
|
|
|
|
|
.arg("--decorations=never")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single Line");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn no_pager_arg() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--no-pager")
|
|
|
|
|
.arg("--color=never")
|
|
|
|
|
.arg("--decorations=never")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single Line");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 07:34:22 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn plain_mode_does_not_add_nonexisting_newline() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--paging=never")
|
|
|
|
|
.arg("--color=never")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=plain")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("Single Line");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 16:00:14 +00:00
|
|
|
|
// Regression test for https://github.com/sharkdp/bat/issues/299
|
|
|
|
|
#[test]
|
|
|
|
|
fn grid_for_file_without_newline() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("--paging=never")
|
|
|
|
|
.arg("--color=never")
|
|
|
|
|
.arg("--terminal-width=80")
|
|
|
|
|
.arg("--wrap=never")
|
|
|
|
|
.arg("--decorations=always")
|
|
|
|
|
.arg("--style=full")
|
|
|
|
|
.arg("single-line.txt")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout(
|
|
|
|
|
"\
|
|
|
|
|
───────┬────────────────────────────────────────────────────────────────────────
|
|
|
|
|
│ File: single-line.txt
|
|
|
|
|
───────┼────────────────────────────────────────────────────────────────────────
|
|
|
|
|
1 │ Single Line
|
|
|
|
|
───────┴────────────────────────────────────────────────────────────────────────
|
|
|
|
|
",
|
|
|
|
|
)
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|
2021-11-19 16:05:23 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn ignored_suffix_arg() {
|
|
|
|
|
bat()
|
|
|
|
|
.arg("-f")
|
|
|
|
|
.arg("-p")
|
|
|
|
|
.arg("test.json~")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m")
|
|
|
|
|
.stderr("");
|
|
|
|
|
|
|
|
|
|
bat()
|
|
|
|
|
.arg("-f")
|
|
|
|
|
.arg("-p")
|
|
|
|
|
.arg("--ignored-suffix=.suffix")
|
|
|
|
|
.arg("test.json.suffix")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m")
|
|
|
|
|
.stderr("");
|
|
|
|
|
|
|
|
|
|
bat()
|
|
|
|
|
.arg("-f")
|
|
|
|
|
.arg("-p")
|
|
|
|
|
.arg("test.json.suffix")
|
|
|
|
|
.assert()
|
|
|
|
|
.success()
|
|
|
|
|
.stdout("\u{1b}[38;5;231m{\"test\": \"value\"}\u{1b}[0m")
|
|
|
|
|
.stderr("");
|
|
|
|
|
}
|