Commit Graph

122 Commits

Author SHA1 Message Date
Robert van Gent
a8825fef58 wire: add info from the dependency graph when a type is not provided 2018-11-13 13:16:46 -08:00
Robert van Gent
b1fd26c92a wire: improve error message for provider set conflicts (google/go-cloud#500) 2018-11-13 13:16:46 -08:00
Robert van Gent
be8ecba636 wire: fix error messages for Bind and InterfaceValue when the arg doesn't implement the interface (google/go-cloud#491)
Fixes google/go-cloud#490
2018-11-13 13:16:46 -08:00
Robert van Gent
2c50843322 wire: add an example and document how to use wire with mocks (google/go-cloud#488) 2018-11-13 13:16:46 -08:00
Robert van Gent
ec7cb36215 wire: report an error if a func with wire.Build in it is an invalid injector (google/go-cloud#487) 2018-11-13 13:16:46 -08:00
Robert van Gent
3bc7933406 wire: avoid making variable names that are Go reserved keywords (google/go-cloud#486) 2018-11-13 13:16:46 -08:00
Robert van Gent
26169ca726 wire/test: add tests for missing error and cleanup func in injector (google/go-cloud#484) 2018-11-13 13:16:46 -08:00
shantuo
fbcb6a82cb wire: make Vendor test work with Go module (google/go-cloud#469) 2018-11-13 13:16:46 -08:00
Robert van Gent
a8c7c0b8e1 wire: omit the local package identifier if it matches the package name (google/go-cloud#385)
Fixes google/go-cloud#424
2018-11-13 13:16:46 -08:00
Robert van Gent
c999a4d1b5 wire: use package names to disambiguate variables (google/go-cloud#386) 2018-11-13 13:16:46 -08:00
Robert van Gent
fab79bd5bd wire: add a test that fails due to wire.Value on a value from function scope (google/go-cloud#405)
Fixes google/go-cloud#378
2018-11-13 13:16:46 -08:00
Robert van Gent
46248162d7 wire: add a testcase with multiple similar packages (google/go-cloud#387)
This is based on the description in google/go-cloud#372. It will be useful if we add wire.FieldsOf, and also for the disambiguation-using-package.

Updates google/go-cloud#372
Updates google/go-cloud#386
2018-11-13 13:16:46 -08:00
Robert van Gent
e93f33129e wire: update Provider.Out to be a slice of provided types, and keep track of the provided concrete type in ProviderSet.providerMap (google/go-cloud#332)
Update Provider.Out to be a slice of provided types, and keep track
of the provided concrete type in ProviderSet.providerMap, to more
clearly model-named struct providers (which provide both the struct
type and a pointer to the struct type).

Fixes google/go-cloud#325.
2018-11-13 13:16:46 -08:00
shantuo
86725a2b3f wire: make tests work with Go modules (google/go-cloud#331)
Generates go.mod files for test cases to support Go modules.
2018-11-13 13:16:46 -08:00
Robert van Gent
cd32a686b1 wire: Add wire.InterfaceValue, required instead of wire.Value if the value is an interface value (google/go-cloud#322)
* Add wire.InterfaceValue, required instead of wire.Value if the value is an interface value.

* Update guestbook sample to use InterfaceValue where appropriate.

* Remove unnecessary ok := true

* Addressing comments from code review.
2018-11-13 13:16:46 -08:00
Ross Light
eedae3d8d0 all: change copyright notice to The Go Cloud Authors (google/go-cloud#306)
Added AUTHORS+CONTRIBUTORS files with the contributors already present
from the Git log.

Fixes google/go-cloud#225
2018-11-13 13:16:46 -08:00
shantuo
4328970c68 wire/internal/wire: run wire tests in parallel (google/go-cloud#309) 2018-11-13 13:16:46 -08:00
Robert van Gent
0e97bcaf0c wire: use cmp.Diff instead of shelling out to "diff" to compare against golden strings in tests (google/go-cloud#287) 2018-11-13 13:16:46 -08:00
Oleg Kovalov
0559d22dfe all: simplify and clarify some expressions (google/go-cloud#260) 2018-11-13 13:16:46 -08:00
Issac Trotts
105b7fde1c wire: respect -record flag for tests (google/go-cloud#282)
Fixes google/go-cloud#281
2018-11-13 13:16:46 -08:00
Robert van Gent
3a3760180d wire: fill in ProviderSet.VarName when the set is a package variable (google/go-cloud#279)
Rename ProviderSet.Name to ProviderSet.VarName.

Fixes google/go-cloud#277
2018-11-13 13:16:46 -08:00
Robert van Gent
85deb53791 wire: Build now returns an error if it has any unused arguments (google/go-cloud#268)
Fixes google/go-cloud#164
2018-11-13 13:16:46 -08:00
Robert van Gent
b348a78000 wire: use providerMap.Iterate instead of providerMap.Keys() + At() (google/go-cloud#265) 2018-11-13 13:16:46 -08:00
Issac Trotts
707f33ee6c all: replace more panic(wire.Build(...)) calls with wire.Build(...); return stuff (google/go-cloud#248)
Fixes google/go-cloud#246
2018-11-13 13:16:45 -08:00
Ross Light
1de1d101c7 wire/cmd/wire: rename from gowire (google/go-cloud#217)
@cflewis and @bradfitz were right: drop the "go". It's cleaner.
2018-11-13 13:16:45 -08:00
Ross Light
5f0dd9ee8f wire: add check command (google/go-cloud#207)
In the internal package, this expands the wire.Load function to run
the same solver as wire.Generate would on any injector function. For
completeness, I also print the injector functions in the gowire show
command.

A subsequent PR will add this as a step to Go Cloud CI.

Updates google/go-cloud#30
2018-11-13 13:16:45 -08:00
Ross Light
765b0228ac wire: don't fail at first error (google/go-cloud#204)
This changes both Generate and Load to try to advance as far as possible
while collecting errors. A small helper type, errorCollector, is used to
make control flow easier to read.

Fixes google/go-cloud#5
2018-11-13 13:16:45 -08:00
Ross Light
a2540bae2a wire: update internal functions to return []error (google/go-cloud#197)
This represents no functional change, it purely changes the signature
used for functions that can possibly return multiple errors. A
follow-up commit will change the control flow to proceed in the face
of errors.
2018-11-13 13:16:45 -08:00
Ross Light
777c1c4331 wire: handle build tags with relative paths correctly (google/go-cloud#188)
5cfd0141dd95acd1a98a1b7f6de5b8b304077634 worked correctly with
absolute import paths, but would fail with relative import paths
(most commonly when passing "." in the default invocation of
gowire). This commit introduces test infrastructure to allow
relative import paths to be given as test inputs, along with a test
case that addresses the regression.
2018-11-13 13:16:45 -08:00
Ross Light
0b7bb585fd wire: remove extra trim in parsing golden test output (google/go-cloud#185) 2018-11-13 13:16:45 -08:00
Ross Light
e1df90c68f wire: only apply wireinject build tag to generated package (google/go-cloud#176) 2018-11-13 13:16:45 -08:00
Ross Light
9537acefc2 wire: use return in tests instead of panic (google/go-cloud#169)
Fixes google/go-cloud#105
2018-11-13 13:16:45 -08:00
Ross Light
5e442802c0 wire: fix test data race (google/go-cloud#168)
This was introduced in 7d83fb8532c1455d4e81b587f31d090320f5eb9f and is
surprisingly not caught by the race detector. I suspect that the testing
package makes it not a strict data race, but the result is still
undefined.
2018-11-13 13:16:45 -08:00
Ross Light
54cdfee544 wire: speed up test execution (google/go-cloud#163)
1.  Runs subtests in parallel.
2.  Decreases the number of runs of the Determinism test to a constant 2.
2018-11-13 13:16:45 -08:00
Ross Light
69b0cf53ad all: move back to github.com/google/go-cloud (google/go-cloud#162)
Reverts changes made in google/go-cloud#120 for google/go-cloud#117
2018-11-13 13:16:45 -08:00
Ross Light
1d225cf371 wire: add error string assertions in tests (google/go-cloud#149)
out.txts that start with "ERROR" can now include substrings to assert
exist in the error messages, one per line.  This gives a very
coarse-grained way of testing for error message quality. It is not a
substitute for manual verification, but gives a "good enough" sanity
check that relevant details are reported.

Updates google/go-cloud#5
2018-11-13 13:16:45 -08:00
Ross Light
338b1da068 wire: store value expressions in package variables (google/go-cloud#135)
The code assigns a local unnecessarily, but this should have no
appreciable effect on semantics, just readability.

Fixes google/go-cloud#104
2018-11-13 13:16:45 -08:00
Ross Light
2eb9d5ea1f wire: make solver iterative instead of recursive (google/go-cloud#137)
Primary reason is to make it easier to allow the process to continue and
collect errors. This has the side-effect of allowing larger depth graphs
since the solver no longer pushes Go stack frames.

Updates google/go-cloud#5
2018-11-13 13:16:45 -08:00
Ross Light
f7658c8a13 wire: change call sites to allow multiple errors (google/go-cloud#118)
Updated the call sites to allow multiple errors to be returned from
the package. Load is now permitted to return partial success.

Updates google/go-cloud#5
2018-11-13 13:16:45 -08:00
Ross Light
45a535a0bd all: s/go-cloud/go-x-cloud/ (google/go-cloud#120)
Fixes google/go-cloud#117
2018-11-13 13:16:45 -08:00
Ross Light
366207371e wire: detect cycles incrementally (google/go-cloud#102)
Idea originally mentioned in google/go-cloud#29. This means that any provider set
loaded must not have cycles, which is stricter than before. The cycle
error message now gives full detail on what caused the cycle.
2018-11-13 13:16:45 -08:00
Ross Light
cd52d44251 wire: clean up README (google/go-cloud#100)
Summary of changes:

-   Rewrote introduction (fixes google/go-cloud#81).
-   Simplified `go generate` explanation by automatically adding the
    comment line to the output.
-   Removed mentions of Dagger. Wire stands enough on its own now, but
    Dagger's influence lives on in our minds.
-   Moved best practices to bottom and removed provider set grouping
    guidance.
2018-11-13 13:16:45 -08:00
Ross Light
b12449f9e3 wire: build provider map incrementally (google/go-cloud#96)
One small breaking change: a provider set can no longer include an
interface binding to a concrete type that is not being provided
(directly or indirectly) by the provider set. I can't imagine a
reasonable use case for the previous behavior, so this likely will
catch more errors

In terms of operation, binding conflict error messages will now give
much more specific line numbers, since they will be reported closer to
where the problem occurred.

Now that provider sets gather this information, it can be exposed in
the package API. gowire now uses this information instead of
trying to build it itself.

Fixes google/go-cloud#29
2018-11-13 13:16:45 -08:00
Ross Light
b2d47f8fcc wire: allow non-panic version of injector (google/go-cloud#91)
Fixes google/go-cloud#7
2018-11-13 13:16:45 -08:00
Ross Light
6345348d86 wire: rename from Goose (google/go-cloud#59)
Rename Goose to wire, making it more obvious what the package does, and look more like the stdlib.

Fixes google/go-cloud#8
2018-11-13 13:16:45 -08:00
Chris Lewis
3e60790b34 Remove dead code from parse.go (google/go-cloud#48) 2018-11-13 13:16:45 -08:00
Ross Light
e9a61ba66b goose: require pointer for first argument to goose.Bind (google/go-cloud#31)
Fixes google/go-cloud#15
2018-11-13 13:16:45 -08:00
Ross Light
962288c10a goose: s/Use/Build/
Fixes google/go-cloud#6
2018-11-13 13:16:45 -08:00
Ross Light
cc91a772b0 goose: add test that disambiguate contains the base name
No behavior change, just more unit testing.

Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Lewis <cflewis@google.com>
2018-11-13 13:16:45 -08:00
Ross Light
3c0eaf830e goose: refactor *gen.inject
The function had grown too long. Several related cleanups:

- Factored out the function return value logic, which had been
  duplicated between providers and injectors.
- Moved code generation for different provider call types into separate
  functions. This moves injector-specific state to a new type
  injectorGen to keep the parameter count down.
- Since it's infeasible to keep the "shadow pass" collecting import
  identifiers in sync the spread out logic, the injector code
  generation is just run twice, with initial output discarded.
- Removed the zero value logic left over from Optional.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-13 13:16:45 -08:00