Skip to content

Commit 02665ea

Browse files
authored
Mask insta env vars in integration tests (#579)
1 parent ef7abb8 commit 02665ea

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cargo-insta/tests/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,25 @@ impl TestProject {
111111
}
112112
fn cmd(&self) -> Command {
113113
let mut command = Command::new(env!("CARGO_BIN_EXE_cargo-insta"));
114+
// Remove environment variables so we don't inherit anything (such as
115+
// `INSTA_FORCE_PASS` or `CARGO_INSTA_*`) from a cargo-insta process
116+
// which runs this integration test.
117+
for (key, _) in env::vars() {
118+
if key.starts_with("CARGO_INSTA") || key.starts_with("INSTA") {
119+
command.env_remove(&key);
120+
}
121+
}
122+
// Turn off CI flag so that cargo insta test behaves as we expect
123+
// under normal operation
124+
command.env("CI", "0");
125+
114126
command.current_dir(self.workspace_dir.as_path());
115127
// Use the same target directory as other tests, consistent across test
116128
// run. This makes the compilation much faster (though do some tests
117129
// tread on the toes of others? We could have a different cache for each
118130
// project if so...)
119131
command.env("CARGO_TARGET_DIR", target_dir());
120-
// Turn off CI flag so that cargo insta test behaves as we expect
121-
// under normal operation
122-
command.env("CI", "0");
132+
123133
command
124134
}
125135

0 commit comments

Comments
 (0)