From 1bceb9ca3911ea2b2be172a4b763f446c36e6360 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Sat, 22 Apr 2023 10:33:03 +0700 Subject: [PATCH] chore: more tests Signed-off-by: Giau. Tran Minh --- internal/wire/testdata/Subtract/foo/wire.go | 2 - .../wire/testdata/SubtractErrors/foo/foo.go | 46 +++++++++++++++++++ .../wire/testdata/SubtractErrors/foo/wire.go | 34 ++++++++++++++ internal/wire/testdata/SubtractErrors/pkg | 1 + .../SubtractErrors/want/wire_errs.txt | 5 ++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 internal/wire/testdata/SubtractErrors/foo/foo.go create mode 100644 internal/wire/testdata/SubtractErrors/foo/wire.go create mode 100644 internal/wire/testdata/SubtractErrors/pkg create mode 100644 internal/wire/testdata/SubtractErrors/want/wire_errs.txt diff --git a/internal/wire/testdata/Subtract/foo/wire.go b/internal/wire/testdata/Subtract/foo/wire.go index d2f23ea1..1bb8c4f9 100644 --- a/internal/wire/testdata/Subtract/foo/wire.go +++ b/internal/wire/testdata/Subtract/foo/wire.go @@ -18,8 +18,6 @@ package main import ( - // "strings" - "github.com/google/wire" ) diff --git a/internal/wire/testdata/SubtractErrors/foo/foo.go b/internal/wire/testdata/SubtractErrors/foo/foo.go new file mode 100644 index 00000000..d2c4b96b --- /dev/null +++ b/internal/wire/testdata/SubtractErrors/foo/foo.go @@ -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, +) diff --git a/internal/wire/testdata/SubtractErrors/foo/wire.go b/internal/wire/testdata/SubtractErrors/foo/wire.go new file mode 100644 index 00000000..51d4fb75 --- /dev/null +++ b/internal/wire/testdata/SubtractErrors/foo/wire.go @@ -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{}))) +} diff --git a/internal/wire/testdata/SubtractErrors/pkg b/internal/wire/testdata/SubtractErrors/pkg new file mode 100644 index 00000000..f7a5c8ce --- /dev/null +++ b/internal/wire/testdata/SubtractErrors/pkg @@ -0,0 +1 @@ +example.com/foo diff --git a/internal/wire/testdata/SubtractErrors/want/wire_errs.txt b/internal/wire/testdata/SubtractErrors/want/wire_errs.txt new file mode 100644 index 00000000..6da996ec --- /dev/null +++ b/internal/wire/testdata/SubtractErrors/want/wire_errs.txt @@ -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 \ No newline at end of file