Clear env in all commands
This commit is contained in:
parent
8fc9bb3a29
commit
8d1db6d970
40
src/shell.rs
40
src/shell.rs
|
|
@ -54,6 +54,7 @@ mod tests {
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use seq_macro::seq;
|
use seq_macro::seq;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
macro_rules! with_opts_size {
|
macro_rules! with_opts_size {
|
||||||
|
|
@ -99,12 +100,17 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_cmd(cmd: &str) -> Command {
|
fn make_cmd(cmd: &str) -> Command {
|
||||||
let home = tempfile::tempdir().unwrap();
|
let tempdir = tempfile::tempdir().unwrap();
|
||||||
let home = home.path();
|
let tempdir = tempdir.path().to_str().unwrap();
|
||||||
let path = env::var_os("PATH").unwrap_or_default();
|
|
||||||
|
let mut vars = env::vars()
|
||||||
|
.filter(|(k, _)| k == "PATH" || k.starts_with("PYTHON"))
|
||||||
|
.collect::<HashMap<_, _>>();
|
||||||
|
vars.insert("HOME".to_string(), tempdir.to_string());
|
||||||
|
vars.insert("PYLINTHOME".to_string(), tempdir.to_string());
|
||||||
|
|
||||||
let mut cmd = Command::new(cmd);
|
let mut cmd = Command::new(cmd);
|
||||||
cmd.env_clear().env("HOME", home).env("PATH", path);
|
cmd.env_clear().envs(vars);
|
||||||
|
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +122,7 @@ mod tests {
|
||||||
fn bash_bash_#i() {
|
fn bash_bash_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Bash(opts).render().unwrap();
|
let source = Bash(opts).render().unwrap();
|
||||||
Command::new("bash")
|
make_cmd("bash")
|
||||||
.args(&["-c", &source, "--noediting", "--noprofile", "--norc"])
|
.args(&["-c", &source, "--noediting", "--noprofile", "--norc"])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
@ -128,7 +134,7 @@ mod tests {
|
||||||
fn bash_shellcheck_#i() {
|
fn bash_shellcheck_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Bash(opts).render().unwrap();
|
let source = Bash(opts).render().unwrap();
|
||||||
Command::new("shellcheck")
|
make_cmd("shellcheck")
|
||||||
.args(&["--enable", "all", "--shell", "bash", "-"])
|
.args(&["--enable", "all", "--shell", "bash", "-"])
|
||||||
.write_stdin(source)
|
.write_stdin(source)
|
||||||
.assert()
|
.assert()
|
||||||
|
|
@ -144,7 +150,7 @@ mod tests {
|
||||||
source.push('\n');
|
source.push('\n');
|
||||||
// FIXME: caused by <https://github.com/djc/askama/issues/377>
|
// FIXME: caused by <https://github.com/djc/askama/issues/377>
|
||||||
let source = source.as_str().trim_start();
|
let source = source.as_str().trim_start();
|
||||||
Command::new("shfmt")
|
make_cmd("shfmt")
|
||||||
.args(&["-d", "-s", "-ln", "bash", "-i", "4", "-ci", "-"])
|
.args(&["-d", "-s", "-ln", "bash", "-i", "4", "-ci", "-"])
|
||||||
.write_stdin(source)
|
.write_stdin(source)
|
||||||
.assert()
|
.assert()
|
||||||
|
|
@ -171,7 +177,7 @@ mod tests {
|
||||||
fn posix_bashposix_#i() {
|
fn posix_bashposix_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Posix(opts).render().unwrap();
|
let source = Posix(opts).render().unwrap();
|
||||||
let assert = Command::new("bash")
|
let assert = make_cmd("bash")
|
||||||
.args(&["--posix", "-c", &source, "--noediting", "--noprofile", "--norc"])
|
.args(&["--posix", "-c", &source, "--noediting", "--noprofile", "--norc"])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
@ -186,7 +192,7 @@ mod tests {
|
||||||
fn posix_dash_#i() {
|
fn posix_dash_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Posix(opts).render().unwrap();
|
let source = Posix(opts).render().unwrap();
|
||||||
let assert = Command::new("dash")
|
let assert = make_cmd("dash")
|
||||||
.args(&["-c", &source])
|
.args(&["-c", &source])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
@ -201,7 +207,7 @@ mod tests {
|
||||||
fn posix_shellcheck_#i() {
|
fn posix_shellcheck_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Posix(opts).render().unwrap();
|
let source = Posix(opts).render().unwrap();
|
||||||
Command::new("shellcheck")
|
make_cmd("shellcheck")
|
||||||
.args(&["--enable", "all", "--shell", "sh", "-"])
|
.args(&["--enable", "all", "--shell", "sh", "-"])
|
||||||
.write_stdin(source)
|
.write_stdin(source)
|
||||||
.assert()
|
.assert()
|
||||||
|
|
@ -217,7 +223,7 @@ mod tests {
|
||||||
source.push('\n');
|
source.push('\n');
|
||||||
// FIXME: caused by <https://github.com/djc/askama/issues/377>
|
// FIXME: caused by <https://github.com/djc/askama/issues/377>
|
||||||
let source = source.as_str().trim_start();
|
let source = source.as_str().trim_start();
|
||||||
Command::new("shfmt")
|
make_cmd("shfmt")
|
||||||
.args(&["-d", "-s", "-ln", "posix", "-i", "4", "-ci", "-"])
|
.args(&["-d", "-s", "-ln", "posix", "-i", "4", "-ci", "-"])
|
||||||
.write_stdin(source)
|
.write_stdin(source)
|
||||||
.assert()
|
.assert()
|
||||||
|
|
@ -230,7 +236,7 @@ mod tests {
|
||||||
fn powershell_pwsh_#i() {
|
fn powershell_pwsh_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = PowerShell(opts).render().unwrap();
|
let source = PowerShell(opts).render().unwrap();
|
||||||
Command::new("pwsh")
|
make_cmd("pwsh")
|
||||||
.args(&["-Command", &source, "-NoLogo", "-NonInteractive", "-NoProfile"])
|
.args(&["-Command", &source, "-NoLogo", "-NonInteractive", "-NoProfile"])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
@ -243,7 +249,7 @@ mod tests {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let mut source = Xonsh(opts).render().unwrap();
|
let mut source = Xonsh(opts).render().unwrap();
|
||||||
source.push('\n');
|
source.push('\n');
|
||||||
Command::new("black")
|
make_cmd("black")
|
||||||
.args(&["--check", "--diff", "-"])
|
.args(&["--check", "--diff", "-"])
|
||||||
.write_stdin(source)
|
.write_stdin(source)
|
||||||
.assert()
|
.assert()
|
||||||
|
|
@ -255,7 +261,7 @@ mod tests {
|
||||||
fn xonsh_mypy_#i() {
|
fn xonsh_mypy_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Xonsh(opts).render().unwrap();
|
let source = Xonsh(opts).render().unwrap();
|
||||||
Command::new("mypy")
|
make_cmd("mypy")
|
||||||
.args(&["--command", &source])
|
.args(&["--command", &source])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
@ -267,7 +273,7 @@ mod tests {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let mut source = Xonsh(opts).render().unwrap();
|
let mut source = Xonsh(opts).render().unwrap();
|
||||||
source.push('\n');
|
source.push('\n');
|
||||||
Command::new("pylint")
|
make_cmd("pylint")
|
||||||
.args(&["--from-stdin", "zoxide"])
|
.args(&["--from-stdin", "zoxide"])
|
||||||
.write_stdin(source)
|
.write_stdin(source)
|
||||||
.assert()
|
.assert()
|
||||||
|
|
@ -281,7 +287,7 @@ mod tests {
|
||||||
fn xonsh_xonsh_#i() {
|
fn xonsh_xonsh_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Xonsh(opts).render().unwrap();
|
let source = Xonsh(opts).render().unwrap();
|
||||||
Command::new("xonsh")
|
make_cmd("xonsh")
|
||||||
.args(&["-c", &source, "--no-rc"])
|
.args(&["-c", &source, "--no-rc"])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
@ -293,7 +299,7 @@ mod tests {
|
||||||
fn zsh_zsh_#i() {
|
fn zsh_zsh_#i() {
|
||||||
let opts = dbg!(&opts()[i]);
|
let opts = dbg!(&opts()[i]);
|
||||||
let source = Zsh(opts).render().unwrap();
|
let source = Zsh(opts).render().unwrap();
|
||||||
Command::new("zsh")
|
make_cmd("zsh")
|
||||||
.args(&["-c", &source, "--no-rcs"])
|
.args(&["-c", &source, "--no-rcs"])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue