feat: add pure mode which unsets env variables before script tests

This commit is contained in:
technofab 2025-05-31 19:06:40 +02:00
parent 7bb5c65259
commit 3ff5b358d5
2 changed files with 9 additions and 2 deletions

View file

@ -106,7 +106,11 @@ func buildAndRun(derivation string) (exitCode int, stdout bytes.Buffer, stderr b
return return
} }
cmd := exec.Command("bash", path) args := []string{"bash", path}
if *pure {
args = append([]string{"env", "-i"}, args...)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr
@ -296,6 +300,7 @@ var (
) )
updateSnapshots *bool = flag.Bool("update-snapshots", false, "Update all snapshots") updateSnapshots *bool = flag.Bool("update-snapshots", false, "Update all snapshots")
skipPattern *string = flag.String("skip", "", "Regular expression to skip (e.g., 'test-.*|.*-b')") skipPattern *string = flag.String("skip", "", "Regular expression to skip (e.g., 'test-.*|.*-b')")
pure *bool = flag.Bool("pure", false, "Unset all env vars before running script tests")
) )
func main() { func main() {

View file

@ -83,7 +83,9 @@
type = "script"; type = "script";
script = '' script = ''
echo Test something here echo Test something here
exit 1 # required in pure mode:
export PATH="${lib.makeBinPath [pkgs.gnugrep]}"
grep -q "test" ${builtins.toFile "test" "test"}
''; '';
} }
]; ];