Skip to content

Commit b20d1a4

Browse files
committed
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í <[email protected]> Change-Id: I17ad3471aee89a4d949e7304f20249d40be60c11 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1216895 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Jonathan Matthews <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 82ff070 commit b20d1a4

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

cmd/cue/cmd/exp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ type "any" because the Go type system is not able to express disjunctions.
5454
5555
To ensure that the resulting Go code works, any imported CUE packages or
5656
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.
5859
5960
Generated Go type and field names may differ from the original CUE names by default.
6061
For instance, an exported definition "#foo" becomes "Foo",
@@ -92,7 +93,6 @@ The default is "zero", representing a missing field as the zero value.
9293
@go(,optional=nillable) // set for all fields under this struct
9394
}
9495
`[1:],
95-
// TODO: write a long help text once the feature set is reasonably stable.
9696
RunE: mkRunE(c, runExpGenGoTypes),
9797
}
9898

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+

0 commit comments

Comments
 (0)