summaryrefslogtreecommitdiffstats
path: root/tests
AgeCommit message (Collapse)Author
2019-05-29progressag/snafuAndrew Gallant
2019-04-19cli: fix bug where last byte was strippedAndrew Gallant
In an effort to strip line terminators, we assumed their existence. But a pattern file may not end with a line terminator, so we shouldn't unconditionally strip them. We fix this by moving to bstr's line handling, which does this for us automatically.
2019-04-15ripgrep: max-column-preview --> max-columns-previewAndrew Gallant
Credit to @okdana for catching this. This naming is a bit more consistent with the existing --max-columns flag.
2019-04-14ripgrep: add --auto-hybrid-regex flagAndrew Gallant
This flag, when set, will automatically dispatch to PCRE2 if the given regex cannot be compiled by Rust's regex engine. If both engines fail to compile the regex, then both errors are surfaced. Closes #1155
2019-04-14printer: support previews for long linesAndrew Gallant
This commit adds support for showing a preview of long lines. While the default still remains as completely suppressing the entire line, this new functionality will show the first N graphemes of a matching line, including the number of matches that are suppressed. This was unfortunately a fairly invasive change to the printer that required a bit of refactoring. On the bright side, the single line and multi-line coloring are now more unified than they were before. Closes #1078
2019-04-14binary: rejigger ripgrep's handling of binary filesAndrew Gallant
This commit attempts to surface binary filtering in a slightly more user friendly way. Namely, before, ripgrep would silently stop searching a file if it detected a NUL byte, even if it had previously printed a match. This can lead to the user quite reasonably assuming that there are no more matches, since a partial search is fairly unintuitive. (ripgrep has this behavior by default because it really wants to NOT search binary files at all, just like it doesn't search gitignored or hidden files.) With this commit, if a match has already been printed and ripgrep detects a NUL byte, then it will print a warning message indicating that the search stopped prematurely. Moreover, this commit adds a new flag, --binary, which causes ripgrep to stop filtering binary files, but in a way that still avoids dumping binary data into terminals. That is, the --binary flag makes ripgrep behave more like grep's default behavior. For files explicitly specified in a search, e.g., `rg foo some-file`, then no binary filtering is applied (just like no gitignore and no hidden file filtering is applied). Instead, ripgrep behaves as if you gave the --binary flag for all explicitly given files. This was a fairly invasive change, and potentially increases the UX complexity of ripgrep around binary files. (Before, there were two binary modes, where as now there are three.) However, ripgrep is now a bit louder with warning messages when binary file detection might otherwise be hiding potential matches, so hopefully this is a net improvement. Finally, the `-uuu` convenience now maps to `--no-ignore --hidden --binary`, since this is closer to the actualy intent of the `--unrestricted` flag, i.e., to reduce ripgrep's smart filtering. As a consequence, `rg -uuu foo` should now search roughly the same number of bytes as `grep -r foo`, and `rg -uuua foo` should search roughly the same number of bytes as `grep -ra foo`. (The "roughly" weasel word is used because grep's and ripgrep's binary file detection might differ somewhat---perhaps based on buffer sizes---which can impact exactly what is and isn't searched.) See the numerous tests in tests/binary.rs for intended behavior. Fixes #306, Fixes #855
2019-04-06searcher: add option to disable BOM sniffinglesnyrumcajs
This commit adds a new encoding feature where the -E/--encoding flag will now accept a value of 'none'. When given this value, all encoding related machinery is disabled and ripgrep will search the raw bytes of the file, including the BOM if it's present. Closes #1207, Closes #1208
2019-02-27regex: bump regex dep to fix match bugAndrew Gallant
See * https://github.com/rust-lang/regex/commit/661bf53d5b2b6dde25549aaad601ad8c59b37bfd * https://github.com/rust-lang/regex/commit/edf45e6f5fa54705298ba14f3216cfb5277c0908 for details on the bug fix, which was in the regex engine. Fixes #1203
2019-02-09tests: use const constructor for atomicsAndrew Gallant
We did this in 05411b2b for core ripgrep, but didn't carry it over to tests.
2019-01-26search: fix -F and -f interaction bugAndrew Gallant
This fixes what appears to be a pretty egregious regression where the `-F/--fixed-strings` flag wasn't be applied to patterns supplied via the `-f/--file` flag. The same bug existed for the `-x/--line-regexp` flag as well, which we fix here. Fixes #1176
2019-01-26exit: tweak exit status logicAndrew Gallant
This changes how ripgrep emit exit status codes. In particular, any error that occurs while searching will now cause ripgrep to emit a `2` exit code, where as it previously would emit either a `0` or a `1` code based on whether it matched or not. That is, ripgrep would only emit a `2` exit code for a catastrophic error. This tweak includes additional logic that GNU grep adheres to, which seems like good sense. Namely, if -q/--quiet is given, and an error occurs and a match occurs, then ripgrep will emit a `0` exit code. Closes #1159
2019-01-26args: prevent panicking in 'rg -h | rg'Andrew Gallant
Previously, we relied on clap to handle printing either an error message, or --help/--version output, in addition to setting the exit status code. Unfortunately, for --help/--version output, clap was panicking if the write failed, which can happen in fairly common scenarios via a broken pipe error. e.g., `rg -h | head`. We fix this by using clap's "safe" API and doing the printing ourselves. We also set the exit code to `2` when an invalid command has been given. Fixes #1125 and partially addresses #1159
2019-01-26config: add --no-ignore-dot flagAndrew Gallant
This flag causes ripgrep to ignore `.ignore` files. Closes #1138
2019-01-26regex: make CRLF hack more robustAndrew Gallant
This commit improves the CRLF hack to be more robust. In particular, in addition to rewriting `$` as `(?:\r??$)`, we now strip `\r` from the end of a match if and only if the regex has an ending line anchor required for a match. This doesn't quite make the hack 100% correct, but should fix most use cases in practice. An example of a regex that will still be incorrect is `foo|bar$`, since the analysis isn't quite sophisticated enough to determine that a `\r` can be safely stripped from any match. Even if we fix that, regexes like `foo\r|bar$` still won't be handled correctly. Alas, more work on this front should really be focused on enabling this in the regex engine itself. The specific cause of this bug was that grep-searcher was sneakily stripping CRLF from matching lines when it really shouldn't have. We remove that code now, and instead rely on better match semantics provided at a lower level. Fixes #1095
2019-01-25searcher: always strip BOMAndrew Gallant
This fixes a bug where a BOM prefix was included. While this was somewhat intentional in order to have a faithful "UTF8 passthru" option, in practice, this causes problems such as breaking patterns like `^` in a really non-obvious way. The actual fix was to add a new API to encoding_rs_io, which this commit brings in. Fixes #1163
2019-01-23globset: permit ** to appear anywhereAndrew Gallant
Previously, `man gitignore` specified that `**` was invalid unless it was used in one of a few specific circumstances, i.e., `**`, `a/**`, `**/b` or `a/**/b`. That is, `**` always had to be surrounded by either a path separator or the beginning/end of the pattern. It turns out that git itself has treated `**` outside the above contexts as valid for quite a while, so there was an inconsistency between the spec `man gitignore` and the implementation, and it wasn't clear which was actually correct. @okdana filed a bug against git[1] and got this fixed. The spec was wrong, which has now been fixed [2] and updated[2]. This commit brings ripgrep in line with git and treats `**` outside of the above contexts as two consecutive `*` patterns. We deprecate the `InvalidRecursive` error since it is no longer used. Fixes #373, Fixes #1098 [1] - https://public-inbox.org/git/C16A9F17-0375-42F9-90A9-A92C9F3D8BBA@dana.is [2] - https://github.com/git/git/commit/627186d0206dcb219c43f8e6670b4487802a4921 [3] - https://git-scm.com/docs/gitignore
2019-01-23globset: fix repeated use of **Andrew Gallant
This fixes a bug where repeated use of ** didn't behave as it should. In particular, each use of `**` added a new requirement directory depth requirement. For example, something like `**/**/b` would match `foo/bar/b`, but it wouldn't match `foo/b` even though it should. In particular, `**` semantics demand "infinite" depth, so repeated uses of `**` should just coalesce as if only one was given. We do this coalescing in the parser. It's a little tricky because we treat `**/a`, `a/**` and `a/**/b` as distinct tokens with their own regex conversions. We also test the crap out of it. Fixes #1174
2019-01-23ignore: fix handling of **Andrew Gallant
When deciding whether to add the `**/` prefix or not, we should choose not to add it if the pattern is simply a bare `**`. Previously, we were only not adding it if it was `**/`, which is correct, but we also need to do it for `**` since `**` can already match anywhere. There's likely a more principled solution to this, but this works for now. Fixes #1173
2019-01-22printer: fix path handling in summarizerMika Dede
This commit fixes a bug where both of the following commands always reported an error: rg --files-with-matches foo file rg --files-without-match foo file In particular, the printer was erroneously respecting the `path` option even the the summary kind was `PathWithMatch` or `PathWithoutMatch`. The documented behavior is that those summary kinds always require a path, and thus, the `path` option has no effect. We fix this by correcting the case analysis. This also fixes a bug where the exit code for `--files-without-match` was not set correctly. We update the printer's `has_match` method to report the correct value. Fixes #1106, Closes #1130
2019-01-22grep-cli: support Brotli/Zstd decompressiondana
Fixes #1099
2019-01-22ripgrep: add --ignore-file-case-insensitiveDavid Torosyan
The --ignore-file-case-insensitive flag causes all .gitignore/.rgignore/.ignore files to have their globs matched without regard for case. Because this introduces a potentially significant performance regression, this is always disabled by default. Users that need case insensitive matching can enable it on a case by case basis. Closes #1164, Closes #1170
2019-01-19edition: move core ripgrep to Rust 2018Andrew Gallant
2018-09-25grep-regex: fix inner literal detectionAndrew Gallant
It seems the inner literal detector fails spectacularly in cases of concatenations that involve groups. The issue here is that if the prefix of a group inside a concatenation can match the empty string, then any literals generated to that point in the concatenation need to be cut such that they are never extended. The detector isn't really built to handle this case, so we just act conservative cut literals whenever we see a sub-group. This may make some regexes slower, but the inner literal detector already misses plenty of cases. Literal detection (including in the regex engine) is a key component that needs to be completely rethought at some point. Fixes #1064
2018-09-04ripgrep: add --pre-glob flagAndrew Gallant
The --pre-glob flag is like the --glob flag, except it applies to filtering files through the preprocessor instead of for search. This makes it possible to apply the preprocessor to only a small subset of files, which can greatly reduce the process overhead of using a preprocessor when searching large directories.
2018-08-21tests: touch up tests on WindowsAndrew Gallant
This fixes warnings and adds an additional invalid UTF-8 test that will run on Windows.
2018-08-20tests: re-tool integration testsAndrew Gallant
This basically rewrites every integration test. We reduce the amount of magic involved here in terms of which arguments are being passed to ripgrep processes. To make up for the boiler plate saved by the magic, we make the Dir (formerly WorkDir) type a bit nicer to use, along with a new TestCommand that wraps a std::process::Command. In exchange, we get tests that are easier to read and write. We also run every test with the `--pcre2` flag to make sure that works, when PCRE2 is available.
2018-08-20ripgrep: migrate to libripgrepAndrew Gallant
This commit does the work to delete the old `grep` crate and effectively rewrite most of ripgrep core to use the new libripgrep crates. The new `grep` crate is now a facade that collects the various crates that make up libripgrep. The most complex part of ripgrep core is now arguably the translation between command line parameters and the library options, which is ultimately where we want to be.
2018-07-29tests: reduce reliance on state in testsAndrew Gallant
This commit improves the integration test setup by running tests inside the system's temporary directory instead of within ripgrep's `target` directory. The motivation here is to attempt to reduce the effect of unanticipated state on ripgrep's integration tests, such as the presence of `.gitignore` files in ripgrep's checkout directory hierarchy (including parent directories). This doesn't remove all possible state. For example, there's no guarantee that the system's temporary directory isn't itself within a git repository. Moreover, there may still be other ignore rules in the directory tree that might impact test behavior. Fixing this seems somewhat difficult. Conceptually, it seems like ripgrep should run each test in its own `chroot`-like environment, but doing this in a non-annoying and portable way (including Windows) doesn't appear to be possible. Another approach to take here might be to teach ripgrep itself that a particular directory should be treated as root, and therefore, never look at anything outside that directory. This also seems complex to implement, but tractable. Let's see how this approach works for now. Fixes #448, #996
2018-07-29tests/style: 80 columns, dammitAndrew Gallant
2018-07-22ripgrep: when given no patterns, don't matchAndrew Gallant
Generally speaking, ripgrep prevents the case of not having any patterns via its arg parsing. However, it is possible for users to provide a file of patterns via the `-f` flag. If that file is empty, then ripgrep has nothing to search for and therefore should not ever produce any match. One way of fixing this might be to replace the absence of patterns with a pattern that can never match, but this still requires opening and searching through every file, which is quite a waste. Instead, we detect this case explicitly and quit early. Fixes #900
2018-07-22tests: be looser with gzip failureAndrew Gallant
Don't expect the exact error message. Instead, just ask that the error message exist and be non-empty. Fixes #903
2018-07-22ignore: only respect .gitignore in git reposAndrew Gallant
This commit fixes an interesting bug in the `ignore` crate where it would basically respect any `.gitignore` file anywhere (including global gitignores in `~/.config/git/ignore`), regardless of whether we were searching in a git repository or not. This commit rectifies that behavior to only respect gitignore rules when in a git repo. The key change here is to move the logic of whether to traverse parents into the directory matcher rather than putting the onus on the directory traverser. In particular, we now need to traverse parent directories in more cases than we previously did, since we need to determine whether we're in a git repository or not. Fixes #934
2018-07-21ripgrep: add --pre flagCharles Blake
The preprocessor flag accepts a command program and executes this program for every input file that is searched. Instead of searching the file directly, ripgrep will instead search the stdout contents of the program. Closes #978, Closes #981
2018-07-21ripgrep: add support for lz4 decompressionKalle Samuels
This uses the lz4 binary for decompression. Closes #898
2018-06-19ripgrep: use exit code 2 to indicate errorJon Surrell
Exit code 1 was shared to indicate both "no results" and "error." Use status code 2 to indicate errors, similar to grep's behavior. Fixes #948 PR #954
2018-04-23tests: fix tests on WindowsAndrew Gallant
A bug in the atty crate was previously masking a problem with the integration tests on Windows. Namely, the bug in atty resulted in atty::is(Stdin) returning true if we couldn't get the file name for the stdin stream. This in turn caused tests like `rg foo` to search the CWD, which was the intended behavior. However, once the atty bug was fixed, atty::is(Stdin) no longer returned true, causing `rg foo` searches to fail. On Unix-like systems, the atty behavior has always been correct. However, on Unix-like systems we have a decent way of detecting whether stdin is readable or not. If it isn't---which is the case in the integration tests---then we fall back to searching the CWD. On Windows however, we haven't yet implemented anything to detect whether stdin is readable or not, so we must always assume that it is. Therefore, we never get the "go ahead" to search the CWD and the tests fail. Most of the tests are written to search the CWD explicitly, but there were a few stragglers that don't. This isn't great, and we should try to figure out how to do better stdin detection on Windows.
2018-04-23output: remove --line-number-width flagAndrew Gallant
This commit does what no software project has ever done before: we've outright removed a flag with no possible way to recapture its functionality. This flag presents numerous problems in that it never really worked well in the first place, and completely falls over when ripgrep uses the --no-heading output format. Well meaning users want ripgrep to fix this by getting into the alignment business by buffering all output, but that is a line that I refuse to cross. Fixes #795
2018-04-23output: add --no-column flagAndrew Gallant
This disables columns in the output if they were otherwise enabled. Fixes #880
2018-04-23ignore: support .git directory OR fileAndrew Gallant
This improves support for submodules, which seem to use a '.git' file instead of a '.git' directory to indicate a worktree. Fixes #893
2018-03-13grep: upgrade to regex-syntax 0.5Andrew Gallant
This update brings with it many bug fixes: * Better error messages are printed overall. We also include explicit call out for unsupported features like backreferences and look-around. * Regexes like `\s*{` no longer emit incomprehensible errors. * Unicode escape sequences, such as `\u{..}` are now supported. For the most part, this upgrade was done in a straight-forward way. We resist the urge to refactor the `grep` crate, in anticipation of it being rewritten anyway. Note that we removed the `--fixed-strings` suggestion whenever a regex syntax error occurs. In practice, I've found that it results in a lot of false positives, and I believe that its use is not as paramount now that regex parse errors are much more readable. Closes #268, Closes #395, Closes #702, Closes #853
2018-03-10output: add --stats flagBalaji Sivaraman
This commit provides basic support for a --stats flag, which will print various aggregate statistics about a search after all of the results have been printed. This is mostly intended to support a similar feature found in the Silver Searcher. Note though that we don't emit the total bytes searched; this is a first pass at an implementation and we can improve upon it later. Closes #411, Closes #799
2018-03-10args: treat --count --only-matching as --count-matchesAndrew Gallant
Namely, when ripgrep is asked to count things and is also asked to print every match on its own line, then we should just automatically count the matches and not the lines. This is a departure from how GNU grep behaves, but there is a compelling argument to be made that GNU grep's behavior doesn't make a lot of sense. Note that since this changes the behavior of combining two existing flags, this is a breaking change.
2018-03-10search: add a --count-matches flagBalaji Sivaraman
This commit introduces a new flag, --count-matches, which will cause ripgrep to report a total count of all matches instead of a count of total lines matched. Closes #566, Closes #814
2018-03-10search: add -b/--byte-offset flagBalaji Sivaraman
This commit adds support for printing 0-based byte offset before each line. We handle corner cases such as `-o/--only-matching` and `-C/--context` as well. Closes #812
2018-03-10ignore: support backslash escapingBrian Malehorn
Use the new `Globset::backslash_escape` knob to conform to git behavior: `\` will escape the following character. For example, the pattern `\*` will match a file literally named `*`. Also tweak a test in ripgrep that was relying on this incorrect behavior. Closes #526, Closes #811
2018-02-20termcolor: add underline supportBalaji Sivaraman
This commit adds underline support to the termcolor crate, and exposes it through ripgrep. Fixes #798
2018-02-14ignore: fix improper hidden filteringAndrew Gallant
This commit fixes a bug where `rg --hidden .` would behave differently with respect to ignore filtering than `rg --hidden ./`. In particular, this was due to a bug where the directory name `.` caused the leading `.` in a hidden directory to get stripped, which in turn caused the ignore rules to fail. Fixes #807
2018-02-06argv: update clap to 2.29.4Andrew Gallant
We use the new AppSettings::AllArgsOverrideSelf to permit all flags to be specified multiple times. This removes the need for our previous work-around where we would enable `multiple` for every flag and then just extract the last value when consuming clap's matches. We also add a couple regression tests that ensure repeated switches and flags work as expected.
2018-02-04config: add persistent configurationAndrew Gallant
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
2018-01-30search: add support for searching compressed filesBalaji Sivaraman
This commit adds opt-in support for searching compressed files during recursive search. This behavior is only enabled when the `-z/--search-zip` flag is passed to ripgrep. When enabled, a limited set of common compression formats are recognized via file extension, and a new process is spawned to perform the decompression. ripgrep then searches the stdout of that spawned process. Closes #539