From ebb381989abf9fd00efe473e91955beb2539f195 Mon Sep 17 00:00:00 2001 From: Robert van Gent Date: Thu, 15 Nov 2018 09:47:35 -0800 Subject: [PATCH] wire/tests: add a test for multiple args of the same type to an injector function (google/go-cloud#706) --- .../testdata/MultipleArgsSameType/foo/foo.go | 31 +++++++++++++++++++ .../testdata/MultipleArgsSameType/foo/wire.go | 26 ++++++++++++++++ .../wire/testdata/MultipleArgsSameType/pkg | 1 + .../MultipleArgsSameType/want/wire_errs.txt | 1 + 4 files changed, 59 insertions(+) create mode 100644 internal/wire/testdata/MultipleArgsSameType/foo/foo.go create mode 100644 internal/wire/testdata/MultipleArgsSameType/foo/wire.go create mode 100644 internal/wire/testdata/MultipleArgsSameType/pkg create mode 100644 internal/wire/testdata/MultipleArgsSameType/want/wire_errs.txt diff --git a/internal/wire/testdata/MultipleArgsSameType/foo/foo.go b/internal/wire/testdata/MultipleArgsSameType/foo/foo.go new file mode 100644 index 0000000..f632a5d --- /dev/null +++ b/internal/wire/testdata/MultipleArgsSameType/foo/foo.go @@ -0,0 +1,31 @@ +// Copyright 2018 The Go Cloud 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 ( + "fmt" +) + +func main() { + fmt.Println(inject("foo", "bar").A) +} + +type Foo struct { + A string +} + +func provideFoo(a string) *Foo { + return &Foo{A: a} +} diff --git a/internal/wire/testdata/MultipleArgsSameType/foo/wire.go b/internal/wire/testdata/MultipleArgsSameType/foo/wire.go new file mode 100644 index 0000000..d26e1e5 --- /dev/null +++ b/internal/wire/testdata/MultipleArgsSameType/foo/wire.go @@ -0,0 +1,26 @@ +// Copyright 2018 The Go Cloud 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. + +//+build wireinject + +package main + +import ( + "github.com/google/go-cloud/wire" +) + +func inject(a, b string) *Foo { + // fail: can't have two args of the same type. + panic(wire.Build(provideFoo)) +} diff --git a/internal/wire/testdata/MultipleArgsSameType/pkg b/internal/wire/testdata/MultipleArgsSameType/pkg new file mode 100644 index 0000000..f7a5c8c --- /dev/null +++ b/internal/wire/testdata/MultipleArgsSameType/pkg @@ -0,0 +1 @@ +example.com/foo diff --git a/internal/wire/testdata/MultipleArgsSameType/want/wire_errs.txt b/internal/wire/testdata/MultipleArgsSameType/want/wire_errs.txt new file mode 100644 index 0000000..ad3bf9c --- /dev/null +++ b/internal/wire/testdata/MultipleArgsSameType/want/wire_errs.txt @@ -0,0 +1 @@ +example.com/foo/wire.go:x:y: inject inject: multiple inputs of the same type string \ No newline at end of file