mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-18 20:11:03 +00:00
Co-authored-by: Boy van Duuren <boy.van.duuren@rabobank.nl>
This commit is contained in:
parent
f49278cfaa
commit
d6e11b59e7
8
.github/workflows/CICD.yml
vendored
8
.github/workflows/CICD.yml
vendored
@ -247,7 +247,13 @@ jobs:
|
|||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
shell: bash
|
shell: bash
|
||||||
run: $BUILD_CMD test --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}
|
run: |
|
||||||
|
if [[ ${{ matrix.job.os }} = windows-* ]]
|
||||||
|
then
|
||||||
|
powershell.exe -command "$BUILD_CMD test --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}"
|
||||||
|
else
|
||||||
|
$BUILD_CMD test --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Run bat
|
- name: Run bat
|
||||||
shell: bash
|
shell: bash
|
||||||
|
5
tests/examples/bat-windows.conf
vendored
Normal file
5
tests/examples/bat-windows.conf
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Make sure that the pager gets executed
|
||||||
|
--paging=always
|
||||||
|
|
||||||
|
# Output a dummy message for the integration test and system wide config test.
|
||||||
|
--pager="echo.bat dummy-pager-from-config"
|
@ -34,6 +34,14 @@ use utils::mocked_pagers;
|
|||||||
|
|
||||||
const EXAMPLES_DIR: &str = "tests/examples";
|
const EXAMPLES_DIR: &str = "tests/examples";
|
||||||
|
|
||||||
|
fn get_config() -> &'static str {
|
||||||
|
if cfg!(windows) {
|
||||||
|
"bat-windows.conf"
|
||||||
|
} else {
|
||||||
|
"bat.conf"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn basic() {
|
||||||
bat()
|
bat()
|
||||||
@ -589,37 +597,49 @@ fn do_not_exit_directory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn pager_basic() {
|
fn pager_basic() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat()
|
bat()
|
||||||
.env("PAGER", "echo pager-output")
|
.env("PAGER", mocked_pagers::from("echo pager-output"))
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn pager_basic_arg() {
|
fn pager_basic_arg() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat()
|
bat()
|
||||||
.arg("--pager=echo pager-output")
|
.arg(format!(
|
||||||
|
"--pager={}",
|
||||||
|
mocked_pagers::from("echo pager-output")
|
||||||
|
))
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn pager_overwrite() {
|
fn pager_overwrite() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat()
|
bat()
|
||||||
.env("PAGER", "echo other-pager")
|
.env("PAGER", mocked_pagers::from("echo other-pager"))
|
||||||
.env("BAT_PAGER", "echo pager-output")
|
.env("BAT_PAGER", mocked_pagers::from("echo pager-output"))
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -635,55 +655,73 @@ fn pager_disable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn pager_arg_override_env_withconfig() {
|
fn pager_arg_override_env_withconfig() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat_with_config()
|
bat_with_config()
|
||||||
.env("BAT_CONFIG_PATH", "bat.conf")
|
.env("BAT_CONFIG_PATH", get_config())
|
||||||
.env("PAGER", "echo another-pager")
|
.env("PAGER", mocked_pagers::from("echo another-pager"))
|
||||||
.env("BAT_PAGER", "echo other-pager")
|
.env("BAT_PAGER", mocked_pagers::from("echo other-pager"))
|
||||||
.arg("--pager=echo pager-output")
|
.arg(format!(
|
||||||
|
"--pager={}",
|
||||||
|
mocked_pagers::from("echo pager-output")
|
||||||
|
))
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn pager_arg_override_env_noconfig() {
|
fn pager_arg_override_env_noconfig() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat()
|
bat()
|
||||||
.env("PAGER", "echo another-pager")
|
.env("PAGER", mocked_pagers::from("echo another-pager"))
|
||||||
.env("BAT_PAGER", "echo other-pager")
|
.env("BAT_PAGER", mocked_pagers::from("echo other-pager"))
|
||||||
.arg("--pager=echo pager-output")
|
.arg(format!(
|
||||||
|
"--pager={}",
|
||||||
|
mocked_pagers::from("echo pager-output")
|
||||||
|
))
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn pager_env_bat_pager_override_config() {
|
fn pager_env_bat_pager_override_config() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat_with_config()
|
bat_with_config()
|
||||||
.env("BAT_CONFIG_PATH", "bat.conf")
|
.env("BAT_CONFIG_PATH", get_config())
|
||||||
.env("PAGER", "echo other-pager")
|
.env("PAGER", mocked_pagers::from("echo other-pager"))
|
||||||
.env("BAT_PAGER", "echo pager-output")
|
.env("BAT_PAGER", mocked_pagers::from("echo pager-output"))
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn pager_env_pager_nooverride_config() {
|
fn pager_env_pager_nooverride_config() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat_with_config()
|
bat_with_config()
|
||||||
.env("BAT_CONFIG_PATH", "bat.conf")
|
.env("BAT_CONFIG_PATH", get_config())
|
||||||
.env("PAGER", "echo other-pager")
|
.env("PAGER", mocked_pagers::from("echo other-pager"))
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("dummy-pager-from-config\n").normalize());
|
.stdout(predicate::str::contains("dummy-pager-from-config\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -809,15 +847,18 @@ fn alias_pager_disable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn alias_pager_disable_long_overrides_short() {
|
fn alias_pager_disable_long_overrides_short() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat()
|
bat()
|
||||||
.env("PAGER", "echo pager-output")
|
.env("PAGER", mocked_pagers::from("echo pager-output"))
|
||||||
.arg("-P")
|
.arg("-P")
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -844,14 +885,17 @@ fn pager_failed_to_parse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn env_var_bat_paging() {
|
fn env_var_bat_paging() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat()
|
bat()
|
||||||
.env("BAT_PAGER", "echo pager-output")
|
.env("BAT_PAGER", mocked_pagers::from("echo pager-output"))
|
||||||
.env("BAT_PAGING", "always")
|
.env("BAT_PAGING", "always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("pager-output\n"));
|
.stdout(predicate::str::contains("pager-output\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -912,13 +956,16 @@ fn config_location_from_bat_config_dir_variable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[serial]
|
||||||
fn config_read_arguments_from_file() {
|
fn config_read_arguments_from_file() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
bat_with_config()
|
bat_with_config()
|
||||||
.env("BAT_CONFIG_PATH", "bat.conf")
|
.env("BAT_CONFIG_PATH", get_config())
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::eq("dummy-pager-from-config\n").normalize());
|
.stdout(predicate::str::contains("dummy-pager-from-config\n").normalize());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
1
tests/mocked-pagers/echo.bat
Normal file
1
tests/mocked-pagers/echo.bat
Normal file
@ -0,0 +1 @@
|
|||||||
|
ECHO %*
|
@ -17,11 +17,16 @@ fn get_mocked_pagers_dir() -> PathBuf {
|
|||||||
/// On Unix: 'most' -> 'most'
|
/// On Unix: 'most' -> 'most'
|
||||||
/// On Windows: 'most' -> 'most.bat'
|
/// On Windows: 'most' -> 'most.bat'
|
||||||
pub fn from(base: &str) -> String {
|
pub fn from(base: &str) -> String {
|
||||||
if cfg!(windows) {
|
let mut cmd_and_args = shell_words::split(base).unwrap();
|
||||||
format!("{}.bat", base)
|
let suffix = if cfg!(windows) { ".bat" } else { "" };
|
||||||
} else {
|
let mut out_cmd = format!("{}{}", cmd_and_args.first().unwrap(), suffix);
|
||||||
String::from(base)
|
|
||||||
|
if (cmd_and_args.len() > 1) {
|
||||||
|
out_cmd.push(' ');
|
||||||
|
out_cmd.push_str(cmd_and_args[1..].to_vec().join(" ").as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepends a directory to the PATH environment variable
|
/// Prepends a directory to the PATH environment variable
|
||||||
@ -62,6 +67,11 @@ pub fn with_mocked_versions_of_more_and_most_in_path(actual_test: fn()) {
|
|||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::str::contains("I am most"));
|
.stdout(predicate::str::contains("I am most"));
|
||||||
|
Command::new(from("echo"))
|
||||||
|
.arg("foobar")
|
||||||
|
.assert()
|
||||||
|
.success()
|
||||||
|
.stdout(predicate::str::contains("foobar"));
|
||||||
|
|
||||||
// Now run the actual test
|
// Now run the actual test
|
||||||
actual_test();
|
actual_test();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user