goose: read tests from testdata

Since tests are all written in terms of Go source, it makes tests easier
to write.  They still need to be arranged in a GOPATH for go build, but
tests that just call Generate can operate in-place because I've faked
the filesystem.

Reviewed-by: Tuo Shan <shantuo@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
Ross Light
2018-03-29 15:17:58 -07:00
parent c9506b42e5
commit b92ac73ae3
32 changed files with 578 additions and 331 deletions

View File

@@ -0,0 +1,20 @@
package main
import "fmt"
func main() {
fmt.Println(injectFooBar())
}
type Foo int
type FooBar int
//goose:provide Set
func provideFoo() Foo {
return 41
}
//goose:provide Set
func provideFooBar(foo Foo) FooBar {
return FooBar(foo) + 1
}

View File

@@ -0,0 +1,7 @@
//+build gooseinject
package main
//goose:use Set
func injectFooBar() FooBar

1
internal/goose/testdata/Chain/out.txt vendored Normal file
View File

@@ -0,0 +1 @@
42

1
internal/goose/testdata/Chain/pkg vendored Normal file
View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,21 @@
package main
import "fmt"
func main() {
fmt.Println(injectFooBar(40))
}
type Foo int
type Bar int
type FooBar int
//goose:provide Set
func provideBar() Bar {
return 2
}
//goose:provide Set
func provideFooBar(foo Foo, bar Bar) FooBar {
return FooBar(foo) + FooBar(bar)
}

View File

@@ -0,0 +1,7 @@
//+build gooseinject
package main
//goose:use Set
func injectFooBar(foo Foo) FooBar

View File

@@ -0,0 +1 @@
42

View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,23 @@
package main
import "fmt"
func main() {
// I'm on the fence as to whether this should be an error (versus an
// override). For now, I will make it an error that can be relaxed
// later.
fmt.Println(injectBar(40))
}
type Foo int
type Bar int
//goose:provide Set
func provideFoo() Foo {
return -888
}
//goose:provide Set
func provideBar(foo Foo) Bar {
return 2
}

View File

@@ -0,0 +1,7 @@
//+build gooseinject
package main
//goose:use Set
func injectBar(foo Foo) Bar

View File

@@ -0,0 +1 @@
ERROR

View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,14 @@
package main
import "fmt"
func main() {
fmt.Println(injectedMessage())
}
//goose:provide Set
// provideMessage provides a friendly user greeting.
func provideMessage() string {
return "Hello, World!"
}

View File

@@ -0,0 +1,5 @@
//+build gooseinject
package main
func injectedMessage() string

View File

@@ -0,0 +1 @@
ERROR

View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,14 @@
package main
import "fmt"
func main() {
fmt.Println(injectedMessage())
}
//goose:provide
// provideMessage provides a friendly user greeting.
func provideMessage() string {
return "Hello, World!"
}

View File

@@ -0,0 +1,7 @@
//+build gooseinject
package main
//goose:use provideMessage
func injectedMessage() string

View File

@@ -0,0 +1 @@
Hello, World!

View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}

View File

@@ -0,0 +1 @@
Hello, World!

1
internal/goose/testdata/NoopBuild/pkg vendored Normal file
View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,22 @@
package main
import "errors"
import "fmt"
import "strings"
func main() {
foo, err := injectFoo()
fmt.Println(foo) // should be zero, the injector should ignore provideFoo's return value.
if err == nil {
fmt.Println("<nil>")
} else {
fmt.Println(strings.Contains(err.Error(), "there is no Foo"))
}
}
type Foo int
//goose:provide Set
func provideFoo() (Foo, error) {
return 42, errors.New("there is no Foo")
}

View File

@@ -0,0 +1,7 @@
//+build gooseinject
package main
//goose:use Set
func injectFoo() (Foo, error)

View File

@@ -0,0 +1,2 @@
0
true

View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,26 @@
package main
import "fmt"
func main() {
fmt.Println(injectFooBar())
}
type Foo int
type Bar int
type FooBar int
//goose:provide Set
func provideFoo() Foo {
return 40
}
//goose:provide Set
func provideBar() Bar {
return 2
}
//goose:provide Set
func provideFooBar(foo Foo, bar Bar) FooBar {
return FooBar(foo) + FooBar(bar)
}

View File

@@ -0,0 +1,7 @@
//+build gooseinject
package main
//goose:use Set
func injectFooBar() FooBar

View File

@@ -0,0 +1 @@
42

1
internal/goose/testdata/TwoDeps/pkg vendored Normal file
View File

@@ -0,0 +1 @@
foo