github.com/seh/gb@v0.4.4-0.20160724065125-065d2b2b1ba1/cmd/gb/depfile_test.go (about) 1 package main_test 2 3 import ( 4 "path/filepath" 5 "runtime" 6 "testing" 7 ) 8 9 func TestMissingDepfile(t *testing.T) { 10 gb := T{T: t} 11 defer gb.cleanup() 12 13 gb.tempDir("src/github.com/user/proj") 14 gb.tempFile("src/github.com/user/proj/main.go", `package main 15 16 import "fmt" 17 import "github.com/a/b" // would be in depfile 18 19 func main() { 20 fmt.Println(b.B) 21 } 22 `) 23 24 gb.cd(gb.tempdir) 25 gb.runFail("build") 26 gb.grepStderr(`FATAL: command "build" failed:.+import "github.com/a/b": not found`, `import "github.com/a/b": not found`) 27 } 28 29 func TestDepfileVersionPresent(t *testing.T) { 30 gb := T{T: t} 31 defer gb.cleanup() 32 33 gb.tempDir("src/github.com/user/proj/a/") 34 gb.tempFile("src/github.com/user/proj/a/main.go", `package main 35 36 import "github.com/a/b" 37 38 func main() { 39 println(b.B) 40 } 41 `) 42 gb.tempFile("depfile", ` 43 github.com/a/b version=2.0.0 44 `) 45 46 gbhome := gb.tempDir(".gb") 47 gb.tempFile(".gb/cache/f51babb8d8973d3796013755348c5a072f1a2e47/src/github.com/a/b/b.go", `package b; const B=1`) 48 gb.setenv("GB_HOME", gbhome) 49 50 gb.cd(gb.tempdir) 51 gb.run("build") 52 name := "a" 53 if runtime.GOOS == "windows" { 54 name += ".exe" 55 } 56 gb.wantExecutable(gb.path("bin", name), "expected $PROJECT/bin/"+name) 57 } 58 59 func TestDepfileFetchMissingByVersion(t *testing.T) { 60 if testing.Short() { 61 t.Skip("skipping test during -short") 62 } 63 64 gb := T{T: t} 65 defer gb.cleanup() 66 67 gb.tempDir("src/github.com/user/proj/a/") 68 gb.tempFile("src/github.com/user/proj/a/main.go", `package main 69 70 import "github.com/pkg/profile" 71 72 func main() { 73 defer profile.Start().Stop() 74 } 75 `) 76 gb.tempFile("depfile", ` 77 github.com/pkg/profile version=1.1.0 78 `) 79 80 gb.cd(gb.tempdir) 81 gbhome := gb.tempDir(".gb") 82 gb.setenv("GB_HOME", gbhome) 83 gb.run("build") 84 name := "a" 85 if runtime.GOOS == "windows" { 86 name += ".exe" 87 } 88 gb.wantExecutable(gb.path("bin", name), "expected $PROJECT/bin/"+name) 89 gb.grepStdout("^fetching github.com/pkg/profile", "fetching pkg/profile not found") 90 gb.mustExist(filepath.Join(gbhome, "cache", "8fd41ea4fa48cd8435005bad56faeefdc57a25d6", "src", "github.com", "pkg", "profile", "profile.go")) 91 } 92 93 func TestDepfileTagPresent(t *testing.T) { 94 gb := T{T: t} 95 defer gb.cleanup() 96 97 gb.tempDir("src/github.com/user/proj/a/") 98 gb.tempFile("src/github.com/user/proj/a/main.go", `package main 99 100 import "github.com/a/b" 101 102 func main() { 103 println(b.B) 104 } 105 `) 106 gb.tempFile("depfile", ` 107 github.com/a/b tag=2.0.0 108 `) 109 110 gbhome := gb.tempDir(".gb") 111 gb.tempFile(".gb/cache/f51babb8d8973d3796013755348c5a072f1a2e47/src/github.com/a/b/b.go", `package b; const B=1`) 112 gb.setenv("GB_HOME", gbhome) 113 114 gb.cd(gb.tempdir) 115 gb.run("build") 116 name := "a" 117 if runtime.GOOS == "windows" { 118 name += ".exe" 119 } 120 gb.wantExecutable(gb.path("bin", name), "expected $PROJECT/bin/"+name) 121 } 122 123 func TestDepfileFetchMissingByTag(t *testing.T) { 124 if testing.Short() { 125 t.Skip("skipping test during -short") 126 } 127 128 gb := T{T: t} 129 defer gb.cleanup() 130 131 gb.tempDir("src/github.com/user/proj/a/") 132 gb.tempFile("src/github.com/user/proj/a/main.go", `package main 133 134 import "github.com/pkg/profile" 135 136 func main() { 137 defer profile.Start().Stop() 138 } 139 `) 140 gb.tempFile("depfile", ` 141 github.com/pkg/profile tag=v1.1.0 142 `) 143 144 gb.cd(gb.tempdir) 145 gbhome := gb.tempDir(".gb") 146 gb.setenv("GB_HOME", gbhome) 147 gb.run("build") 148 name := "a" 149 if runtime.GOOS == "windows" { 150 name += ".exe" 151 } 152 gb.wantExecutable(gb.path("bin", name), "expected $PROJECT/bin/"+name) 153 gb.grepStdout("^fetching github.com/pkg/profile", "fetching pkg/profile not found") 154 gb.mustExist(filepath.Join(gbhome, "cache", "e693c641ace92b5910c4a64d3241128094f74f19", "src", "github.com", "pkg", "profile", "profile.go")) 155 }