goose: use marker functions instead of comments

To avoid making this CL too large, I did not migrate the existing goose
comments through the repository.  This will be addressed in a subsequent
CL.

Reviewed-by: Tuo Shan <shantuo@google.com>
This commit is contained in:
Ross Light
2018-04-27 13:44:54 -04:00
parent 13698e656a
commit f8e446fa17
59 changed files with 713 additions and 983 deletions

View File

@@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"codename/goose"
)
func main() {
fmt.Println(injectFooBar())
@@ -9,12 +13,14 @@ func main() {
type Foo int
type FooBar int
//goose:provide Set
var Set = goose.NewSet(
provideFoo,
provideFooBar)
func provideFoo() Foo {
return 41
}
//goose:provide Set
func provideFooBar(foo Foo) FooBar {
return FooBar(foo) + 1
}

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectFooBar() FooBar
func injectFooBar() FooBar {
panic(goose.Use(Set))
}

View File

@@ -1,6 +1,8 @@
package main
import "fmt"
import (
"fmt"
)
func main() {
bar, cleanup := injectBar()
@@ -12,14 +14,12 @@ func main() {
type Foo int
type Bar int
//goose:provide Foo
func provideFoo() (*Foo, func()) {
foo := new(Foo)
*foo = 42
return foo, func() { *foo = 0 }
}
//goose:provide Bar
func provideBar(foo *Foo) (*Bar, func()) {
bar := new(Bar)
*bar = 77

View File

@@ -2,7 +2,10 @@
package main
//goose:use Foo
//goose:use Bar
import (
"codename/goose"
)
func injectBar() (*Bar, func())
func injectBar() (*Bar, func()) {
panic(goose.Use(provideFoo, provideBar))
}

View File

@@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(injectedMessage())
}
var myFakeSet struct{}

View File

@@ -0,0 +1,11 @@
//+build gooseinject
package main
import (
"codename/goose"
)
func injectedMessage() string {
panic(goose.Use(myFakeSet))
}

View File

@@ -3,7 +3,8 @@ package main
import (
"fmt"
_ "foo"
"codename/goose"
"foo"
)
func main() {
@@ -16,11 +17,12 @@ func (b *Bar) Foo() string {
return string(*b)
}
//goose:provide
func provideBar() *Bar {
b := new(Bar)
*b = "Hello, World!"
return b
}
//goose:bind provideBar "foo".Fooer *Bar
var Set = goose.NewSet(
provideBar,
goose.Bind(foo.Fooer(nil), (*Bar)(nil)))

View File

@@ -2,8 +2,11 @@
package main
import "foo"
import (
"codename/goose"
"foo"
)
//goose:use provideBar
func injectFooer() foo.Fooer
func injectFooer() foo.Fooer {
panic(goose.Use(Set))
}

View File

@@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"codename/goose"
)
func main() {
fmt.Println(injectFooBar(40))
@@ -10,12 +14,14 @@ type Foo int
type Bar int
type FooBar int
//goose:provide Set
var Set = goose.NewSet(
provideBar,
provideFooBar)
func provideBar() Bar {
return 2
}
//goose:provide Set
func provideFooBar(foo Foo, bar Bar) FooBar {
return FooBar(foo) + FooBar(bar)
}

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectFooBar(foo Foo) FooBar
func injectFooBar(foo Foo) FooBar {
panic(goose.Use(Set))
}

View File

@@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"codename/goose"
)
func main() {
// I'm on the fence as to whether this should be an error (versus an
@@ -12,12 +16,14 @@ func main() {
type Foo int
type Bar int
//goose:provide Set
var Set = goose.NewSet(
provideFoo,
provideBar)
func provideFoo() Foo {
return -888
}
//goose:provide Set
func provideBar(foo Foo) Bar {
return 2
}

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectBar(foo Foo) Bar
func injectBar(foo Foo) Bar {
panic(goose.Use(Set))
}

View File

@@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"codename/goose"
)
func main() {
fmt.Println(injectFooer().Foo())
@@ -16,11 +20,12 @@ func (b *Bar) Foo() string {
return string(*b)
}
//goose:provide
func provideBar() *Bar {
b := new(Bar)
*b = "Hello, World!"
return b
}
//goose:bind provideBar Fooer *Bar
var Set = goose.NewSet(
provideBar,
goose.Bind(Fooer(nil), (*Bar)(nil)))

View File

@@ -2,6 +2,10 @@
package main
//goose:use provideBar
import (
"codename/goose"
)
func injectFooer() Fooer
func injectFooer() Fooer {
panic(goose.Use(Set))
}

View File

@@ -28,8 +28,6 @@ func (b *Bar) Foo() string {
return string(*b)
}
//goose:provide
//goose:bind provideBar Fooer *Bar
func provideBar() *Bar {
mu.Lock()
provideBarCalls++
@@ -44,7 +42,6 @@ var (
provideBarCalls int
)
//goose:provide
func provideFooBar(fooer Fooer, bar *Bar) FooBar {
return FooBar{fooer, bar}
}

View File

@@ -2,7 +2,13 @@
package main
//goose:use provideBar
//goose:use provideFooBar
import (
"codename/goose"
)
func injectFooBar() FooBar
func injectFooBar() FooBar {
panic(goose.Use(
provideBar,
provideFooBar,
goose.Bind(Fooer(nil), (*Bar)(nil))))
}

View File

@@ -1,14 +0,0 @@
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

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

View File

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

View File

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

View File

@@ -1 +0,0 @@
42

View File

@@ -1 +0,0 @@
foo

View File

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

View File

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

View File

@@ -1 +0,0 @@
42

View File

@@ -1 +0,0 @@
foo

View File

@@ -17,8 +17,6 @@ func main() {
fmt.Println(c)
}
//goose:provide
func provide(ctx stdcontext.Context) (context, error) {
return context{}, nil
}

View File

@@ -4,8 +4,10 @@ package main
import (
stdcontext "context"
"codename/goose"
)
//goose:use provide
func inject(context stdcontext.Context, err struct{}) (context, error)
func inject(context stdcontext.Context, err struct{}) (context, error) {
panic(goose.Use(provide))
}

View File

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

View File

@@ -2,6 +2,10 @@
package main
//goose:use provideMessage
import (
"codename/goose"
)
func injectedMessage() string
func injectedMessage() string {
panic(goose.Use(provideMessage))
}

View File

@@ -16,7 +16,6 @@ func (b Bar) Foo() string {
return string(b)
}
//goose:provide
func provideBar() Bar {
return "Hello, World!"
}

View File

@@ -2,6 +2,10 @@
package main
//goose:use provideBar
import (
"codename/goose"
)
func injectFooer() Fooer
func injectFooer() Fooer {
panic(goose.Use(provideBar))
}

View File

@@ -17,8 +17,6 @@ func main() {
fmt.Println(c)
}
//goose:provide
func provide(ctx stdcontext.Context) (context, error) {
return context{}, nil
}

View File

@@ -4,11 +4,13 @@ package main
import (
stdcontext "context"
"codename/goose"
)
// The notable characteristic of this test is that there are no
// parameter names on the inject stub.
//goose:use provide
func inject(stdcontext.Context, struct{}) (context, error)
func inject(stdcontext.Context, struct{}) (context, error) {
panic(goose.Use(provide))
}

View File

@@ -25,14 +25,12 @@ type Foo int
type Bar int
type Baz int
//goose:provide Foo
func provideFoo() (*Foo, func()) {
foo := new(Foo)
*foo = 42
return foo, func() { *foo = 0; cleanedFoo = true }
}
//goose:provide Bar
func provideBar(foo *Foo) (*Bar, func(), error) {
bar := new(Bar)
*bar = 77
@@ -45,7 +43,6 @@ func provideBar(foo *Foo) (*Bar, func(), error) {
}, nil
}
//goose:provide Baz
func provideBaz(bar *Bar) (Baz, error) {
return 0, errors.New("bork!")
}

View File

@@ -2,8 +2,10 @@
package main
//goose:use Foo
//goose:use Bar
//goose:use Baz
import (
"codename/goose"
)
func injectBaz() (Baz, func(), error)
func injectBaz() (Baz, func(), error) {
panic(goose.Use(provideFoo, provideBar, provideBaz))
}

View File

@@ -2,7 +2,6 @@ package bar
type Bar int
//goose:provide Bar
func ProvideBar() Bar {
return 1
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"bar"
"codename/goose"
)
func main() {
@@ -13,14 +14,15 @@ func main() {
type Foo int
type FooBar int
//goose:provide Set
var Set = goose.NewSet(
provideFoo,
bar.ProvideBar,
provideFooBar)
func provideFoo() Foo {
return 41
}
//goose:import Set "bar".Bar
//goose:provide Set
func provideFooBar(foo Foo, barVal bar.Bar) FooBar {
return FooBar(foo) + FooBar(barVal)
}

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectFooBar() FooBar
func injectFooBar() FooBar {
panic(goose.Use(Set))
}

View File

@@ -1,8 +1,12 @@
package main
import "errors"
import "fmt"
import "strings"
import (
"errors"
"fmt"
"strings"
"codename/goose"
)
func main() {
foo, err := injectFoo()
@@ -16,7 +20,8 @@ func main() {
type Foo int
//goose:provide Set
func provideFoo() (Foo, error) {
return 42, errors.New("there is no Foo")
}
var Set = goose.NewSet(provideFoo)

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectFoo() (Foo, error)
func injectFoo() (Foo, error) {
panic(goose.Use(Set))
}

View File

@@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"codename/goose"
)
func main() {
fb := injectFooBar()
@@ -10,18 +14,20 @@ func main() {
type Foo int
type Bar int
//goose:provide Set
type FooBar struct {
Foo Foo
Bar Bar
}
//goose:provide Set
func provideFoo() Foo {
return 41
}
//goose:provide Set
func provideBar() Bar {
return 1
}
var Set = goose.NewSet(
FooBar{},
provideFoo,
provideBar)

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectFooBar() FooBar
func injectFooBar() FooBar {
panic(goose.Use(Set))
}

View File

@@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"codename/goose"
)
func main() {
fb := injectFooBar()
@@ -10,18 +14,20 @@ func main() {
type Foo int
type Bar int
//goose:provide Set
type FooBar struct {
Foo Foo
Bar Bar
}
//goose:provide Set
func provideFoo() Foo {
return 41
}
//goose:provide Set
func provideBar() Bar {
return 1
}
var Set = goose.NewSet(
FooBar{},
provideFoo,
provideBar)

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectFooBar() *FooBar
func injectFooBar() *FooBar {
panic(goose.Use(Set))
}

View File

@@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"codename/goose"
)
func main() {
fmt.Println(injectFooBar())
@@ -10,17 +14,19 @@ 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)
}
var Set = goose.NewSet(
provideFoo,
provideBar,
provideFooBar)

View File

@@ -2,6 +2,10 @@
package main
//goose:use Set
import (
"codename/goose"
)
func injectFooBar() FooBar
func injectFooBar() FooBar {
panic(goose.Use(Set))
}

View File

@@ -3,9 +3,10 @@
package main
import (
_ "bar"
"bar"
"codename/goose"
)
//goose:use "bar".Message
func injectedMessage() string
func injectedMessage() string {
panic(goose.Use(bar.ProvideMessage))
}

View File

@@ -1,8 +1,6 @@
// Package bar is the vendored copy of bar which contains the real provider.
package bar
//goose:provide Message
// ProvideMessage provides a friendly user greeting.
func ProvideMessage() string {
return "Hello, World!"