@@ -61,7 +61,7 @@ func testmain(m *testing.M) int {
6161}
6262
6363func TestTransitiveDepCache (t * testing.T ) {
64- cache , err := internal .OutputDebug ("go" , "env" , "gocache " )
64+ cache , err := internal .OutputDebug ("go" , "env" , "GOCACHE " )
6565 if err != nil {
6666 t .Fatal (err )
6767 }
@@ -108,6 +108,61 @@ func TestTransitiveDepCache(t *testing.T) {
108108 }
109109}
110110
111+ func TestTransitiveHashFast (t * testing.T ) {
112+ cache , err := internal .OutputDebug ("go" , "env" , "GOCACHE" )
113+ if err != nil {
114+ t .Fatal (err )
115+ }
116+ if cache == "" {
117+ t .Skip ("skipping hashfast tests on go version without cache" )
118+ }
119+
120+ // Test that if we change a transitive dep, that we don't recompile.
121+ // We intentionally run the first time without hashfast to ensure that
122+ // we recompile the binary with the current code.
123+ stdout := & bytes.Buffer {}
124+ stderr := & bytes.Buffer {}
125+ inv := Invocation {
126+ Stderr : stderr ,
127+ Stdout : stdout ,
128+ Dir : "testdata/transitiveDeps" ,
129+ Args : []string {"Run" },
130+ }
131+ code := Invoke (inv )
132+ if code != 0 {
133+ t .Fatalf ("got code %v, err: %s" , code , stderr )
134+ }
135+ expected := "woof\n "
136+ if actual := stdout .String (); actual != expected {
137+ t .Fatalf ("expected %q but got %q" , expected , actual )
138+ }
139+
140+ // ok, so baseline, the generated and cached binary should do "woof"
141+ // now change out the transitive dependency that does the output
142+ // so that it produces different output.
143+ if err := os .Rename ("testdata/transitiveDeps/dep/dog.go" , "testdata/transitiveDeps/dep/dog.notgo" ); err != nil {
144+ t .Fatal (err )
145+ }
146+ defer os .Rename ("testdata/transitiveDeps/dep/dog.notgo" , "testdata/transitiveDeps/dep/dog.go" )
147+ if err := os .Rename ("testdata/transitiveDeps/dep/cat.notgo" , "testdata/transitiveDeps/dep/cat.go" ); err != nil {
148+ t .Fatal (err )
149+ }
150+ defer os .Rename ("testdata/transitiveDeps/dep/cat.go" , "testdata/transitiveDeps/dep/cat.notgo" )
151+ stderr .Reset ()
152+ stdout .Reset ()
153+ inv .HashFast = true
154+ code = Invoke (inv )
155+ if code != 0 {
156+ t .Fatalf ("got code %v, err: %s" , code , stderr )
157+ }
158+ // we should still get woof, even though the dependency was changed to
159+ // return "meow", because we're only hashing the top level magefiles, not
160+ // dependencies.
161+ if actual := stdout .String (); actual != expected {
162+ t .Fatalf ("expected %q but got %q" , expected , actual )
163+ }
164+ }
165+
111166func TestListMagefilesMain (t * testing.T ) {
112167 buf := & bytes.Buffer {}
113168 files , err := Magefiles ("testdata/mixed_main_files" , "" , "" , "go" , buf , false )
0 commit comments