Simplify integration test setup

This commit is contained in:
sharkdp 2018-11-04 10:46:56 +01:00 committed by David Peter
parent 558134f6c8
commit 48c6ea6b25

View File

@ -3,12 +3,18 @@ extern crate assert_cmd;
use assert_cmd::prelude::*; use assert_cmd::prelude::*;
use std::process::Command; use std::process::Command;
fn bat() -> Command { fn bat_with_config() -> Command {
let mut cmd = Command::main_binary().unwrap(); let mut cmd = Command::main_binary().unwrap();
cmd.current_dir("tests/examples"); cmd.current_dir("tests/examples");
cmd.arg("--no-config");
cmd.env_remove("PAGER"); cmd.env_remove("PAGER");
cmd.env_remove("BAT_PAGER"); cmd.env_remove("BAT_PAGER");
cmd.env_remove("BAT_CONFIG_PATH");
cmd
}
fn bat() -> Command {
let mut cmd = bat_with_config();
cmd.arg("--no-config");
cmd cmd
} }
@ -323,18 +329,9 @@ fn pager_disable() {
.stdout("hello world\n"); .stdout("hello world\n");
} }
fn bat_config() -> Command {
let mut cmd = Command::main_binary().unwrap();
cmd.current_dir("tests/examples");
cmd.env_remove("BAT_PAGER");
cmd.env_remove("BAT_CONFIG_PATH");
cmd
}
#[test] #[test]
fn config_location_test() { fn config_location_test() {
bat_config() bat_with_config()
.env_remove("BAT_CONFIG_PATH")
.env("BAT_CONFIG_PATH", "bat.conf") .env("BAT_CONFIG_PATH", "bat.conf")
.arg("--config-file") .arg("--config-file")
.assert() .assert()
@ -344,8 +341,7 @@ fn config_location_test() {
#[test] #[test]
fn config_read_paging_test() { fn config_read_paging_test() {
bat_config() bat_with_config()
.env_remove("BAT_CONFIG_PATH")
.env("BAT_CONFIG_PATH", "bat.conf") .env("BAT_CONFIG_PATH", "bat.conf")
.env("BAT_PAGER", "echo testing-config-file") .env("BAT_PAGER", "echo testing-config-file")
.arg("test.txt") .arg("test.txt")