Skip to content
Myr

regression.rs

This file

Path

tests/regression.rs

1,744 lines · 53.5 KiB · Rust

Last changed by

ignore: support `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` for `core.excludesFile`Amaan Qureshibefore adoption241b87b

History of this file

Take it

1use crate::hay::SHERLOCK;2use crate::util::{Dir, TestCommand, sort_lines};34// See: https://github.com/BurntSushi/ripgrep/issues/165rgtest!(r16, |dir: Dir, mut cmd: TestCommand| {6    dir.create_dir(".git");7    dir.create(".gitignore", "ghi/");8    dir.create_dir("ghi");9    dir.create_dir("def/ghi");10    dir.create("ghi/toplevel.txt", "xyz");11    dir.create("def/ghi/subdir.txt", "xyz");1213    cmd.arg("xyz").assert_err();14});1516// See: https://github.com/BurntSushi/ripgrep/issues/2517rgtest!(r25, |dir: Dir, mut cmd: TestCommand| {18    dir.create_dir(".git");19    dir.create(".gitignore", "/llvm/");20    dir.create_dir("src/llvm");21    dir.create("src/llvm/foo", "test");2223    cmd.arg("test");24    eqnice!("src/llvm/foo:test\n", cmd.stdout());2526    cmd.current_dir("src");27    eqnice!("llvm/foo:test\n", cmd.stdout());28});2930// See: https://github.com/BurntSushi/ripgrep/issues/3031rgtest!(r30, |dir: Dir, mut cmd: TestCommand| {32    dir.create(".gitignore", "vendor/**\n!vendor/manifest");33    dir.create_dir("vendor");34    dir.create("vendor/manifest", "test");3536    eqnice!("vendor/manifest:test\n", cmd.arg("test").stdout());37});3839// See: https://github.com/BurntSushi/ripgrep/issues/4940rgtest!(r49, |dir: Dir, mut cmd: TestCommand| {41    dir.create(".gitignore", "foo/bar");42    dir.create_dir("test/foo/bar");43    dir.create("test/foo/bar/baz", "test");4445    cmd.arg("xyz").assert_err();46});4748// See: https://github.com/BurntSushi/ripgrep/issues/5049rgtest!(r50, |dir: Dir, mut cmd: TestCommand| {50    dir.create(".gitignore", "XXX/YYY/");51    dir.create_dir("abc/def/XXX/YYY");52    dir.create_dir("ghi/XXX/YYY");53    dir.create("abc/def/XXX/YYY/bar", "test");54    dir.create("ghi/XXX/YYY/bar", "test");5556    cmd.arg("xyz").assert_err();57});5859// See: https://github.com/BurntSushi/ripgrep/issues/6460rgtest!(r64, |dir: Dir, mut cmd: TestCommand| {61    dir.create_dir("dir");62    dir.create_dir("foo");63    dir.create("dir/abc", "");64    dir.create("foo/abc", "");6566    eqnice!("foo/abc\n", cmd.arg("--files").arg("foo").stdout());67});6869// See: https://github.com/BurntSushi/ripgrep/issues/6570rgtest!(r65, |dir: Dir, mut cmd: TestCommand| {71    dir.create_dir(".git");72    dir.create(".gitignore", "a/");73    dir.create_dir("a");74    dir.create("a/foo", "xyz");75    dir.create("a/bar", "xyz");7677    cmd.arg("xyz").assert_err();78});7980// See: https://github.com/BurntSushi/ripgrep/issues/6781rgtest!(r67, |dir: Dir, mut cmd: TestCommand| {82    dir.create_dir(".git");83    dir.create(".gitignore", "/*\n!/dir");84    dir.create_dir("dir");85    dir.create_dir("foo");86    dir.create("foo/bar", "test");87    dir.create("dir/bar", "test");8889    eqnice!("dir/bar:test\n", cmd.arg("test").stdout());90});9192// See: https://github.com/BurntSushi/ripgrep/issues/8793rgtest!(r87, |dir: Dir, mut cmd: TestCommand| {94    dir.create_dir(".git");95    dir.create(".gitignore", "foo\n**no-vcs**");96    dir.create("foo", "test");9798    cmd.arg("test").assert_err();99});100101// See: https://github.com/BurntSushi/ripgrep/issues/90102rgtest!(r90, |dir: Dir, mut cmd: TestCommand| {103    dir.create_dir(".git");104    dir.create(".gitignore", "!.foo");105    dir.create(".foo", "test");106107    eqnice!(".foo:test\n", cmd.arg("test").stdout());108});109110// See: https://github.com/BurntSushi/ripgrep/issues/93111rgtest!(r93, |dir: Dir, mut cmd: TestCommand| {112    dir.create("foo", "192.168.1.1");113114    eqnice!("foo:192.168.1.1\n", cmd.arg(r"(\d{1,3}\.){3}\d{1,3}").stdout());115});116117// See: https://github.com/BurntSushi/ripgrep/issues/99118rgtest!(r99, |dir: Dir, mut cmd: TestCommand| {119    dir.create("foo1", "test");120    dir.create("foo2", "zzz");121    dir.create("bar", "test");122123    eqnice!(124        sort_lines("bar\ntest\n\nfoo1\ntest\n"),125        sort_lines(&cmd.arg("-j1").arg("--heading").arg("test").stdout())126    );127});128129// See: https://github.com/BurntSushi/ripgrep/issues/105130rgtest!(r105_part1, |dir: Dir, mut cmd: TestCommand| {131    dir.create("foo", "zztest");132133    eqnice!("foo:1:3:zztest\n", cmd.arg("--vimgrep").arg("test").stdout());134});135136// See: https://github.com/BurntSushi/ripgrep/issues/105137rgtest!(r105_part2, |dir: Dir, mut cmd: TestCommand| {138    dir.create("foo", "zztest");139140    eqnice!("foo:1:3:zztest\n", cmd.arg("--column").arg("test").stdout());141});142143// See: https://github.com/BurntSushi/ripgrep/issues/127144rgtest!(r127, |dir: Dir, mut cmd: TestCommand| {145    // Set up a directory hierarchy like this:146    //147    // .gitignore148    // foo/149    //   sherlock150    //   watson151    //152    // Where `.gitignore` contains `foo/sherlock`.153    //154    // ripgrep should ignore 'foo/sherlock' giving us results only from155    // 'foo/watson' but on Windows ripgrep will include both 'foo/sherlock' and156    // 'foo/watson' in the search results.157    dir.create_dir(".git");158    dir.create(".gitignore", "foo/sherlock\n");159    dir.create_dir("foo");160    dir.create("foo/sherlock", SHERLOCK);161    dir.create("foo/watson", SHERLOCK);162163    let expected = "\164foo/watson:For the Doctor Watsons of this world, as opposed to the Sherlock165foo/watson:be, to a very large extent, the result of luck. Sherlock Holmes166";167    assert_eq!(expected, cmd.arg("Sherlock").stdout());168});169170// See: https://github.com/BurntSushi/ripgrep/issues/128171rgtest!(r128, |dir: Dir, mut cmd: TestCommand| {172    dir.create_bytes("foo", b"01234567\x0b\n\x0b\n\x0b\n\x0b\nx");173174    eqnice!("foo:5:x\n", cmd.arg("-n").arg("x").stdout());175});176177// See: https://github.com/BurntSushi/ripgrep/issues/131178//179// TODO(burntsushi): Darwin doesn't like this test for some reason. Probably180// due to the weird file path.181#[cfg(not(target_os = "macos"))]182rgtest!(r131, |dir: Dir, mut cmd: TestCommand| {183    dir.create_dir(".git");184    dir.create(".gitignore", "TopÑapa");185    dir.create("TopÑapa", "test");186187    cmd.arg("test").assert_err();188});189190// See: https://github.com/BurntSushi/ripgrep/issues/137191//192// TODO(burntsushi): Figure out how to make this test work on Windows. Right193// now it gives "access denied" errors when trying to create a file symlink.194// For now, disable test on Windows.195#[cfg(not(windows))]196rgtest!(r137, |dir: Dir, mut cmd: TestCommand| {197    dir.create("sherlock", SHERLOCK);198    dir.link_file("sherlock", "sym1");199    dir.link_file("sherlock", "sym2");200201    let expected = "\202./sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock203./sherlock:be, to a very large extent, the result of luck. Sherlock Holmes204sym1:For the Doctor Watsons of this world, as opposed to the Sherlock205sym1:be, to a very large extent, the result of luck. Sherlock Holmes206sym2:For the Doctor Watsons of this world, as opposed to the Sherlock207sym2:be, to a very large extent, the result of luck. Sherlock Holmes208";209    cmd.arg("-j1").arg("Sherlock").arg("./").arg("sym1").arg("sym2");210    eqnice!(expected, cmd.stdout());211});212213// See: https://github.com/BurntSushi/ripgrep/issues/156214rgtest!(r156, |dir: Dir, mut cmd: TestCommand| {215    let expected = r#"#parse('widgets/foo_bar_macros.vm')216#parse ( 'widgets/mobile/foo_bar_macros.vm' )217#parse ("widgets/foobarhiddenformfields.vm")218#parse ( "widgets/foo_bar_legal.vm" )219#include( 'widgets/foo_bar_tips.vm' )220#include('widgets/mobile/foo_bar_macros.vm')221#include ("widgets/mobile/foo_bar_resetpw.vm")222#parse('widgets/foo-bar-macros.vm')223#parse ( 'widgets/mobile/foo-bar-macros.vm' )224#parse ("widgets/foo-bar-hiddenformfields.vm")225#parse ( "widgets/foo-bar-legal.vm" )226#include( 'widgets/foo-bar-tips.vm' )227#include('widgets/mobile/foo-bar-macros.vm')228#include ("widgets/mobile/foo-bar-resetpw.vm")229"#;230    dir.create("testcase.txt", expected);231232    cmd.arg("-N");233    cmd.arg(r#"#(?:parse|include)\s*\(\s*(?:"|')[./A-Za-z_-]+(?:"|')"#);234    cmd.arg("testcase.txt");235    eqnice!(expected, cmd.stdout());236});237238// See: https://github.com/BurntSushi/ripgrep/issues/184239rgtest!(r184, |dir: Dir, mut cmd: TestCommand| {240    dir.create(".gitignore", ".*");241    dir.create_dir("foo/bar");242    dir.create("foo/bar/baz", "test");243244    cmd.arg("test");245    eqnice!("foo/bar/baz:test\n", cmd.stdout());246247    cmd.current_dir("./foo/bar");248    eqnice!("baz:test\n", cmd.stdout());249});250251// See: https://github.com/BurntSushi/ripgrep/issues/199252rgtest!(r199, |dir: Dir, mut cmd: TestCommand| {253    dir.create("foo", "tEsT");254255    eqnice!("foo:tEsT\n", cmd.arg("--smart-case").arg(r"\btest\b").stdout());256});257258// See: https://github.com/BurntSushi/ripgrep/issues/206259rgtest!(r206, |dir: Dir, mut cmd: TestCommand| {260    dir.create_dir("foo");261    dir.create("foo/bar.txt", "test");262263    cmd.arg("test").arg("-g").arg("*.txt");264    eqnice!("foo/bar.txt:test\n", cmd.stdout());265});266267// See: https://github.com/BurntSushi/ripgrep/issues/210268#[cfg(unix)]269rgtest!(r210, |dir: Dir, mut cmd: TestCommand| {270    use std::ffi::OsStr;271    use std::os::unix::ffi::OsStrExt;272273    let badutf8 = OsStr::from_bytes(&b"foo\xffbar"[..]);274275    // APFS does not support creating files with invalid UTF-8 bytes.276    // https://github.com/BurntSushi/ripgrep/issues/559277    if dir.try_create(badutf8, "test").is_ok() {278        cmd.arg("-H").arg("test").arg(badutf8);279        assert_eq!(b"foo\xffbar:test\n".to_vec(), cmd.output().stdout);280    }281});282283// See: https://github.com/BurntSushi/ripgrep/issues/228284rgtest!(r228, |dir: Dir, mut cmd: TestCommand| {285    dir.create_dir("foo");286287    cmd.arg("--ignore-file").arg("foo").arg("test").assert_err();288});289290// See: https://github.com/BurntSushi/ripgrep/issues/229291rgtest!(r229, |dir: Dir, mut cmd: TestCommand| {292    dir.create("foo", "economie");293294    cmd.arg("-S").arg("[E]conomie").assert_err();295});296297// See: https://github.com/BurntSushi/ripgrep/issues/251298rgtest!(r251, |dir: Dir, mut cmd: TestCommand| {299    dir.create("foo", "привет\nПривет\nПрИвЕт");300301    let expected = "foo:привет\nfoo:Привет\nfoo:ПрИвЕт\n";302    eqnice!(expected, cmd.arg("-i").arg("привет").stdout());303});304305// See: https://github.com/BurntSushi/ripgrep/issues/256306#[cfg(not(windows))]307rgtest!(r256, |dir: Dir, mut cmd: TestCommand| {308    dir.create_dir("bar");309    dir.create("bar/baz", "test");310    dir.link_dir("bar", "foo");311312    eqnice!("foo/baz:test\n", cmd.arg("test").arg("foo").stdout());313});314315// See: https://github.com/BurntSushi/ripgrep/issues/256316#[cfg(not(windows))]317rgtest!(r256_j1, |dir: Dir, mut cmd: TestCommand| {318    dir.create_dir("bar");319    dir.create("bar/baz", "test");320    dir.link_dir("bar", "foo");321322    eqnice!("foo/baz:test\n", cmd.arg("-j1").arg("test").arg("foo").stdout());323});324325// See: https://github.com/BurntSushi/ripgrep/issues/270326rgtest!(r270, |dir: Dir, mut cmd: TestCommand| {327    dir.create("foo", "-test");328329    cmd.arg("-e").arg("-test");330    eqnice!("foo:-test\n", cmd.stdout());331});332333// See: https://github.com/BurntSushi/ripgrep/issues/279334rgtest!(r279, |dir: Dir, mut cmd: TestCommand| {335    dir.create("foo", "test");336337    eqnice!("", cmd.arg("-q").arg("test").stdout());338});339340// See: https://github.com/BurntSushi/ripgrep/issues/391341rgtest!(r391, |dir: Dir, mut cmd: TestCommand| {342    dir.create_dir(".git");343    dir.create("lock", "");344    dir.create("bar.py", "");345    dir.create(".git/packed-refs", "");346    dir.create(".git/description", "");347348    cmd.args(&[349        "--no-ignore",350        "--hidden",351        "--follow",352        "--files",353        "--glob",354        "!{.git,node_modules,plugged}/**",355        "--glob",356        "*.{js,json,php,md,styl,scss,sass,pug,html,config,py,cpp,c,go,hs}",357    ]);358    eqnice!("bar.py\n", cmd.stdout());359});360361// See: https://github.com/BurntSushi/ripgrep/issues/405362rgtest!(r405, |dir: Dir, mut cmd: TestCommand| {363    dir.create_dir("foo/bar");364    dir.create_dir("bar/foo");365    dir.create("foo/bar/file1.txt", "test");366    dir.create("bar/foo/file2.txt", "test");367368    cmd.arg("-g").arg("!/foo/**").arg("test");369    eqnice!("bar/foo/file2.txt:test\n", cmd.stdout());370});371372// See: https://github.com/BurntSushi/ripgrep/issues/428373#[cfg(not(windows))]374rgtest!(r428_color_context_path, |dir: Dir, mut cmd: TestCommand| {375    dir.create("sherlock", "foo\nbar");376    cmd.args(&[377        "-A1",378        "-H",379        "--no-heading",380        "-N",381        "--colors=match:none",382        "--color=always",383        "--hyperlink-format=",384        "foo",385    ]);386387    let expected = format!(388        "{colored_path}:foo\n{colored_path}-bar\n",389        colored_path =390            "\x1b\x5b\x30\x6d\x1b\x5b\x33\x35\x6dsherlock\x1b\x5b\x30\x6d"391    );392    eqnice!(expected, cmd.stdout());393});394395// See: https://github.com/BurntSushi/ripgrep/issues/428396rgtest!(r428_unrecognized_style, |dir: Dir, mut cmd: TestCommand| {397    dir.create("file.txt", "Sherlock");398399    cmd.arg("--colors=match:style:").arg("Sherlock");400    cmd.assert_err();401402    let output = cmd.raw_output();403    let stderr = String::from_utf8_lossy(&output.stderr);404    let expected = "\405rg: error parsing flag --colors: \406unrecognized style attribute ''. Choose from: nobold, bold, nointense, \407intense, nounderline, underline, noitalic, italic.408";409    eqnice!(expected, stderr);410});411412// See: https://github.com/BurntSushi/ripgrep/issues/451413rgtest!(r451_only_matching_as_in_issue, |dir: Dir, mut cmd: TestCommand| {414    dir.create("digits.txt", "1 2 3\n");415    cmd.arg("--only-matching").arg(r"[0-9]+").arg("digits.txt");416417    let expected = "\418141924203421";422    eqnice!(expected, cmd.stdout());423});424425// See: https://github.com/BurntSushi/ripgrep/issues/451426rgtest!(r451_only_matching, |dir: Dir, mut cmd: TestCommand| {427    dir.create("digits.txt", "1 2 3\n123\n");428    cmd.args(&["--only-matching", "--column", r"[0-9]", "digits.txt"]);429430    let expected = "\4311:1:14321:3:24331:5:34342:1:14352:2:24362:3:3437";438    eqnice!(expected, cmd.stdout());439});440441// See: https://github.com/BurntSushi/ripgrep/issues/483442rgtest!(r483_matching_no_stdout, |dir: Dir, mut cmd: TestCommand| {443    dir.create("file.py", "");444    cmd.arg("--quiet").arg("--files").arg("--glob").arg("*.py");445    eqnice!("", cmd.stdout());446});447448// See: https://github.com/BurntSushi/ripgrep/issues/483449rgtest!(r483_non_matching_exit_code, |dir: Dir, mut cmd: TestCommand| {450    dir.create("file.rs", "");451    cmd.arg("--quiet").arg("--files").arg("--glob").arg("*.py");452    cmd.assert_err();453});454455// See: https://github.com/BurntSushi/ripgrep/issues/493456rgtest!(r493, |dir: Dir, mut cmd: TestCommand| {457    dir.create("input.txt", "peshwaship 're seminomata");458459    cmd.arg("-o").arg(r"\b 're \b").arg("input.txt");460    assert_eq!(" 're \n", cmd.stdout());461});462463// See: https://github.com/BurntSushi/ripgrep/issues/506464rgtest!(r506_word_not_parenthesized, |dir: Dir, mut cmd: TestCommand| {465    dir.create("wb.txt", "min minimum amin\nmax maximum amax");466    cmd.arg("-w").arg("-o").arg("min|max").arg("wb.txt");467    eqnice!("min\nmax\n", cmd.stdout());468});469470// See: https://github.com/BurntSushi/ripgrep/issues/553471rgtest!(r553_switch, |dir: Dir, mut cmd: TestCommand| {472    dir.create("sherlock", SHERLOCK);473474    let expected = "\475sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock476sherlock:be, to a very large extent, the result of luck. Sherlock Holmes477";478    cmd.arg("-i").arg("sherlock");479    eqnice!(expected, cmd.stdout());480481    // Repeat the `i` flag to make sure everything still works.482    eqnice!(expected, cmd.arg("-i").stdout());483});484485rgtest!(r553_flag, |dir: Dir, mut cmd: TestCommand| {486    dir.create("sherlock", SHERLOCK);487488    let expected = "\489For the Doctor Watsons of this world, as opposed to the Sherlock490Holmeses, success in the province of detective work must always491--492but Doctor Watson has to have it taken out for him and dusted,493and exhibited clearly, with a label attached.494";495    cmd.arg("-C").arg("1").arg(r"world|attached").arg("sherlock");496    eqnice!(expected, cmd.stdout());497498    let expected = "\499For the Doctor Watsons of this world, as opposed to the Sherlock500and exhibited clearly, with a label attached.501";502    eqnice!(expected, cmd.arg("-C").arg("0").stdout());503});504505// See: https://github.com/BurntSushi/ripgrep/issues/568506rgtest!(r568_leading_hyphen_option_args, |dir: Dir, mut cmd: TestCommand| {507    dir.create("file", "foo bar -baz\n");508    cmd.arg("-e-baz").arg("-e").arg("-baz").arg("file");509    eqnice!("foo bar -baz\n", cmd.stdout());510511    let mut cmd = dir.command();512    cmd.arg("-rni").arg("bar").arg("file");513    eqnice!("foo ni -baz\n", cmd.stdout());514515    let mut cmd = dir.command();516    cmd.arg("-r").arg("-n").arg("-i").arg("bar").arg("file");517    eqnice!("foo -n -baz\n", cmd.stdout());518});519520// See: https://github.com/BurntSushi/ripgrep/issues/599521//522// This test used to check that we emitted color escape sequences even for523// empty matches, but with the addition of the JSON output format, clients no524// longer need to rely on escape sequences to parse matches. Therefore, we no525// longer emit useless escape sequences.526rgtest!(r599, |dir: Dir, mut cmd: TestCommand| {527    dir.create("input.txt", "\n\ntest\n");528    cmd.args(&[529        "--color",530        "ansi",531        "--colors",532        "path:none",533        "--colors",534        "line:none",535        "--colors",536        "match:fg:red",537        "--colors",538        "match:style:nobold",539        "--line-number",540        r"^$",541        "input.txt",542    ]);543544    let expected = "\5451:5462:547";548    eqnice_repr!(expected, cmd.stdout());549});550551// See: https://github.com/BurntSushi/ripgrep/issues/693552rgtest!(r693_context_in_contextless_mode, |dir: Dir, mut cmd: TestCommand| {553    dir.create("foo", "xyz\n");554    dir.create("bar", "xyz\n");555556    cmd.arg("-C1").arg("-c").arg("--sort-files").arg("xyz");557    eqnice!("bar:1\nfoo:1\n", cmd.stdout());558});559560// See: https://github.com/BurntSushi/ripgrep/issues/807561rgtest!(r807, |dir: Dir, mut cmd: TestCommand| {562    dir.create_dir(".git");563    dir.create(".gitignore", ".a/b");564    dir.create_dir(".a/b");565    dir.create_dir(".a/c");566    dir.create(".a/b/file", "test");567    dir.create(".a/c/file", "test");568569    eqnice!(".a/c/file:test\n", cmd.arg("--hidden").arg("test").stdout());570});571572// See: https://github.com/BurntSushi/ripgrep/pull/2711573//574// Note that this isn't a regression test. In particular, this didn't fail575// with ripgrep 14.1.1. I couldn't figure out how to turn what the OP gave me576// into a failing test.577rgtest!(r2711, |dir: Dir, _cmd: TestCommand| {578    dir.create_dir("a/b");579    dir.create("a/.ignore", ".foo");580    dir.create("a/b/.foo", "");581582    {583        let mut cmd = dir.command();584        eqnice!("a/.ignore\n", cmd.arg("--hidden").arg("--files").stdout());585    }586    {587        let mut cmd = dir.command();588        eqnice!(589            "./a/.ignore\n",590            cmd.arg("--hidden").arg("--files").arg("./").stdout()591        );592    }593594    {595        let mut cmd = dir.command();596        eqnice!(597            "a/.ignore\n",598            cmd.arg("--hidden").arg("--files").arg("a").stdout()599        );600    }601    {602        let mut cmd = dir.command();603        cmd.arg("--hidden").arg("--files").arg("a/b").assert_err();604    }605    {606        let mut cmd = dir.command();607        eqnice!(608            "./a/.ignore\n",609            cmd.arg("--hidden").arg("--files").arg("./a").stdout()610        );611    }612613    {614        let mut cmd = dir.command();615        cmd.current_dir("a");616        eqnice!(".ignore\n", cmd.arg("--hidden").arg("--files").stdout());617    }618    {619        let mut cmd = dir.command();620        cmd.current_dir("a/b");621        cmd.arg("--hidden").arg("--files").assert_err();622    }623    {624        let mut cmd = dir.command();625        cmd.current_dir("./a");626        eqnice!(".ignore\n", cmd.arg("--hidden").arg("--files").stdout());627    }628});629630// See: https://github.com/BurntSushi/ripgrep/issues/829631rgtest!(r829_original, |dir: Dir, _cmd: TestCommand| {632    dir.create_dir("a/b");633    dir.create(".ignore", "/a/b");634    dir.create("a/b/test.txt", "Sample text");635636    {637        let mut cmd = dir.command();638        cmd.args(&["Sample"]).assert_err();639    }640    {641        let mut cmd = dir.command();642        cmd.args(&["Sample", "a"]).assert_err();643    }644    {645        let mut cmd = dir.command();646        cmd.current_dir("a");647        cmd.args(&["Sample"]).assert_err();648    }649});650651// See: https://github.com/BurntSushi/ripgrep/issues/2731652rgtest!(r829_2731, |dir: Dir, _cmd: TestCommand| {653    dir.create_dir("some_dir/build");654    dir.create("some_dir/build/foo", "string");655    dir.create(".ignore", "build/\n!/some_dir/build/");656657    {658        let mut cmd = dir.command();659        eqnice!("some_dir/build/foo\n", cmd.arg("-l").arg("string").stdout());660    }661    {662        let mut cmd = dir.command();663        eqnice!(664            "some_dir/build/foo\n",665            cmd.arg("-l").arg("string").arg("some_dir").stdout()666        );667    }668    {669        let mut cmd = dir.command();670        eqnice!(671            "./some_dir/build/foo\n",672            cmd.arg("-l").arg("string").arg("./some_dir").stdout()673        );674    }675    {676        let mut cmd = dir.command();677        eqnice!(678            "some_dir/build/foo\n",679            cmd.arg("-l").arg("string").arg("some_dir/build").stdout()680        );681    }682    {683        let mut cmd = dir.command();684        eqnice!(685            "./some_dir/build/foo\n",686            cmd.arg("-l").arg("string").arg("./some_dir/build").stdout()687        );688    }689});690691// See: https://github.com/BurntSushi/ripgrep/issues/2747692rgtest!(r829_2747, |dir: Dir, _cmd: TestCommand| {693    dir.create_dir("a/c/b");694    dir.create_dir("a/src/f/b");695    dir.create("a/c/b/foo", "");696    dir.create("a/src/f/b/foo", "");697    dir.create(".ignore", "/a/*/b");698699    {700        let mut cmd = dir.command();701        eqnice!("a/src/f/b/foo\n", cmd.arg("--files").stdout());702    }703    {704        let mut cmd = dir.command();705        eqnice!("a/src/f/b/foo\n", cmd.arg("--files").arg("a/src").stdout());706    }707    {708        let mut cmd = dir.command();709        cmd.current_dir("a/src");710        eqnice!("f/b/foo\n", cmd.arg("--files").stdout());711    }712});713714// See: https://github.com/BurntSushi/ripgrep/issues/2778715rgtest!(r829_2778, |dir: Dir, _cmd: TestCommand| {716    dir.create_dir("parent/subdir");717    dir.create(".ignore", "/parent/*.txt");718    dir.create("parent/ignore-me.txt", "");719    dir.create("parent/subdir/dont-ignore-me.txt", "");720721    {722        let mut cmd = dir.command();723        eqnice!(724            "parent/subdir/dont-ignore-me.txt\n",725            cmd.arg("--files").stdout()726        );727    }728    {729        let mut cmd = dir.command();730        cmd.current_dir("parent");731        eqnice!("subdir/dont-ignore-me.txt\n", cmd.arg("--files").stdout());732    }733});734735// See: https://github.com/BurntSushi/ripgrep/issues/2836736rgtest!(r829_2836, |dir: Dir, _cmd: TestCommand| {737    dir.create_dir("testdir/sub/sub2");738    dir.create(".ignore", "/testdir/sub/sub2/\n");739    dir.create("testdir/sub/sub2/foo", "");740741    {742        let mut cmd = dir.command();743        cmd.arg("--files").assert_err();744    }745    {746        let mut cmd = dir.command();747        cmd.current_dir("testdir");748        cmd.arg("--files").assert_err();749    }750});751752// See: https://github.com/BurntSushi/ripgrep/pull/2933753rgtest!(r829_2933, |dir: Dir, mut cmd: TestCommand| {754    dir.create_dir("testdir/sub/sub2");755    dir.create(".ignore", "/testdir/sub/sub2/");756    dir.create("testdir/sub/sub2/testfile", "needle");757758    let args = &["--files-with-matches", "needle"];759    cmd.current_dir("testdir");760    cmd.args(args).assert_err();761});762763// See: https://github.com/BurntSushi/ripgrep/issues/900764rgtest!(r900, |dir: Dir, mut cmd: TestCommand| {765    dir.create("sherlock", SHERLOCK);766    dir.create("pat", "");767768    cmd.arg("-fpat").arg("sherlock").assert_err();769});770771// See: https://github.com/BurntSushi/ripgrep/issues/1064772rgtest!(r1064, |dir: Dir, mut cmd: TestCommand| {773    dir.create("input", "abc");774    eqnice!("input:abc\n", cmd.arg("a(.*c)").stdout());775});776777// See: https://github.com/BurntSushi/ripgrep/issues/1174778rgtest!(r1098, |dir: Dir, mut cmd: TestCommand| {779    dir.create_dir(".git");780    dir.create(".gitignore", "a**b");781    dir.create("afoob", "test");782    cmd.arg("test").assert_err();783});784785// See: https://github.com/BurntSushi/ripgrep/issues/1130786rgtest!(r1130, |dir: Dir, mut cmd: TestCommand| {787    dir.create("foo", "test");788    eqnice!(789        "foo\n",790        cmd.arg("--files-with-matches").arg("test").arg("foo").stdout()791    );792793    let mut cmd = dir.command();794    eqnice!(795        "foo\n",796        cmd.arg("--files-without-match").arg("nada").arg("foo").stdout()797    );798});799800// See: https://github.com/BurntSushi/ripgrep/issues/1159801rgtest!(r1159_invalid_flag, |_: Dir, mut cmd: TestCommand| {802    cmd.arg("--wat").assert_exit_code(2);803});804805// See: https://github.com/BurntSushi/ripgrep/issues/1159806rgtest!(r1159_exit_status, |dir: Dir, _: TestCommand| {807    dir.create("foo", "test");808809    // search with a match gets 0 exit status.810    let mut cmd = dir.command();811    cmd.arg("test").assert_exit_code(0);812813    // search with --quiet and a match gets 0 exit status.814    let mut cmd = dir.command();815    cmd.arg("-q").arg("test").assert_exit_code(0);816817    // search with a match and an error gets 2 exit status.818    let mut cmd = dir.command();819    cmd.arg("test").arg("no-file").assert_exit_code(2);820821    // search with a match in --quiet mode and an error gets 0 exit status.822    let mut cmd = dir.command();823    cmd.arg("-q").arg("test").arg("foo").arg("no-file").assert_exit_code(0);824825    // search with no match gets 1 exit status.826    let mut cmd = dir.command();827    cmd.arg("nada").assert_exit_code(1);828829    // search with --quiet and no match gets 1 exit status.830    let mut cmd = dir.command();831    cmd.arg("-q").arg("nada").assert_exit_code(1);832833    // search with no match and an error gets 2 exit status.834    let mut cmd = dir.command();835    cmd.arg("nada").arg("no-file").assert_exit_code(2);836837    // search with no match in --quiet mode and an error gets 2 exit status.838    let mut cmd = dir.command();839    cmd.arg("-q").arg("nada").arg("foo").arg("no-file").assert_exit_code(2);840});841842// See: https://github.com/BurntSushi/ripgrep/issues/1163843rgtest!(r1163, |dir: Dir, mut cmd: TestCommand| {844    dir.create("bom.txt", "\u{FEFF}test123\ntest123");845    eqnice!(846        "bom.txt:test123\nbom.txt:test123\n",847        cmd.arg("^test123").stdout()848    );849});850851// See: https://github.com/BurntSushi/ripgrep/issues/1164852rgtest!(r1164, |dir: Dir, mut cmd: TestCommand| {853    dir.create_dir(".git");854    dir.create(".gitignore", "myfile");855    dir.create("MYFILE", "test");856857    cmd.arg("--ignore-file-case-insensitive").arg("test").assert_err();858    eqnice!(859        "MYFILE:test\n",860        cmd.arg("--no-ignore-file-case-insensitive").stdout()861    );862});863864// See: https://github.com/BurntSushi/ripgrep/issues/1173865rgtest!(r1173, |dir: Dir, mut cmd: TestCommand| {866    dir.create_dir(".git");867    dir.create(".gitignore", "**");868    dir.create("foo", "test");869    cmd.arg("test").assert_err();870});871872// See: https://github.com/BurntSushi/ripgrep/issues/1174873rgtest!(r1174, |dir: Dir, mut cmd: TestCommand| {874    dir.create_dir(".git");875    dir.create(".gitignore", "**/**/*");876    dir.create_dir("a");877    dir.create("a/foo", "test");878    cmd.arg("test").assert_err();879});880881// See: https://github.com/BurntSushi/ripgrep/issues/1176882rgtest!(r1176_literal_file, |dir: Dir, mut cmd: TestCommand| {883    dir.create("patterns", "foo(bar\n");884    dir.create("test", "foo(bar");885886    eqnice!(887        "foo(bar\n",888        cmd.arg("-F").arg("-f").arg("patterns").arg("test").stdout()889    );890});891892// See: https://github.com/BurntSushi/ripgrep/issues/1176893rgtest!(r1176_line_regex, |dir: Dir, mut cmd: TestCommand| {894    dir.create("patterns", "foo\n");895    dir.create("test", "foobar\nfoo\nbarfoo\n");896897    eqnice!(898        "foo\n",899        cmd.arg("-x").arg("-f").arg("patterns").arg("test").stdout()900    );901});902903// See: https://github.com/BurntSushi/ripgrep/issues/1203904rgtest!(r1203_reverse_suffix_literal, |dir: Dir, _: TestCommand| {905    dir.create("test", "153.230000\n");906907    let mut cmd = dir.command();908    eqnice!("153.230000\n", cmd.arg(r"\d\d\d00").arg("test").stdout());909910    let mut cmd = dir.command();911    eqnice!("153.230000\n", cmd.arg(r"\d\d\d000").arg("test").stdout());912});913914// See: https://github.com/BurntSushi/ripgrep/issues/1223915rgtest!(916    r1223_no_dir_check_for_default_path,917    |dir: Dir, mut cmd: TestCommand| {918        dir.create_dir("-");919        dir.create("a.json", "{}");920        dir.create("a.txt", "some text");921922        eqnice!(923            "a.json\na.txt\n",924            sort_lines(&cmd.arg("a").pipe(b"a.json\na.txt"))925        );926    }927);928929// See: https://github.com/BurntSushi/ripgrep/issues/1259930rgtest!(r1259_drop_last_byte_nonl, |dir: Dir, mut cmd: TestCommand| {931    dir.create("patterns-nonl", "[foo]");932    dir.create("patterns-nl", "[foo]\n");933    dir.create("test", "fz");934935    eqnice!("fz\n", cmd.arg("-f").arg("patterns-nonl").arg("test").stdout());936    cmd = dir.command();937    eqnice!("fz\n", cmd.arg("-f").arg("patterns-nl").arg("test").stdout());938});939940// See: https://github.com/BurntSushi/ripgrep/issues/1311941rgtest!(r1311_multi_line_term_replace, |dir: Dir, mut cmd: TestCommand| {942    dir.create("input", "hello\nworld\n");943    eqnice!(944        "1:hello?world?\n",945        cmd.args(&["-U", "-r?", "-n", "\n", "input"]).stdout()946    );947});948949// See: https://github.com/BurntSushi/ripgrep/issues/1319950rgtest!(r1319, |dir: Dir, mut cmd: TestCommand| {951    dir.create("input", "CCAGCTACTCGGGAGGCTGAGGCTGGAGGATCGCTTGAGTCCAGGAGTTC");952    eqnice!(953        "input:CCAGCTACTCGGGAGGCTGAGGCTGGAGGATCGCTTGAGTCCAGGAGTTC\n",954        cmd.arg("TTGAGTCCAGGAG[ATCG]{2}C").stdout()955    );956});957958// See: https://github.com/BurntSushi/ripgrep/issues/1332959rgtest!(r1334_invert_empty_patterns, |dir: Dir, _cmd: TestCommand| {960    dir.create("zero-patterns", "");961    dir.create("one-pattern", "\n");962    dir.create("haystack", "one\ntwo\nthree\n");963964    // zero patterns matches nothing965    {966        let mut cmd = dir.command();967        cmd.arg("-f").arg("zero-patterns").arg("haystack").assert_err();968    }969    // one pattern that matches empty string matches everything970    {971        let mut cmd = dir.command();972        eqnice!(973            "one\ntwo\nthree\n",974            cmd.arg("-f").arg("one-pattern").arg("haystack").stdout()975        );976    }977978    // inverting zero patterns matches everything979    // (This is the regression. ripgrep used to match nothing because of an980    // incorrect optimization.)981    {982        let mut cmd = dir.command();983        eqnice!(984            "one\ntwo\nthree\n",985            cmd.arg("-vf").arg("zero-patterns").arg("haystack").stdout()986        );987    }988    // inverting one pattern that matches empty string matches nothing989    {990        let mut cmd = dir.command();991        cmd.arg("-vf").arg("one-pattern").arg("haystack").assert_err();992    }993});994995// See: https://github.com/BurntSushi/ripgrep/issues/1334996rgtest!(r1334_crazy_literals, |dir: Dir, mut cmd: TestCommand| {997    dir.create("patterns", &"1.208.0.0/12\n".repeat(40));998    dir.create("corpus", "1.208.0.0/12\n");999    eqnice!(1000        "1.208.0.0/12\n",1001        cmd.arg("-Ff").arg("patterns").arg("corpus").stdout()1002    );1003});10041005// See: https://github.com/BurntSushi/ripgrep/issues/13801006rgtest!(r1380, |dir: Dir, mut cmd: TestCommand| {1007    dir.create(1008        "foo",1009        "\1010a1011b1012c1013d1014e1015d1016e1017d1018e1019d1020e1021",1022    );10231024    eqnice!("d\ne\nd\n", cmd.args(&["-A2", "-m1", "d", "foo"]).stdout());1025});10261027// See: https://github.com/BurntSushi/ripgrep/issues/13891028rgtest!(r1389_bad_symlinks_no_biscuit, |dir: Dir, mut cmd: TestCommand| {1029    dir.create_dir("mydir");1030    dir.create("mydir/file.txt", "test");1031    dir.link_dir("mydir", "mylink");10321033    let stdout = cmd1034        .args(&["test", "--no-ignore", "--sort", "path", "mylink"])1035        .stdout();1036    eqnice!("mylink/file.txt:test\n", stdout);1037});10381039// See: https://github.com/BurntSushi/ripgrep/issues/14011040rgtest!(r1401_look_ahead_only_matching_1, |dir: Dir, mut cmd: TestCommand| {1041    // Only PCRE2 supports look-around.1042    if !dir.is_pcre2() {1043        return;1044    }1045    dir.create("ip.txt", "foo 42\nxoyz\ncat\tdog\n");1046    cmd.args(&["-No", r".*o(?!.*\s)", "ip.txt"]);1047    eqnice!("xo\ncat\tdo\n", cmd.stdout());10481049    let mut cmd = dir.command();1050    cmd.args(&["-No", r".*o(?!.*[ \t])", "ip.txt"]);1051    eqnice!("xo\ncat\tdo\n", cmd.stdout());1052});10531054// See: https://github.com/BurntSushi/ripgrep/issues/14011055rgtest!(r1401_look_ahead_only_matching_2, |dir: Dir, mut cmd: TestCommand| {1056    // Only PCRE2 supports look-around.1057    if !dir.is_pcre2() {1058        return;1059    }1060    dir.create("ip.txt", "foo 42\nxoyz\ncat\tdog\nfoo");1061    cmd.args(&["-No", r".*o(?!.*\s)", "ip.txt"]);1062    eqnice!("xo\ncat\tdo\nfoo\n", cmd.stdout());1063});10641065// See: https://github.com/BurntSushi/ripgrep/issues/14121066rgtest!(r1412_look_behind_no_replacement, |dir: Dir, mut cmd: TestCommand| {1067    // Only PCRE2 supports look-around.1068    if !dir.is_pcre2() {1069        return;1070    }10711072    dir.create("test", "foo\nbar\n");1073    cmd.args(&["-nU", "-rquux", r"(?<=foo\n)bar", "test"]);1074    eqnice!("2:quux\n", cmd.stdout());1075});10761077// See: https://github.com/BurntSushi/ripgrep/pull/14461078rgtest!(1079    r1446_respect_excludes_in_worktree,1080    |dir: Dir, mut cmd: TestCommand| {1081        dir.create_dir("repo/.git/info");1082        dir.create("repo/.git/info/exclude", "ignored");1083        dir.create_dir("repo/.git/worktrees/repotree");1084        dir.create("repo/.git/worktrees/repotree/commondir", "../..");10851086        dir.create_dir("repotree");1087        dir.create("repotree/.git", "gitdir: repo/.git/worktrees/repotree");1088        dir.create("repotree/ignored", "");1089        dir.create("repotree/not-ignored", "");10901091        cmd.arg("--sort").arg("path").arg("--files").arg("repotree");1092        eqnice!("repotree/not-ignored\n", cmd.stdout());1093    }1094);10951096// See: https://github.com/BurntSushi/ripgrep/issues/15371097rgtest!(r1537, |dir: Dir, mut cmd: TestCommand| {1098    dir.create("foo", "abc;de,fg");10991100    let expected = "foo:abc;de,fg\n";1101    eqnice!(expected, cmd.arg(";(.*,){1}").stdout());1102});11031104// See: https://github.com/BurntSushi/ripgrep/issues/15591105rgtest!(r1559, |dir: Dir, mut cmd: TestCommand| {1106    dir.create(1107        "foo",1108        "\1109type A struct {1110	TaskID int `json:\"taskID\"`1111}11121113type B struct {1114	ObjectID string `json:\"objectID\"`1115	TaskID   int    `json:\"taskID\"`1116}1117",1118    );11191120    let expected = "\1121foo:	TaskID int `json:\"taskID\"`1122foo:	TaskID   int    `json:\"taskID\"`1123";1124    eqnice!(expected, cmd.arg("TaskID +int").stdout());1125});11261127// See: https://github.com/BurntSushi/ripgrep/issues/15731128//1129// Tests that if look-ahead is used, then --count-matches is correct.1130rgtest!(r1573, |dir: Dir, mut cmd: TestCommand| {1131    // Only PCRE2 supports look-ahead.1132    if !dir.is_pcre2() {1133        return;1134    }11351136    dir.create_bytes("foo", b"\xFF\xFE\x00\x62");1137    dir.create(1138        "foo",1139        "\1140def A;1141def B;1142use A;1143use B;1144",1145    );11461147    // Check that normal --count is correct.1148    cmd.args(&[1149        "--pcre2",1150        "--multiline",1151        "--count",1152        r"(?s)def (\w+);(?=.*use \w+)",1153        "foo",1154    ]);1155    eqnice!("2\n", cmd.stdout());11561157    // Now check --count-matches.1158    let mut cmd = dir.command();1159    cmd.args(&[1160        "--pcre2",1161        "--multiline",1162        "--count-matches",1163        r"(?s)def (\w+);(?=.*use \w+)",1164        "foo",1165    ]);1166    eqnice!("2\n", cmd.stdout());1167});11681169// See: https://github.com/BurntSushi/ripgrep/issues/16381170//1171// Tests if UTF-8 BOM is sniffed, then the column index is correct.1172rgtest!(r1638, |dir: Dir, mut cmd: TestCommand| {1173    dir.create_bytes("foo", b"\xef\xbb\xbfx");11741175    eqnice!("foo:1:1:x\n", cmd.arg("--column").arg("x").stdout());1176});11771178// See: https://github.com/BurntSushi/ripgrep/issues/17391179rgtest!(r1739_replacement_lineterm_match, |dir: Dir, mut cmd: TestCommand| {1180    dir.create("test", "a\n");1181    cmd.args(&[r"-r${0}f", r".*", "test"]);1182    eqnice!("af\n", cmd.stdout());1183});11841185// See: https://github.com/BurntSushi/ripgrep/issues/17571186rgtest!(f1757, |dir: Dir, _: TestCommand| {1187    dir.create_dir("rust/target");1188    dir.create(".ignore", "rust/target");1189    dir.create("rust/source.rs", "needle");1190    dir.create("rust/target/rustdoc-output.html", "needle");11911192    let args = &["--files-with-matches", "needle", "rust"];1193    eqnice!("rust/source.rs\n", dir.command().args(args).stdout());1194    let args = &["--files-with-matches", "needle", "./rust"];1195    eqnice!("./rust/source.rs\n", dir.command().args(args).stdout());11961197    dir.create_dir("rust1/target/onemore");1198    dir.create(".ignore", "rust1/target/onemore");1199    dir.create("rust1/source.rs", "needle");1200    dir.create("rust1/target/onemore/rustdoc-output.html", "needle");1201    let args = &["--files-with-matches", "needle", "rust1"];1202    eqnice!("rust1/source.rs\n", dir.command().args(args).stdout());1203    let args = &["--files-with-matches", "needle", "./rust1"];1204    eqnice!("./rust1/source.rs\n", dir.command().args(args).stdout());1205});12061207// See: https://github.com/BurntSushi/ripgrep/issues/17651208rgtest!(r1765, |dir: Dir, mut cmd: TestCommand| {1209    dir.create("test", "\n");1210    // We need to add --color=always here to force the failure, since the bad1211    // code path is only triggered when colors are enabled.1212    cmd.args(&[r"x?", "--crlf", "--color", "always"]);12131214    assert!(!cmd.stdout().is_empty());1215});12161217// See: https://github.com/BurntSushi/ripgrep/issues/18381218rgtest!(r1838_nul_error_with_binary_detection, |dir: Dir, _: TestCommand| {1219    // We don't support this error reporting with PCRE2 since we can't parse1220    // the pattern (easily) to give a good error message.1221    if dir.is_pcre2() {1222        return;1223    }1224    dir.create("test", "foo\n");12251226    dir.command().args(&[r"foo\x00?"]).assert_err();1227    eqnice!("test:foo\n", dir.command().args(&["-a", r"foo\x00?"]).stdout());1228});12291230// See: https://github.com/BurntSushi/ripgrep/issues/18661231rgtest!(r1866, |dir: Dir, mut cmd: TestCommand| {1232    dir.create("test", "foobar\nfoobar\nfoo quux");1233    cmd.args(&[1234        "--multiline",1235        "--vimgrep",1236        r"foobar\nfoobar\nfoo|quux",1237        "test",1238    ]);12391240    // vimgrep only wants the first line of each match, even when a match1241    // spans multiple lines.1242    //1243    // See: https://github.com/BurntSushi/ripgrep/issues/18661244    let expected = "\1245test:1:1:foobar1246test:3:5:foo quux1247";1248    eqnice!(expected, cmd.stdout());1249});12501251// See: https://github.com/BurntSushi/ripgrep/issues/18681252rgtest!(r1868_context_passthru_override, |dir: Dir, _: TestCommand| {1253    dir.create("test", "foo\nbar\nbaz\nquux\n");12541255    let args = &["-C1", "bar", "test"];1256    eqnice!("foo\nbar\nbaz\n", dir.command().args(args).stdout());1257    let args = &["--passthru", "bar", "test"];1258    eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());12591260    let args = &["--passthru", "-C1", "bar", "test"];1261    eqnice!("foo\nbar\nbaz\n", dir.command().args(args).stdout());1262    let args = &["-C1", "--passthru", "bar", "test"];1263    eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());12641265    let args = &["--passthru", "-B1", "bar", "test"];1266    eqnice!("foo\nbar\n", dir.command().args(args).stdout());1267    let args = &["-B1", "--passthru", "bar", "test"];1268    eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());12691270    let args = &["--passthru", "-A1", "bar", "test"];1271    eqnice!("bar\nbaz\n", dir.command().args(args).stdout());1272    let args = &["-A1", "--passthru", "bar", "test"];1273    eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());1274});12751276rgtest!(r1878, |dir: Dir, _: TestCommand| {1277    dir.create("test", "a\nbaz\nabc\n");12781279    // Since ripgrep enables (?m) by default, '^' will match at the beginning1280    // of a line, even when -U/--multiline is used.1281    let args = &["-U", "--no-mmap", r"^baz", "test"];1282    eqnice!("baz\n", dir.command().args(args).stdout());1283    let args = &["-U", "--mmap", r"^baz", "test"];1284    eqnice!("baz\n", dir.command().args(args).stdout());12851286    // But when (?-m) is disabled, or when \A is used, then there should be no1287    // matches that aren't anchored to the beginning of the file.1288    let args = &["-U", "--no-mmap", r"(?-m)^baz", "test"];1289    dir.command().args(args).assert_err();1290    let args = &["-U", "--mmap", r"(?-m)^baz", "test"];1291    dir.command().args(args).assert_err();12921293    let args = &["-U", "--no-mmap", r"\Abaz", "test"];1294    dir.command().args(args).assert_err();1295    let args = &["-U", "--mmap", r"\Abaz", "test"];1296    dir.command().args(args).assert_err();1297});12981299// See: https://github.com/BurntSushi/ripgrep/issues/18911300rgtest!(r1891, |dir: Dir, mut cmd: TestCommand| {1301    dir.create("test", "\n##\n");1302    // N.B. We use -o here to force the issue to occur, which seems to only1303    // happen when each match needs to be detected.1304    eqnice!("1:\n2:\n2:\n2:\n", cmd.args(&["-won", "", "test"]).stdout());1305});13061307// See: https://github.com/BurntSushi/ripgrep/issues/20941308rgtest!(r2094, |dir: Dir, mut cmd: TestCommand| {1309    dir.create("haystack", "a\nb\nc\na\nb\nc");1310    cmd.args(&[1311        "--no-line-number",1312        "--no-filename",1313        "--multiline",1314        "--max-count=1",1315        "--passthru",1316        "--replace=B",1317        "b",1318        "haystack",1319    ]);1320    let expected = "\1321a1322B1323c1324a1325b1326c1327";1328    eqnice!(expected, cmd.stdout());1329});13301331// See: https://github.com/BurntSushi/ripgrep/issues/20951332rgtest!(r2095, |dir: Dir, mut cmd: TestCommand| {1333    dir.create(1334        "test",1335        "#!/usr/bin/env bash13361337zero=one13381339a=one13401341if true; then1342	a=(1343		a1344		b1345		c1346	)1347	true1348fi13491350a=two13511352b=one1353});1354",1355    );1356    cmd.args(&[1357        "--line-number",1358        "--multiline",1359        "--only-matching",1360        "--replace",1361        "${value}",1362        r"^(?P<indent>\s*)a=(?P<value>(?ms:[(].*?[)])|.*?)$",1363        "test",1364    ]);1365    let expected = "4:one13668:(13679:		a136810:		b136911:		c137012:	)137115:two1372";1373    eqnice!(expected, cmd.stdout());1374});13751376// See: https://github.com/BurntSushi/ripgrep/issues/21981377rgtest!(r2198, |dir: Dir, mut cmd: TestCommand| {1378    dir.create(".ignore", "a");1379    dir.create(".rgignore", "b");1380    dir.create("a", "");1381    dir.create("b", "");1382    dir.create("c", "");13831384    cmd.arg("--files").arg("--sort").arg("path");1385    eqnice!("c\n", cmd.stdout());1386    eqnice!("a\nb\nc\n", cmd.arg("--no-ignore-dot").stdout());1387});13881389// See: https://github.com/BurntSushi/ripgrep/issues/22081390rgtest!(r2208, |dir: Dir, mut cmd: TestCommand| {1391    dir.create("test", "# Compile requirements.txt files from all found or specified requirements.in files (compile).1392# Use -h to include hashes, -u dep1,dep2... to upgrade specific dependencies, and -U to upgrade all.1393pipc () {  # [-h] [-U|-u <pkgspec>[,<pkgspec>...]] [<reqs-in>...] [-- <pip-compile-arg>...]1394    emulate -L zsh1395    unset REPLY1396    if [[ $1 == --help ]] { zpy $0; return }1397    [[ $ZPY_PROCS ]] || return13981399    local gen_hashes upgrade upgrade_csv1400    while [[ $1 == -[hUu] ]] {1401        if [[ $1 == -h ]] { gen_hashes=--generate-hashes; shift   }1402        if [[ $1 == -U ]] { upgrade=1;                    shift   }1403        if [[ $1 == -u ]] { upgrade=1; upgrade_csv=$2;    shift 2 }1404    }1405}1406");1407    cmd.args(&[1408        "-N",1409        "-U",1410        "-r", "$usage",1411        r#"^(?P<predoc>\n?(# .*\n)*)(alias (?P<aname>pipc)="[^"]+"|(?P<fname>pipc) \(\) \{)(  #(?P<usage> .+))?"#,1412        "test",1413    ]);1414    let expected = " [-h] [-U|-u <pkgspec>[,<pkgspec>...]] [<reqs-in>...] [-- <pip-compile-arg>...]\n";1415    eqnice!(expected, cmd.stdout());1416});14171418// See: https://github.com/BurntSushi/ripgrep/issues/22361419rgtest!(r2236, |dir: Dir, mut cmd: TestCommand| {1420    dir.create(".ignore", r"foo\/");1421    dir.create_dir("foo");1422    dir.create("foo/bar", "test\n");1423    cmd.args(&["test"]).assert_err();1424});14251426// See: https://github.com/BurntSushi/ripgrep/issues/24801427rgtest!(r2480, |dir: Dir, mut cmd: TestCommand| {1428    dir.create("file", "FooBar\n");14291430    // no regression in empty pattern behavior1431    cmd.args(&["-e", "", "file"]);1432    eqnice!("FooBar\n", cmd.stdout());14331434    // no regression in single pattern behavior1435    let mut cmd = dir.command();1436    cmd.args(&["-e", ")(", "file"]);1437    eqnice!("FooBar\n", cmd.stdout());14381439    // no regression in multiple patterns behavior1440    let mut cmd = dir.command();1441    cmd.args(&["--only-matching", "-e", "Foo", "-e", "Bar", "file"]);1442    eqnice!("Foo\nBar\n", cmd.stdout());14431444    // no regression in capture groups behavior1445    let mut cmd = dir.command();1446    cmd.args(&["-e", "Fo(oB)a(r)", "--replace", "${0}_${1}_${2}${3}", "file"]);1447    eqnice!("FooBar_oB_r\n", cmd.stdout()); // note: ${3} expected to be empty14481449    // flag does not leak into next pattern on match1450    let mut cmd = dir.command();1451    cmd.args(&["--only-matching", "-e", "(?i)foo", "-e", "bar", "file"]);1452    eqnice!("Foo\n", cmd.stdout());14531454    // flag does not leak into next pattern on mismatch1455    let mut cmd = dir.command();1456    cmd.args(&["--only-matching", "-e", "(?i)notfoo", "-e", "bar", "file"]);1457    cmd.assert_err();1458});14591460// See: https://github.com/BurntSushi/ripgrep/issues/25741461rgtest!(r2574, |dir: Dir, mut cmd: TestCommand| {1462    dir.create("haystack", "some.domain.com\nsome.domain.com/x\n");1463    let got = cmd1464        .args(&[1465            "--no-filename",1466            "--no-unicode",1467            "-w",1468            "-o",1469            r"(\w+\.)*domain\.(\w+)",1470        ])1471        .stdout();1472    eqnice!("some.domain.com\nsome.domain.com\n", got);1473});14741475// See: https://github.com/BurntSushi/ripgrep/issues/26581476rgtest!(r2658_null_data_line_regexp, |dir: Dir, mut cmd: TestCommand| {1477    dir.create("haystack", "foo\0bar\0quux\0");1478    let got = cmd.args(&["--null-data", "--line-regexp", r"bar"]).stdout();1479    eqnice!("haystack:bar\0", got);1480});14811482// See: https://github.com/BurntSushi/ripgrep/issues/27701483rgtest!(r2770_gitignore_error, |dir: Dir, _cmd: TestCommand| {1484    dir.create(".git", "");1485    dir.create(".gitignore", "**/bar/*");1486    dir.create_dir("foo/bar");1487    dir.create("foo/bar/baz", "quux");14881489    dir.command().arg("-l").arg("quux").assert_err();1490    dir.command().current_dir("foo").arg("-l").arg("quux").assert_err();1491});14921493// See: https://github.com/BurntSushi/ripgrep/pull/29441494rgtest!(r2944_incorrect_bytes_searched, |dir: Dir, mut cmd: TestCommand| {1495    dir.create("haystack", "foo1\nfoo2\nfoo3\nfoo4\nfoo5\n");1496    let got = cmd.args(&["--stats", "-m2", "foo", "."]).stdout();1497    assert!(got.contains("10 bytes searched\n"));1498});14991500// See: https://github.com/BurntSushi/ripgrep/issues/29901501#[cfg(unix)]1502rgtest!(r2990_trip_over_trailing_dot, |dir: Dir, _cmd: TestCommand| {1503    dir.create_dir("asdf");1504    dir.create_dir("asdf.");1505    dir.create("asdf/foo", "");1506    dir.create("asdf./foo", "");15071508    let got = dir.command().args(&["--files", "-g", "!asdf/"]).stdout();1509    eqnice!("asdf./foo\n", got);15101511    // This used to ignore the glob given and included `asdf./foo` in output.1512    let got = dir.command().args(&["--files", "-g", "!asdf./"]).stdout();1513    eqnice!("asdf/foo\n", got);1514});15151516// See: https://github.com/BurntSushi/ripgrep/issues/30671517rgtest!(r3067_gitignore_error, |dir: Dir, mut cmd: TestCommand| {1518    dir.create(".git", "");1519    dir.create(".gitignore", "foobar/debug");1520    dir.create_dir("foobar/some/debug");1521    dir.create_dir("foobar/debug");1522    dir.create("foobar/some/debug/flag", "baz");1523    dir.create("foobar/debug/flag2", "baz");15241525    let got = cmd.arg("baz").stdout();1526    eqnice!("foobar/some/debug/flag:baz\n", got);1527});15281529// See: https://github.com/BurntSushi/ripgrep/issues/31081530rgtest!(r3108_files_without_match_quiet_exit, |dir: Dir, _: TestCommand| {1531    dir.create("yes-match", "abc");1532    dir.create("non-match", "xyz");15331534    dir.command().args(&["-q", "abc", "non-match"]).assert_exit_code(1);1535    dir.command().args(&["-q", "abc", "yes-match"]).assert_exit_code(0);1536    dir.command()1537        .args(&["--files-with-matches", "-q", "abc", "non-match"])1538        .assert_exit_code(1);1539    dir.command()1540        .args(&["--files-with-matches", "-q", "abc", "yes-match"])1541        .assert_exit_code(0);15421543    dir.command()1544        .args(&["--files-without-match", "abc", "non-match"])1545        .assert_exit_code(0);1546    dir.command()1547        .args(&["--files-without-match", "abc", "yes-match"])1548        .assert_exit_code(1);15491550    let got = dir1551        .command()1552        .args(&["--files-without-match", "abc", "non-match"])1553        .stdout();1554    eqnice!("non-match\n", got);15551556    dir.command()1557        .args(&["--files-without-match", "-q", "abc", "non-match"])1558        .assert_exit_code(0);1559    dir.command()1560        .args(&["--files-without-match", "-q", "abc", "yes-match"])1561        .assert_exit_code(1);15621563    let got = dir1564        .command()1565        .args(&["--files-without-match", "-q", "abc", "non-match"])1566        .stdout();1567    eqnice!("", got);1568});15691570// See: https://github.com/BurntSushi/ripgrep/issues/31271571rgtest!(1572    r3127_gitignore_allow_unclosed_class,1573    |dir: Dir, mut cmd: TestCommand| {1574        dir.create_dir(".git");1575        dir.create(".gitignore", "[abc");1576        dir.create("[abc", "");1577        dir.create("test", "");15781579        let got = cmd.args(&["--files"]).stdout();1580        eqnice!("test\n", got);1581    }1582);15831584// See: https://github.com/BurntSushi/ripgrep/issues/31271585rgtest!(1586    r3127_glob_flag_not_allow_unclosed_class,1587    |dir: Dir, mut cmd: TestCommand| {1588        dir.create("[abc", "");1589        dir.create("test", "");15901591        cmd.args(&["--files", "-g", "[abc"]).assert_err();1592    }1593);15941595// See: https://github.com/BurntSushi/ripgrep/issues/31391596rgtest!(1597    r3139_multiline_lookahead_files_with_matches,1598    |dir: Dir, _cmd: TestCommand| {1599        // Only PCRE2 supports look-around.1600        if !dir.is_pcre2() {1601            return;1602        }1603        dir.create(1604            "test",1605            "\1606Start \n   \n\n   \1607XXXXXXXXXXXXXXXXXXXXXXXXXX\n   \1608YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\n   \1609\n      thing2 \n\n",1610        );16111612        let got = dir1613            .command()1614            .args(&[1615                "--multiline",1616                "--pcre2",1617                r"(?s)Start(?=.*thing2)",1618                "test",1619            ])1620            .stdout();1621        eqnice!("Start \n", got);16221623        let got = dir1624            .command()1625            .args(&[1626                "--multiline",1627                "--pcre2",1628                "--files-with-matches",1629                r"(?s)Start(?=.*thing2)",1630                "test",1631            ])1632            .stdout();1633        eqnice!("test\n", got);1634    }1635);16361637// See: https://github.com/BurntSushi/ripgrep/issues/31731638rgtest!(r3173_hidden_whitelist_only_dot, |dir: Dir, _: TestCommand| {1639    dir.create_dir("subdir");1640    dir.create("subdir/.foo.txt", "text");1641    dir.create(".ignore", "!.foo.txt");16421643    let cmd = || dir.command();1644    eqnice!(cmd().args(&["--files"]).stdout(), "subdir/.foo.txt\n");1645    eqnice!(cmd().args(&["--files", "."]).stdout(), "./subdir/.foo.txt\n");1646    eqnice!(cmd().args(&["--files", "./"]).stdout(), "./subdir/.foo.txt\n");16471648    let cmd = || {1649        let mut cmd = dir.command();1650        cmd.current_dir("subdir");1651        cmd1652    };1653    eqnice!(cmd().args(&["--files"]).stdout(), ".foo.txt\n");1654    eqnice!(cmd().args(&["--files", "."]).stdout(), "./.foo.txt\n");1655    eqnice!(cmd().args(&["--files", "./"]).stdout(), "./.foo.txt\n");1656});16571658// See: https://github.com/BurntSushi/ripgrep/issues/31791659rgtest!(r3179_global_gitignore_cwd, |dir: Dir, mut cmd: TestCommand| {1660    dir.create_dir("a/b/c");1661    dir.create("a/b/c/haystack", "");1662    dir.create(".test.gitignore", "/haystack");16631664    // I'm not sure in which cases this can fail. If it1665    // does and it's unavoidable, feel free to submit a1666    // patch that skips this test when this canonicalization1667    // fails.1668    //1669    // The reason we canonicalize here is strange, and it is1670    // perhaps papering over a bug in ripgrep. But on macOS,1671    // `TMPDIR` is set to `/var/blah/blah`. However, `/var`1672    // is symlinked to `/private/var`. So the CWD detected by1673    // the process is `/private/var`. So it turns out that the1674    // CWD is not a proper prefix of `dir.path()` here. So we1675    // cheat around this by forcing our path to be canonicalized1676    // so it's `/private/var` everywhere.1677    //1678    // Arguably, ripgrep should still work here without1679    // canonicalization. But it's not actually quite clear1680    // to me how to do it. I *believe* the solution here is1681    // that gitignore matching should be relative to the directory1682    // path given to `WalkBuilder::{add,new}`, and *not* to the1683    // CWD. But this is a very big change to how `ignore` works1684    // I think. At least conceptually. So that will need to be1685    // something we do when we rewrite `ignore`. Sigh.1686    //1687    // ...  but, on Windows, path canonicalization seems to1688    // totally fuck things up, so skip it there. HEAVY sigh.1689    let dir_path = if cfg!(windows) {1690        dir.path().to_path_buf()1691    } else {1692        dir.path().canonicalize().unwrap()1693    };1694    let ignore_file_path = dir_path.join(".test.gitignore");1695    cmd.current_dir("a/b/c")1696        .arg("--files")1697        .arg("--ignore-file")1698        .arg(ignore_file_path.display().to_string())1699        // This is a key part of the reproduction. When just providing `.`1700        // to ignore's walker (as ripgrep does when a path to search isn't1701        // provided), then everything works as one expects. Because there's1702        // nothing to strip off of the paths being searched. But when one1703        // provides an absolute path, the stripping didn't work.1704        .arg(&dir_path)1705        .assert_err();1706});17071708// See: https://github.com/BurntSushi/ripgrep/issues/31801709rgtest!(r3180_look_around_panic, |dir: Dir, mut cmd: TestCommand| {1710    dir.create("haystack", " b b b b b b b b\nc\n");17111712    let got = cmd1713        .arg(r#"(^|[^a-z])((([a-z]+)?)\s)?b(\s([a-z]+)?)($|[^a-z])"#)1714        .arg("haystack")1715        .arg("-U")1716        .arg("-rx")1717        .stdout();1718    eqnice!("xbxbx\n", got);1719});17201721// See: https://github.com/BurntSushi/ripgrep/issues/32751722//1723// This test doesn't seem to work on Windows for whatever reason. I haven't1724// investigated it yet, but I'm pretty sure it's just the test. I'm guessing1725// it's related to path separators. ---AG1726#[cfg(not(windows))]1727rgtest!(r3275_git_global_config_env, |dir: Dir, mut cmd: TestCommand| {1728    dir.create_dir("foo");1729    dir.create(".git", "");1730    dir.create("foo/foo1", "");1731    dir.create("foo/foo2", "");1732    dir.create("global-excludes-nonstandard", "foo2");1733    dir.create(1734        "global-config-nonstandard",1735        &format!(1736            "[core]\n\texcludesFile = {path}",1737            path = dir.path().join("global-excludes-nonstandard").display()1738        ),1739    );17401741    let config_path = dir.path().join("global-config-nonstandard");1742    cmd.env("GIT_CONFIG_GLOBAL", config_path);1743    eqnice!("foo/foo1\n", cmd.arg("--files").arg("foo").stdout());1744});