mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-21 12:28:30 +00:00
Changed to unwrap methods, added integration tests
This commit is contained in:
parent
1dd57e6d7e
commit
558134f6c8
@ -9,17 +9,11 @@ use dirs::PROJECT_DIRS;
|
|||||||
use util::transpose;
|
use util::transpose;
|
||||||
|
|
||||||
pub fn config_file() -> PathBuf {
|
pub fn config_file() -> PathBuf {
|
||||||
match env::var("BAT_CONFIG_PATH") {
|
env::var("BAT_CONFIG_PATH")
|
||||||
Ok(env_path) => {
|
.ok()
|
||||||
let env_path_buf = PathBuf::from(env_path);
|
.map(PathBuf::from)
|
||||||
if env_path_buf.is_file() {
|
.filter(|config_path| config_path.is_file())
|
||||||
return env_path_buf;
|
.unwrap_or(PROJECT_DIRS.config_dir().join("config"))
|
||||||
} else {
|
|
||||||
return PROJECT_DIRS.config_dir().join("config");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => PROJECT_DIRS.config_dir().join("config"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
|
pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
|
||||||
|
1
tests/examples/bat.conf
Normal file
1
tests/examples/bat.conf
Normal file
@ -0,0 +1 @@
|
|||||||
|
--paging=always
|
@ -322,3 +322,34 @@ fn pager_disable() {
|
|||||||
.success()
|
.success()
|
||||||
.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]
|
||||||
|
fn config_location_test() {
|
||||||
|
bat_config()
|
||||||
|
.env_remove("BAT_CONFIG_PATH")
|
||||||
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
||||||
|
.arg("--config-file")
|
||||||
|
.assert()
|
||||||
|
.success()
|
||||||
|
.stdout("bat.conf\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn config_read_paging_test() {
|
||||||
|
bat_config()
|
||||||
|
.env_remove("BAT_CONFIG_PATH")
|
||||||
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
||||||
|
.env("BAT_PAGER", "echo testing-config-file")
|
||||||
|
.arg("test.txt")
|
||||||
|
.assert()
|
||||||
|
.success()
|
||||||
|
.stdout("testing-config-file\n");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user