Esempio n. 1
0
// Runs before other test methods
func TestMain(m *testing.M) {
	// set up
	path, err := ioutil.TempDir("", "golang_cmd_test__")

	if err != nil {
		panic(err)
	}

	err = os.Chdir(path)

	if err != nil {
		panic(err)
	}

	// This is due to lib.init() running before TestMain()
	// Working dir is incorrect until corrected- will move to TestMain()
	d, _ := os.Getwd()
	// Ensures that the correct project dir is being called 100% of the time
	err = lib.SetProjectDirectory(d)

	if err != nil {
		panic(err)
	}

	r := m.Run() // run tests

	// tear down
	err = os.RemoveAll(path)

	if err != nil {
		panic(err)
	}

	os.Exit(r)
}
Esempio n. 2
0
File: init.go Progetto: massmep/env
func initRun(args []string) (err error) {
	if len(args) == 0 {
		return lib.Error("A name is required!")
	}

	d, err := os.Getwd()

	if err != nil {
		return
	}

	err = lib.SetProjectDirectory(d + seperator + args[0])

	if err != nil {
		return
	}

	err = createAllProjectDirectories(args[0], d)

	// if there is an error, remove the created directories
	if err != nil {
		os.RemoveAll(d + seperator + args[0])
		return
	}

	return
}
Esempio n. 3
0
func TestAddingPackage(t *testing.T) {
	// Init's a project in wd before adding a package
	// Sets dir to newly created project
	err := InitCommand.Run([]string{"add_test"})

	if err != nil {
		t.Error(err)
	}

	d, _ := os.Getwd() // If d == nil, SetProjDir will cause an exception
	err = lib.SetProjectDirectory(d + seperator + "add_test")

	if err != nil {
		t.Error(err)
	}

	err = AddCommand.Run([]string{"package", "test"})

	if err != nil {
		t.Error(err)
	}
}