Skip to content

Commit 97707a8

Browse files
Add tests
1 parent 7a69aaf commit 97707a8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/cargo/util/config/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,20 @@ impl Config {
450450
if let Some(dir) = &self.target_dir {
451451
Ok(Some(dir.clone()))
452452
} else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
453+
// Check if the CARGO_TARGET_DIR environment variable is set to an empty string.
453454
if dir.to_string_lossy() == "" {
454-
anyhow::bail!("the target directory is set to an empty string")
455+
anyhow::bail!("the target directory is set to an empty string in the CARGO_TARGET_DIR environment variable.")
455456
}
456457

457458
Ok(Some(Filesystem::new(self.cwd.join(dir))))
458459
} else if let Some(val) = &self.build_config()?.target_dir {
459460
let path = val.resolve_path(self);
460461

462+
// Check if the target directory is set to an empty string in the config.toml file.
461463
if val.raw_value() == "" {
462-
anyhow::bail!("the target directory is set to an empty string")
464+
anyhow::bail!(
465+
"the target directory is set to an empty string in the config.toml file.",
466+
)
463467
}
464468

465469
Ok(Some(Filesystem::new(path)))

tests/testsuite/config.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,17 @@ target-dir = ''
14971497

14981498
assert_error(
14991499
config.target_dir().unwrap_err(),
1500-
"the target directory is set to an empty string",
1500+
"the target directory is set to an empty string in the config.toml file.",
15011501
);
15021502
}
1503+
1504+
#[cargo_test]
1505+
fn cargo_target_empty_env() {
1506+
let project = project().build();
1507+
1508+
project.cargo("build")
1509+
.env("CARGO_TARGET_DIR", "")
1510+
.with_stderr("error: the target directory is set to an empty string in the CARGO_TARGET_DIR environment variable.")
1511+
.with_status(101)
1512+
.run()
1513+
}

0 commit comments

Comments
 (0)