Skip to content

Commit 3045243

Browse files
committed
Interpret relative paths relative to <ROOT>
1 parent 93a2e98 commit 3045243

5 files changed

Lines changed: 12 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ To be clear, Necessist does not apply (`*`) formally, e.g., Necessist does not a
172172
Usage: necessist [OPTIONS] [TEST_FILES_OR_DIRS]... [-- <ARGS>...]
173173
174174
Arguments:
175-
[TEST_FILES_OR_DIRS]... Test files or directories to mutilate (optional)
175+
[TEST_FILES_OR_DIRS]... Test files or directories to mutilate; if `--root <ROOT>` is passed, relative paths are interpreted relative to <ROOT>
176176
[ARGS]... Additional arguments to pass to each test command
177177
178178
Options:

core/src/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub struct Opts<Identifier: Clone + Send + Sync + ValueEnum + 'static> {
5959
verbose: bool,
6060
#[clap(
6161
value_name = "TEST_FILES_OR_DIRS",
62-
help = "Test files or directories to mutilate (optional)"
62+
help = "Test files or directories to mutilate; if `--root <ROOT>` is passed, relative \
63+
paths are interpreted relative to <ROOT>"
6364
)]
6465
zsource_files: Vec<String>,
6566
#[clap(

core/src/core.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,12 @@ fn canonicalize_source_files(context: &LightContext) -> Result<Vec<PathBuf>> {
491491
.source_files
492492
.iter()
493493
.map(|path| {
494-
let path_buf = dunce::canonicalize(path)
494+
let path_to_canonicalize = if path.is_absolute() {
495+
path.clone()
496+
} else {
497+
context.root.join(path)
498+
};
499+
let path_buf = dunce::canonicalize(&path_to_canonicalize)
495500
.with_context(|| format!("Failed to canonicalize `{}`", path.display()))?;
496501
ensure!(
497502
path_buf.starts_with(context.root.as_path()),

necessist/tests/necessist_db_absent/cli_input_mixed.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ args = [
22
"--no-sqlite",
33
"--dump-candidates",
44
"--root=fixtures/cli_input",
5-
"fixtures/cli_input/src/some_dir",
6-
"fixtures/cli_input/src/other_dir/some_file.rs",
5+
"src/some_dir",
6+
"src/other_dir/some_file.rs",
77
]
88

99
stderr = ""

necessist/tests/necessist_db_absent/dry_run_failure_test_file.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
args = [
22
"--no-sqlite",
33
"--root=fixtures/dry_run_failure",
4-
"fixtures/dry_run_failure/tests/b.rs",
4+
"tests/b.rs",
55
]
66

77
stderr = ""

0 commit comments

Comments
 (0)