Skip to content

Commit

Permalink
Add test for systemwide config file support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Patrick Pichler committed Oct 28, 2021
1 parent a2e937c commit 25f6f03
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ jobs:
- name: Test custom assets
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:
name: Documentation
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/bat.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Make sure that the pager gets executed
--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"
5 changes: 5 additions & 0 deletions tests/examples/system_config/bat/config
Original file line number Diff line number Diff line change
@@ -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"
47 changes: 47 additions & 0 deletions tests/system_wide_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use assert_cmd::cargo::CommandCargoExt;
use predicates::{prelude::predicate, str::PredicateStrExt};
use std::process::Command;

fn bat_raw_command() -> 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() -> assert_cmd::Command {
assert_cmd::Command::from_std(bat_raw_command())
}

// This test is ignored, as it needs a special system wide config put into place
#[test]
#[ignore]
fn use_systemwide_config() {
bat()
.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
#[test]
#[ignore]
fn config_overrides_system_config() {
bat()
.env("BAT_CONFIG_PATH", "bat.conf")
.arg("test.txt")
.assert()
.success()
.stdout(predicate::eq("dummy-pager-from-config\n").normalize());
}

0 comments on commit 25f6f03

Please sign in to comment.