summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-02-03 20:33:52 -0500
committerAndrew Gallant <jamslam@gmail.com>2018-02-04 10:40:20 -0500
commitc57d0fb4e862005ca0c7b79fb90a31a11e022ff7 (patch)
tree5af2b3c6e5426dd30ba55e5250c4e2ddab1f920b /tests
parentd83bab4d3f29a0176a20ea004c2cba44058d4210 (diff)
config: add persistent configuration
This commit adds support for reading configuration files that change ripgrep's default behavior. The format of the configuration file is an "rc" style and is very simple. It is defined by two rules: 1. Every line is a shell argument, after trimming ASCII whitespace. 2. Lines starting with '#' (optionally preceded by any amount of ASCII whitespace) are ignored. ripgrep will look for a single configuration file if and only if the RIPGREP_CONFIG_PATH environment variable is set and is non-empty. ripgrep will parse shell arguments from this file on startup and will behave as if the arguments in this file were prepended to any explicit arguments given to ripgrep on the command line. For example, if your ripgreprc file contained a single line: --smart-case then the following command RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo would behave identically to the following command rg --smart-case foo This commit also adds a new flag, --no-config, that when present will suppress any and all support for configuration. This includes any future support for auto-loading configuration files from pre-determined paths (which this commit does not add). Conflicts between configuration files and explicit arguments are handled exactly like conflicts in the same command line invocation. That is, this command: RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo --case-sensitive is exactly equivalent to rg --smart-case foo --case-sensitive in which case, the --case-sensitive flag would override the --smart-case flag. Closes #196
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.rs16
-rw-r--r--tests/workdir.rs1
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index dc19350c..ecc840e7 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1711,6 +1711,22 @@ fn compressed_failing_gzip() {
assert_eq!(err.contains("not in gzip format"), true);
}
+sherlock!(feature_196_persistent_config, "sherlock",
+|wd: WorkDir, mut cmd: Command| {
+ // Make sure we get no matches by default.
+ wd.assert_err(&mut cmd);
+
+ // Now add our config file, and make sure it impacts ripgrep.
+ wd.create(".ripgreprc", "--ignore-case");
+ cmd.env("RIPGREP_CONFIG_PATH", ".ripgreprc");
+ let lines: String = wd.stdout(&mut cmd);
+ let expected = "\
+For the Doctor Watsons of this world, as opposed to the Sherlock
+be, to a very large extent, the result of luck. Sherlock Holmes
+";
+ assert_eq!(lines, expected);
+});
+
#[test]
fn feature_740_passthru() {
let wd = WorkDir::new("feature_740");
diff --git a/tests/workdir.rs b/tests/workdir.rs
index ea5408a4..3c47e948 100644
--- a/tests/workdir.rs
+++ b/tests/workdir.rs
@@ -93,6 +93,7 @@ impl WorkDir {
/// this working directory.
pub fn command(&self) -> process::Command {
let mut cmd = process::Command::new(&self.bin());
+ cmd.env_remove("RIPGREP_CONFIG_PATH");
cmd.current_dir(&self.dir);
cmd
}