mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-11-23 21:54:45 +02:00
test: fix Command::current_dir API
Every single call site wants to pass a path relative to the directory the command was created for. So just make it do that automatically, similar to `Dir::create` and friends.
This commit is contained in:
@@ -154,7 +154,7 @@ test
|
||||
// parent ignore files and manually specified ignore files.
|
||||
let mut cmd = dir.command();
|
||||
cmd.args(&["--ignore-file", "../.not-an-ignore", "-l", "test"]);
|
||||
cmd.current_dir(dir.path().join("baz"));
|
||||
cmd.current_dir("baz");
|
||||
let expected = "
|
||||
baz/bar/test
|
||||
test
|
||||
|
||||
@@ -627,7 +627,7 @@ rgtest!(ignore_git_parent, |dir: Dir, mut cmd: TestCommand| {
|
||||
|
||||
// Even though we search in foo/, which has no .gitignore, ripgrep will
|
||||
// traverse parent directories and respect the gitignore files found.
|
||||
cmd.current_dir(dir.path().join("foo"));
|
||||
cmd.current_dir("foo");
|
||||
cmd.assert_err();
|
||||
});
|
||||
|
||||
@@ -651,7 +651,7 @@ rgtest!(ignore_git_parent_stop, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create_dir("foo/bar");
|
||||
dir.create("foo/bar/sherlock", SHERLOCK);
|
||||
cmd.arg("Sherlock");
|
||||
cmd.current_dir(dir.path().join("foo").join("bar"));
|
||||
cmd.current_dir("foo/bar");
|
||||
|
||||
let expected = "\
|
||||
sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||
@@ -682,7 +682,7 @@ rgtest!(ignore_git_parent_stop_file, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create_dir("foo/bar");
|
||||
dir.create("foo/bar/sherlock", SHERLOCK);
|
||||
cmd.arg("Sherlock");
|
||||
cmd.current_dir(dir.path().join("foo").join("bar"));
|
||||
cmd.current_dir("foo/bar");
|
||||
|
||||
let expected = "\
|
||||
sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||
@@ -700,7 +700,7 @@ rgtest!(ignore_ripgrep_parent_no_stop, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create_dir("foo/bar");
|
||||
dir.create("foo/bar/sherlock", SHERLOCK);
|
||||
cmd.arg("Sherlock");
|
||||
cmd.current_dir(dir.path().join("foo").join("bar"));
|
||||
cmd.current_dir("foo/bar");
|
||||
|
||||
// The top-level .rgignore applies.
|
||||
cmd.assert_err();
|
||||
@@ -733,7 +733,7 @@ rgtest!(no_parent_ignore_git, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create("foo/sherlock", SHERLOCK);
|
||||
dir.create("foo/watson", SHERLOCK);
|
||||
cmd.arg("--no-ignore-parent").arg("Sherlock");
|
||||
cmd.current_dir(dir.path().join("foo"));
|
||||
cmd.current_dir("foo");
|
||||
|
||||
let expected = "\
|
||||
sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||
@@ -749,7 +749,7 @@ rgtest!(symlink_nofollow, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create_dir("foo/baz");
|
||||
dir.create("foo/baz/sherlock", SHERLOCK);
|
||||
cmd.arg("Sherlock");
|
||||
cmd.current_dir(dir.path().join("foo/bar"));
|
||||
cmd.current_dir("foo/bar");
|
||||
|
||||
cmd.assert_err();
|
||||
});
|
||||
@@ -762,7 +762,7 @@ rgtest!(symlink_follow, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create("foo/baz/sherlock", SHERLOCK);
|
||||
dir.link_dir("foo/baz", "foo/bar/baz");
|
||||
cmd.arg("-L").arg("Sherlock");
|
||||
cmd.current_dir(dir.path().join("foo/bar"));
|
||||
cmd.current_dir("foo/bar");
|
||||
|
||||
let expected = "\
|
||||
baz/sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||
|
||||
@@ -23,7 +23,7 @@ rgtest!(r25, |dir: Dir, mut cmd: TestCommand| {
|
||||
cmd.arg("test");
|
||||
eqnice!("src/llvm/foo:test\n", cmd.stdout());
|
||||
|
||||
cmd.current_dir(dir.path().join("src"));
|
||||
cmd.current_dir("src");
|
||||
eqnice!("llvm/foo:test\n", cmd.stdout());
|
||||
});
|
||||
|
||||
@@ -244,7 +244,7 @@ rgtest!(r184, |dir: Dir, mut cmd: TestCommand| {
|
||||
cmd.arg("test");
|
||||
eqnice!("foo/bar/baz:test\n", cmd.stdout());
|
||||
|
||||
cmd.current_dir(dir.path().join("./foo/bar"));
|
||||
cmd.current_dir("./foo/bar");
|
||||
eqnice!("baz:test\n", cmd.stdout());
|
||||
});
|
||||
|
||||
@@ -612,17 +612,17 @@ rgtest!(r2711, |dir: Dir, _cmd: TestCommand| {
|
||||
|
||||
{
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("a"));
|
||||
cmd.current_dir("a");
|
||||
eqnice!(".ignore\n", cmd.arg("--hidden").arg("--files").stdout());
|
||||
}
|
||||
{
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("a").join("b"));
|
||||
cmd.current_dir("a/b");
|
||||
cmd.arg("--hidden").arg("--files").assert_err();
|
||||
}
|
||||
{
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("./a"));
|
||||
cmd.current_dir("./a");
|
||||
eqnice!(".ignore\n", cmd.arg("--hidden").arg("--files").stdout());
|
||||
}
|
||||
});
|
||||
@@ -643,7 +643,7 @@ rgtest!(r829_original, |dir: Dir, _cmd: TestCommand| {
|
||||
}
|
||||
{
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("a"));
|
||||
cmd.current_dir("a");
|
||||
cmd.args(&["Sample"]).assert_err();
|
||||
}
|
||||
});
|
||||
@@ -706,7 +706,7 @@ rgtest!(r829_2747, |dir: Dir, _cmd: TestCommand| {
|
||||
}
|
||||
{
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("a/src"));
|
||||
cmd.current_dir("a/src");
|
||||
eqnice!("f/b/foo\n", cmd.arg("--files").stdout());
|
||||
}
|
||||
});
|
||||
@@ -727,7 +727,7 @@ rgtest!(r829_2778, |dir: Dir, _cmd: TestCommand| {
|
||||
}
|
||||
{
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("parent"));
|
||||
cmd.current_dir("parent");
|
||||
eqnice!("subdir/dont-ignore-me.txt\n", cmd.arg("--files").stdout());
|
||||
}
|
||||
});
|
||||
@@ -744,7 +744,7 @@ rgtest!(r829_2836, |dir: Dir, _cmd: TestCommand| {
|
||||
}
|
||||
{
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("testdir"));
|
||||
cmd.current_dir("testdir");
|
||||
cmd.arg("--files").assert_err();
|
||||
}
|
||||
});
|
||||
@@ -756,7 +756,7 @@ rgtest!(r829_2933, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create("testdir/sub/sub2/testfile", "needle");
|
||||
|
||||
let args = &["--files-with-matches", "needle"];
|
||||
cmd.current_dir(dir.path().join("testdir"));
|
||||
cmd.current_dir("testdir");
|
||||
cmd.args(args).assert_err();
|
||||
});
|
||||
|
||||
@@ -1463,11 +1463,7 @@ rgtest!(r2770_gitignore_error, |dir: Dir, _cmd: TestCommand| {
|
||||
dir.create("foo/bar/baz", "quux");
|
||||
|
||||
dir.command().arg("-l").arg("quux").assert_err();
|
||||
dir.command()
|
||||
.current_dir(dir.path().join("foo"))
|
||||
.arg("-l")
|
||||
.arg("quux")
|
||||
.assert_err();
|
||||
dir.command().current_dir("foo").arg("-l").arg("quux").assert_err();
|
||||
});
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/pull/2944
|
||||
@@ -1627,7 +1623,7 @@ rgtest!(r3173_hidden_whitelist_only_dot, |dir: Dir, _: TestCommand| {
|
||||
|
||||
let cmd = || {
|
||||
let mut cmd = dir.command();
|
||||
cmd.current_dir(dir.path().join("subdir"));
|
||||
cmd.current_dir("subdir");
|
||||
cmd
|
||||
};
|
||||
eqnice!(cmd().args(&["--files"]).stdout(), ".foo.txt\n");
|
||||
|
||||
@@ -273,11 +273,14 @@ impl TestCommand {
|
||||
|
||||
/// Set the working directory for this command.
|
||||
///
|
||||
/// The path given is interpreted relative to the directory that this
|
||||
/// command was created for.
|
||||
///
|
||||
/// Note that this does not need to be called normally, since the creation
|
||||
/// of this TestCommand causes its working directory to be set to the
|
||||
/// test's directory automatically.
|
||||
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut TestCommand {
|
||||
self.cmd.current_dir(dir);
|
||||
self.cmd.current_dir(self.dir.path().join(dir));
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user