| 1827 | } |
| 1828 | |
| 1829 | func TestWithEnv_UnsetsAllEnvVarsGivenEmptySlice(t *testing.T) { |
| 1830 | t.Parallel() |
| 1831 | p := script.NewPipe().WithEnv([]string{"ENV1=test1"}).Exec("sh -c 'echo ENV1=$ENV1'") |
| 1832 | want := "ENV1=test1\n" |
| 1833 | got, err := p.String() |
| 1834 | if err != nil { |
| 1835 | t.Fatal(err) |
| 1836 | } |
| 1837 | if got != want { |
| 1838 | t.Fatalf("want %q, got %q", want, got) |
| 1839 | } |
| 1840 | got, err = p.Echo("").WithEnv([]string{}).Exec("sh -c 'echo ENV1=$ENV1'").String() |
| 1841 | if err != nil { |
| 1842 | t.Fatal(err) |
| 1843 | } |
| 1844 | want = "ENV1=\n" |
| 1845 | if got != want { |
| 1846 | t.Errorf("want %q, got %q", want, got) |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | func TestWithEnv_SetsGivenVariablesForSubsequentExec(t *testing.T) { |
| 1851 | t.Parallel() |