Exemple #1
0
func TestComplexValue(t *testing.T) {
	vanish.Env(func() {
		fs := flag.NewFlagSet("f", flag.ContinueOnError)
		fs.Var(envflag.NewValue(), "x", "tutu")
		os.Unsetenv("A")

		assert.Nil(t, fs.Parse([]string{"-x", "A=42 B=17"}))

		assert.Equal(t, "42 B=17", os.Getenv("A"))
	})
}
Exemple #2
0
func TestMultipleValues(t *testing.T) {
	vanish.Env(func() {
		fs := flag.NewFlagSet("f", flag.ContinueOnError)
		fs.Var(envflag.NewValue(), "yo", "tutu")

		os.Unsetenv("A")
		os.Unsetenv("B")
		os.Unsetenv("C")

		err := fs.Parse([]string{
			"-yo", "A=42", "-yo", "B=yo", "-yo", "C=true", "-yo", "A=43",
		})

		assert.Nil(t, err)
		assert.Equal(t, "43", os.Getenv("A"))
		assert.Equal(t, "yo", os.Getenv("B"))
		assert.Equal(t, "true", os.Getenv("C"))
	})
}
Exemple #3
0
func testEnv(t *testing.T, fn func(d1, d2 string)) {
	vanish.Env(func() {
		vanish.Dir(func(dir1 string) {
			touch(t, dir1, "a-exe", true)
			touch(t, dir1, "b-exe", true)
			touch(t, dir1, "c", false)
			touch(t, dir1, "e", false)
			touch(t, dir1, "both", true)

			vanish.Dir(func(dir2 string) {
				touch(t, dir2, "a", false)
				touch(t, dir2, "b-exe", false)
				touch(t, dir2, "e", true)
				touch(t, dir2, "both", true)

				os.Setenv("PATH", fmt.Sprintf("%s:%s", dir1, dir2))

				fn(dir1, dir2)
			})
		})
	})
}