diff --git a/cmd/nixtest/main.go b/cmd/nixtest/main.go index 4e11cac..e092788 100644 --- a/cmd/nixtest/main.go +++ b/cmd/nixtest/main.go @@ -106,7 +106,11 @@ func buildAndRun(derivation string) (exitCode int, stdout bytes.Buffer, stderr b 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.Stderr = &stderr @@ -296,6 +300,7 @@ var ( ) updateSnapshots *bool = flag.Bool("update-snapshots", false, "Update all snapshots") 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() { diff --git a/flake.nix b/flake.nix index 1f81625..5eb6c64 100644 --- a/flake.nix +++ b/flake.nix @@ -83,7 +83,9 @@ type = "script"; script = '' echo Test something here - exit 1 + # required in pure mode: + export PATH="${lib.makeBinPath [pkgs.gnugrep]}" + grep -q "test" ${builtins.toFile "test" "test"} ''; } ];