mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-29 03:04:04 +01:00
Add test for systemwide config file support
There is now a new stage in the CICD workflow present, which will build `bat` with the `BAT_SYSTEM_CONFIG_PREFIX` set to load the config file from `/tests/examples/system_config/bat/config`, plus a basic set of tests, to ensure the feature is working as expected. By default the tests are set to ignored, as they need special setup before they can be run.
This commit is contained in:
parent
5ed64444e3
commit
6b660ef63a
28
.github/workflows/CICD.yml
vendored
28
.github/workflows/CICD.yml
vendored
@ -96,7 +96,7 @@ jobs:
|
|||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --locked --release -- --ignored
|
args: --locked --release --test assets -- --ignored
|
||||||
- name: Syntax highlighting regression test
|
- name: Syntax highlighting regression test
|
||||||
run: tests/syntax-tests/regression_test.sh
|
run: tests/syntax-tests/regression_test.sh
|
||||||
- name: List of languages
|
- name: List of languages
|
||||||
@ -106,6 +106,32 @@ jobs:
|
|||||||
- name: Test custom assets
|
- name: Test custom assets
|
||||||
run: tests/syntax-tests/test_custom_assets.sh
|
run: tests/syntax-tests/test_custom_assets.sh
|
||||||
|
|
||||||
|
test_with_system_config:
|
||||||
|
name: Run tests with system wide configuration
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Git checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Prepare environment variables
|
||||||
|
run: |
|
||||||
|
echo "BAT_SYSTEM_CONFIG_PREFIX=$GITHUB_WORKSPACE/tests/examples/system_config" >> $GITHUB_ENV
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
default: true
|
||||||
|
profile: minimal
|
||||||
|
- name: Build and install bat
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: install
|
||||||
|
args: --locked --path .
|
||||||
|
- name: Run unit tests
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --locked --test system_wide_config -- --ignored
|
||||||
|
|
||||||
documentation:
|
documentation:
|
||||||
name: Documentation
|
name: Documentation
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
2
tests/examples/bat.conf
vendored
2
tests/examples/bat.conf
vendored
@ -1,5 +1,5 @@
|
|||||||
# Make sure that the pager gets executed
|
# Make sure that the pager gets executed
|
||||||
--paging=always
|
--paging=always
|
||||||
|
|
||||||
# Output a dummy message for the integration test.
|
# Output a dummy message for the integration test and system wide config test.
|
||||||
--pager="echo dummy-pager-from-config"
|
--pager="echo dummy-pager-from-config"
|
||||||
|
5
tests/examples/system_config/bat/config
vendored
Normal file
5
tests/examples/system_config/bat/config
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Make sure that the pager gets executed
|
||||||
|
--paging=always
|
||||||
|
|
||||||
|
# Output a dummy message for the integration test.
|
||||||
|
--pager="echo dummy-pager-from-system-config"
|
@ -3,7 +3,6 @@ use predicates::boolean::PredicateBooleanExt;
|
|||||||
use predicates::{prelude::predicate, str::PredicateStrExt};
|
use predicates::{prelude::predicate, str::PredicateStrExt};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
@ -28,41 +27,14 @@ mod unix {
|
|||||||
use unix::*;
|
use unix::*;
|
||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
use utils::command::{bat, bat_with_config};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use utils::command::bat_raw_command;
|
||||||
use utils::mocked_pagers;
|
use utils::mocked_pagers;
|
||||||
|
|
||||||
const EXAMPLES_DIR: &str = "tests/examples";
|
const EXAMPLES_DIR: &str = "tests/examples";
|
||||||
|
|
||||||
fn bat_raw_command_with_config() -> Command {
|
|
||||||
let mut cmd = Command::cargo_bin("bat").unwrap();
|
|
||||||
cmd.current_dir("tests/examples");
|
|
||||||
cmd.env_remove("BAT_CACHE_PATH");
|
|
||||||
cmd.env_remove("BAT_CONFIG_DIR");
|
|
||||||
cmd.env_remove("BAT_CONFIG_PATH");
|
|
||||||
cmd.env_remove("BAT_OPTS");
|
|
||||||
cmd.env_remove("BAT_PAGER");
|
|
||||||
cmd.env_remove("BAT_STYLE");
|
|
||||||
cmd.env_remove("BAT_TABS");
|
|
||||||
cmd.env_remove("BAT_THEME");
|
|
||||||
cmd.env_remove("COLORTERM");
|
|
||||||
cmd.env_remove("NO_COLOR");
|
|
||||||
cmd.env_remove("PAGER");
|
|
||||||
cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bat_raw_command() -> Command {
|
|
||||||
let mut cmd = bat_raw_command_with_config();
|
|
||||||
cmd.arg("--no-config");
|
|
||||||
cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bat_with_config() -> assert_cmd::Command {
|
|
||||||
assert_cmd::Command::from_std(bat_raw_command_with_config())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bat() -> assert_cmd::Command {
|
|
||||||
assert_cmd::Command::from_std(bat_raw_command())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn basic() {
|
||||||
bat()
|
bat()
|
||||||
|
29
tests/system_wide_config.rs
Normal file
29
tests/system_wide_config.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use predicates::{prelude::predicate, str::PredicateStrExt};
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
use utils::command::bat_with_config;
|
||||||
|
|
||||||
|
// This test is ignored, as it needs a special system wide config put into place.
|
||||||
|
// In order to run this tests, use `cargo test --test system_wide_config -- --ignored`
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn use_systemwide_config() {
|
||||||
|
bat_with_config()
|
||||||
|
.arg("test.txt")
|
||||||
|
.assert()
|
||||||
|
.success()
|
||||||
|
.stdout(predicate::eq("dummy-pager-from-system-config\n").normalize());
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test is ignored, as it needs a special system wide config put into place
|
||||||
|
// In order to run this tests, use `cargo test --test system_wide_config -- --ignored`
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn config_overrides_system_config() {
|
||||||
|
bat_with_config()
|
||||||
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
||||||
|
.arg("test.txt")
|
||||||
|
.assert()
|
||||||
|
.success()
|
||||||
|
.stdout(predicate::eq("dummy-pager-from-config\n").normalize());
|
||||||
|
}
|
36
tests/utils/command.rs
Normal file
36
tests/utils/command.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
use assert_cmd::cargo::CommandCargoExt;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
pub fn bat_raw_command_with_config() -> Command {
|
||||||
|
let mut cmd = Command::cargo_bin("bat").unwrap();
|
||||||
|
cmd.current_dir("tests/examples");
|
||||||
|
cmd.env_remove("BAT_CACHE_PATH");
|
||||||
|
cmd.env_remove("BAT_CONFIG_DIR");
|
||||||
|
cmd.env_remove("BAT_CONFIG_PATH");
|
||||||
|
cmd.env_remove("BAT_OPTS");
|
||||||
|
cmd.env_remove("BAT_PAGER");
|
||||||
|
cmd.env_remove("BAT_STYLE");
|
||||||
|
cmd.env_remove("BAT_TABS");
|
||||||
|
cmd.env_remove("BAT_THEME");
|
||||||
|
cmd.env_remove("COLORTERM");
|
||||||
|
cmd.env_remove("NO_COLOR");
|
||||||
|
cmd.env_remove("PAGER");
|
||||||
|
cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn bat_raw_command() -> Command {
|
||||||
|
let mut cmd = bat_raw_command_with_config();
|
||||||
|
cmd.arg("--no-config");
|
||||||
|
cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn bat_with_config() -> assert_cmd::Command {
|
||||||
|
assert_cmd::Command::from_std(bat_raw_command_with_config())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn bat() -> assert_cmd::Command {
|
||||||
|
assert_cmd::Command::from_std(bat_raw_command())
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
|
pub mod command;
|
||||||
pub mod mocked_pagers;
|
pub mod mocked_pagers;
|
||||||
|
Loading…
Reference in New Issue
Block a user