github.com/golang/dep@v0.5.4/cmd/dep/dep_test.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 "os/exec" 11 "path/filepath" 12 "testing" 13 14 "github.com/golang/dep/internal/test" 15 ) 16 17 // The TestMain function creates a dep command for testing purposes and 18 // deletes it after the tests have been run. 19 // Most of this is taken from https://github.com/golang/go/blob/master/src/cmd/go/go_test.go and reused here. 20 func TestMain(m *testing.M) { 21 args := []string{"build", "-o", "testdep" + test.ExeSuffix} 22 out, err := exec.Command("go", args...).CombinedOutput() 23 if err != nil { 24 fmt.Fprintf(os.Stderr, "building testdep failed: %v\n%s", err, out) 25 os.Exit(2) 26 } 27 28 // Don't let these environment variables confuse the test. 29 os.Unsetenv("GOPATH") 30 os.Unsetenv("GIT_ALLOW_PROTOCOL") 31 if home, ccacheDir := os.Getenv("HOME"), os.Getenv("CCACHE_DIR"); home != "" && ccacheDir == "" { 32 // On some systems the default C compiler is ccache. 33 // Setting HOME to a non-existent directory will break 34 // those systems. Set CCACHE_DIR to cope. Issue 17668. 35 os.Setenv("CCACHE_DIR", filepath.Join(home, ".ccache")) 36 } 37 os.Setenv("HOME", "/test-dep-home-does-not-exist") 38 r := m.Run() 39 40 os.Remove("testdep" + test.ExeSuffix) 41 42 os.Exit(r) 43 }