Example #1
0
func TestLegacyIn(t *testing.T) {

	var cat = "cat"
	if isWindows {
		cat = "cmd /c type"
	}
	//// Run

	// in V2 BashOutput accepts an options map

	out, err := RunOutput(cat+" foo.txt", M{"$in": "test"})
	assert.NoError(t, err)
	assert.Equal(t, "asdf", str.Clean(out))

	// need to support V1 though
	out, err = RunOutput(cat+" foo.txt", In{"test"})
	assert.NoError(t, err)
	assert.Equal(t, "asdf", str.Clean(out))

	if isWindows {
		return
	}

	//// Bash

	// in V2 BashOutput accepts an options map
	out, err = BashOutput("cat foo.txt", M{"$in": "test"})
	assert.NoError(t, err)
	assert.Equal(t, "asdf", str.Clean(out))

	// need to support V1 though
	out, err = BashOutput("cat foo.txt", In{"test"})
	assert.NoError(t, err)
	assert.Equal(t, "asdf", str.Clean(out))
}
Example #2
0
func main() {
	// legacy version used tasks/
	godoFiles := []string{"Gododir/Godofile.go", "tasks/Godofile.go"}
	src := ""
	rel := ""
	for _, filename := range godoFiles {
		rel = filename
		filename, err := filepath.Abs(filename)
		if err != nil {
			panic("Could not get absolute path " + filename)
		}
		if !util.FileExists(filename) {
			continue
		}
		src = filename
		break
	}

	if src == "" {
		godo.Usage("")
		fmt.Printf("\n\n%s not found\n", src)
		os.Exit(1)
	}

	exe := buildMain(rel)
	cmd := exe + " " + strings.Join(os.Args[1:], " ")
	cmd = str.Clean(cmd)
	// errors are displayed by tasks

	godo.Run(cmd)
}
Example #3
0
func TestTemplatedCommands(t *testing.T) {
	echo := "echo"
	if isWindows {
		echo = "cmd /c echo"

	}
	// in V2 BashOutput accepts an options map
	out, err := RunOutput(echo+" {{.name}}", M{"name": "oy"})
	assert.NoError(t, err)
	assert.Equal(t, "oy", str.Clean(out))

	if isWindows {
		return
	}

	// in V2 BashOutput accepts an options map
	out, err = BashOutput("echo {{.name}}", M{"name": "oy"})
	assert.NoError(t, err)
	assert.Equal(t, "oy", str.Clean(out))
}
Example #4
0
func TestInheritedRunEnv(t *testing.T) {
	os.Setenv("TEST_RUN_ENV", "fubar")
	SetEnviron("", true)

	var output string

	if isWindows {
		output, _ = RunOutput(`FOO=bar BAH=baz cmd /C "echo %TEST_RUN_ENV% %FOO%"`)
	} else {
		output, _ = RunOutput(`FOO=bar BAH=baz bash -c "echo -n $TEST_RUN_ENV $FOO"`)
	}

	if str.Clean(output) != "fubar bar" {
		t.Error("Environment was not inherited! Got", fmt.Sprintf("%q", output))
	}
}
Example #5
0
// parseStringEnv parse the package Env string and converts it into an
// environment slice.
func parseStringEnv(s string) []string {
	env := []string{}

	if s == "" {
		return env
	}

	s = str.Clean(s)
	argv := str.ToArgv(s)
	for _, kv := range argv {
		if !strings.Contains(kv, "=") {
			continue
		}
		env = append(env, kv)
	}
	return env
}
Example #6
0
func TestInside(t *testing.T) {
	Inside("test", func() {
		var out string
		if isWindows {
			out, _ = RunOutput("foo.cmd")
		} else {
			out, _ = RunOutput("bash foo.sh")
		}

		if str.Clean(out) != "FOOBAR" {
			t.Error("Inside failed. Got", fmt.Sprintf("%q", out))
		}
	})

	version, _ := ioutil.ReadFile("./VERSION.go")
	if !strings.Contains(string(version), "var Version") {
		t.Error("Inside failed to reset work directory")
	}
}