testutil: use the original environment when calling shellcheck

our own test fixtures might have messed up with it, notably
some tests change DBUS_SESSION_BUS_ADDRESS for example
This commit is contained in:
Samuele Pedroni
2020-12-11 14:41:14 +01:00
parent 7ed830a331
commit 2f89acd032

View File

@@ -57,6 +57,8 @@ func shellcheckSeenAlready(script string) bool {
return false
}
var pristineEnv = os.Environ()
func maybeShellcheck(c *check.C, script string, wholeScript io.Reader) {
// MockCommand is used sometimes in SetUptTest, so it adds up
// even for the empty script, don't recheck the essentially same
@@ -70,6 +72,7 @@ func maybeShellcheck(c *check.C, script string, wholeScript io.Reader) {
return
}
cmd := exec.Command(shellcheckPath, "-s", "bash", "-")
cmd.Env = pristineEnv
cmd.Stdin = wholeScript
out, err := cmd.CombinedOutput()
c.Check(err, check.IsNil, check.Commentf("shellcheck failed:\n%s", string(out)))