on master help sign in
Changed to unwrap methods, added integration tests
commit558134f6c8a9c3601c48863a45f5c3bf7f125972 authorRicky <Ricky@Hosfelt.io> dateThu 1 Nov 2018, 15:48 (8 years ago) parent1dd57e6
3 files changed+37−11
src/config.rs+5−11 tests/examples/bat.conf+1 tests/integration_tests.rs+31
src/config.rs+5−11
@@ -9,17 +9,11 @@ use dirs::PROJECT_DIRS;
99use util::transpose;
1010
1111pub fn config_file() -> PathBuf {
12− match env::var("BAT_CONFIG_PATH") {
13− Ok(env_path) => {
14− let env_path_buf = PathBuf::from(env_path);
15− if env_path_buf.is_file() {
16− return env_path_buf;
17− } else {
18− return PROJECT_DIRS.config_dir().join("config");
19− }
20− }
21− Err(_) => PROJECT_DIRS.config_dir().join("config"),
22− }
12+ env::var("BAT_CONFIG_PATH")
13+ .ok()
14+ .map(PathBuf::from)
15+ .filter(|config_path| config_path.is_file())
16+ .unwrap_or(PROJECT_DIRS.config_dir().join("config"))
2317}
2418
2519pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
tests/examples/bat.confnew file+1
@@ -0,0 +1 @@
1+--paging=always
tests/integration_tests.rs+31
@@ -322,3 +322,34 @@ fn pager_disable() {
322322 .success()
323323 .stdout("hello world\n");
324324}
325+
326+fn bat_config() -> Command {
327+ let mut cmd = Command::main_binary().unwrap();
328+ cmd.current_dir("tests/examples");
329+ cmd.env_remove("BAT_PAGER");
330+ cmd.env_remove("BAT_CONFIG_PATH");
331+ cmd
332+}
333+
334+#[test]
335+fn config_location_test() {
336+ bat_config()
337+ .env_remove("BAT_CONFIG_PATH")
338+ .env("BAT_CONFIG_PATH", "bat.conf")
339+ .arg("--config-file")
340+ .assert()
341+ .success()
342+ .stdout("bat.conf\n");
343+}
344+
345+#[test]
346+fn config_read_paging_test() {
347+ bat_config()
348+ .env_remove("BAT_CONFIG_PATH")
349+ .env("BAT_CONFIG_PATH", "bat.conf")
350+ .env("BAT_PAGER", "echo testing-config-file")
351+ .arg("test.txt")
352+ .assert()
353+ .success()
354+ .stdout("testing-config-file\n");
355+}