Skip to content

Commit 9a53c81

Browse files
committed
cmd/cue: add testscript reproducing get go issues with std packages
For #648. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I5b5f54a3b859e1e55b8bd80f3cf1943ee841e1ba Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1210515 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 239f3d3 commit 9a53c81

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Go standard library packages can cause issues, because we cannot generate
2+
# packages such as cue.mod/gen/time which conflict with our own standard library.
3+
4+
exec cue get go --local
5+
cmp src_go_gen.cue src_go_gen.cue.golden
6+
7+
# Check which files were generated under cue.mod/gen and other directories.
8+
# TODO: we should be generating zero "std" packages under cue.mod/gen.
9+
find-files cue.mod
10+
stdout '^cue.mod/gen/[^.]+/'
11+
12+
# Verify that the result can be loaded correctly.
13+
# TODO: this should succeed, not fail.
14+
! exec cue vet -c=false
15+
cmp stderr vet.stderr
16+
17+
-- go.mod --
18+
module mod.test
19+
20+
go 1.21
21+
-- cue.mod/module.cue --
22+
module: "mod.test"
23+
24+
language: version: "v0.12.0"
25+
-- src.go --
26+
package x
27+
28+
import (
29+
"io"
30+
"reflect"
31+
"time"
32+
)
33+
34+
type Root struct {
35+
// reflect types and values in Go are opaque and do not encode as useful JSON.
36+
ReflectType reflect.Type
37+
ReflectValue reflect.Value
38+
39+
// reflect.ValueError is an example of a struct made up of simple types,
40+
// in this case a Method string and a Kind uint. We could generate that structure,
41+
// as long as we don't place it in cue.mod/pkg/reflect, conflicting with CUE's own std.
42+
ReflectValueError reflect.ValueError
43+
44+
// io.Writer is an interface, so there is no structure to be generated.
45+
// Moreover, even though "io" is a very common Go package, CUE has no such package.
46+
IoWriter io.Writer
47+
48+
// time.Month is just an int type, but this edge case is particularly interesting
49+
// given that CUE already has a "time" package with e.g. Duration and Time, but no Month.
50+
TimeMonth time.Month
51+
}
52+
-- src_go_gen.cue.golden --
53+
// Code generated by cue get go. DO NOT EDIT.
54+
55+
//cue:generate cue get go mod.test
56+
57+
package x
58+
59+
import (
60+
"reflect"
61+
"io"
62+
"time"
63+
)
64+
65+
#Root: {
66+
// reflect types and values in Go are opaque and do not encode as useful JSON.
67+
ReflectType: reflect.#Type
68+
69+
// reflect.ValueError is an example of a struct made up of simple types,
70+
// in this case a Method string and a Kind uint. We could generate that structure,
71+
// as long as we don't place it in cue.mod/pkg/reflect, conflicting with CUE's own std.
72+
ReflectValueError: reflect.#ValueError
73+
74+
// io.Writer is an interface, so there is no structure to be generated.
75+
// Moreover, even though "io" is a very common Go package, CUE has no such package.
76+
IoWriter: io.#Writer
77+
78+
// time.Month is just an int type, but this edge case is particularly interesting
79+
// given that CUE already has a "time" package with e.g. Duration and Time, but no Month.
80+
TimeMonth: time.#Month
81+
}
82+
-- vet.stderr --
83+
builtin package "reflect" undefined:
84+
./src_go_gen.cue:8:2
85+
builtin package "io" undefined:
86+
./src_go_gen.cue:9:2

0 commit comments

Comments
 (0)