Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Giau. Tran Minh <[email protected]>
  • Loading branch information
giautm committed Apr 22, 2023
1 parent 5bbd21a commit 1bceb9c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
2 changes: 0 additions & 2 deletions internal/wire/testdata/Subtract/foo/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package main

import (
// "strings"

"github.com/google/wire"
)

Expand Down
46 changes: 46 additions & 0 deletions internal/wire/testdata/SubtractErrors/foo/foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2018 The Wire Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"github.com/google/wire"
)

type context struct{}

func main() {}

type FooOptions struct{}
type Foo string
type Bar struct{}
type BarName string

func provideFooOptions() *FooOptions {
return &FooOptions{}
}

func provideFoo(*FooOptions) Foo {
return Foo("foo")
}

func provideBar(Foo, BarName) *Bar {
return &Bar{}
}

var Set = wire.NewSet(
provideFooOptions,
provideFoo,
provideBar,
)
34 changes: 34 additions & 0 deletions internal/wire/testdata/SubtractErrors/foo/wire.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2018 The Wire Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build wireinject
// +build wireinject

package main

import (
"github.com/google/wire"
)

func injectMissArgs(opts *FooOptions) Foo {
panic(wire.Build(wire.Subtract(provideFoo)))
}

func injectNonSet(opts *FooOptions) Foo {
panic(wire.Build(wire.Subtract(provideFoo, new(FooOptions))))
}

func injectNonPointer(name BarName, opts *FooOptions) *Bar {
panic(wire.Build(wire.Subtract(Set, FooOptions{})))
}
1 change: 1 addition & 0 deletions internal/wire/testdata/SubtractErrors/pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example.com/foo
5 changes: 5 additions & 0 deletions internal/wire/testdata/SubtractErrors/want/wire_errs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
example.com/foo/wire.go:x:y: call to Subtract must specify types to be subtracted

example.com/foo/wire.go:x:y: first argument to Subtract must be a Set

example.com/foo/wire.go:x:y: argument to Subtract must be a pointer

0 comments on commit 1bceb9c

Please sign in to comment.