this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: add testscript for `exp gengotypes` output filenames

Generated code is placed in cue_types_${pkgname}_gen.go files
in each CUE package directory, where the package name is omitted
from the filename if it is implied by the import path.

Document and test this behavior properly, which we did not do before.
The behavior changed with https://cuelang.org/cl/1216532,
but it actually changed for the better; our code was slightly broken
before as we did not test all edge cases.

Note that we don't want to rely on the directory name when a package
exists outside of a module, because such a package has no import path,
and the directory name is irrelevant as far as CUE is concerned.

Closes #3765.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I17ad3471aee89a4d949e7304f20249d40be60c11
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1216895
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Jonathan Matthews <github@hello.jonathanmatthews.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+36 -2
+2 -2
cmd/cue/cmd/exp.go
··· 54 54 55 55 To ensure that the resulting Go code works, any imported CUE packages or 56 56 referenced CUE definitions are transitively generated as well. 57 - Generated code is placed in cue_types*_gen.go files in each CUE package directory. 57 + Code is generated in each CUE package directory at cue_types_${pkgname}_gen.go, 58 + where the package name is omitted from the filename if it is implied by the import path. 58 59 59 60 Generated Go type and field names may differ from the original CUE names by default. 60 61 For instance, an exported definition "#foo" becomes "Foo", ··· 92 93 @go(,optional=nillable) // set for all fields under this struct 93 94 } 94 95 `[1:], 95 - // TODO: write a long help text once the feature set is reasonably stable. 96 96 RunE: mkRunE(c, runExpGenGoTypes), 97 97 } 98 98
+34
cmd/cue/cmd/testdata/script/exp_gengotypes_output.txtar
··· 1 + cd nomod 2 + exec cue exp gengotypes ./... 3 + find-files . 4 + stdout -count=2 '_gen\.go$' 5 + stdout 'pkg1/cue_types_pkg1_gen\.go' # Keep the package name; without a module, there is no import path. 6 + stdout 'pkg2/cue_types_otherpkg_gen\.go' 7 + 8 + cd ../withmod 9 + exec cue exp gengotypes ./... 10 + find-files . 11 + stdout -count=2 '_gen\.go$' 12 + stdout 'pkg1/cue_types_gen\.go' # Omit the package name, as it matches the import path. 13 + stdout 'pkg2/cue_types_otherpkg_gen\.go' 14 + 15 + -- nomod/pkg1/pkg1.cue -- 16 + package pkg1 17 + 18 + #Foo: int 19 + -- nomod/pkg2/pkg2.cue -- 20 + package otherpkg 21 + 22 + #Foo: int 23 + -- withmod/cue.mod/module.cue -- 24 + module: "foo.test/root" 25 + language: version: "v0.13.0" 26 + -- withmod/pkg1/pkg1.cue -- 27 + package pkg1 28 + 29 + #Foo: int 30 + -- withmod/pkg2/pkg2.cue -- 31 + package otherpkg 32 + 33 + #Foo: int 34 +