From 98ca6e351afd15cd00401972c7b848024bc04b32 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 17 Feb 2026 16:36:02 +0000 Subject: [PATCH] encoding/gocode: fix test As part of previous CL, I noticed that the expected validation didn't seem to be happening. It turned out that this was due to a mismatch in field names between Go type and CUE code. It would probably be better to use a definition here for typo-checking, but in the meantime, change the tests so they're actually checking what they intend to be checking. Signed-off-by: Roger Peppe Change-Id: I63d93f8ed81b29b3ed92bc728bc48f55a90e39ab Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1231503 TryBot-Result: CUEcueckoo Reviewed-by: Marcel van Lohuizen --- encoding/gocode/gen_test.go | 15 ++++++++++++++- encoding/gocode/testdata/pkg1/cue_gen.go | 4 ++-- encoding/gocode/testdata/pkg2/cue_gen.go | 4 ++-- encoding/gocode/testdata/pkg2/instance.cue | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/encoding/gocode/gen_test.go b/encoding/gocode/gen_test.go index 217615965..236d919e4 100644 --- a/encoding/gocode/gen_test.go +++ b/encoding/gocode/gen_test.go @@ -81,11 +81,24 @@ O: conflicting values {A:"X",P:4} and null (mismatched types struct and null): O.P: invalid value 4 (out of bound >5): pkg2/instance.cue:x:x`, }, { + name: "fail nested struct of transitively imported package", + value: &pkg1.MyStruct{ + A: 5, + B: "dog", + I: &pkg2.ImportMe{A: 1000, B: "z"}, + }, + want: `4 errors in empty disjunction: +conflicting values {A:5,B:"dog",T:"0001-01-01T00:00:00Z",I:{a:1000,b:"z"}} and null (mismatched types struct and null) +I: 2 errors in empty disjunction: +I: conflicting values {a:1000,b:"z"} and null (mismatched types struct and null): + pkg1/instance.cue:x:x +I.a: invalid value 1000 (out of bound <100): + pkg2/instance.cue:x:x`}, { name: "all good", value: &pkg1.MyStruct{ A: 5, B: "dog", - I: &pkg2.ImportMe{A: 1000, B: "a"}, + I: &pkg2.ImportMe{A: 50, B: "a"}, }, want: `nil`, }} diff --git a/encoding/gocode/testdata/pkg1/cue_gen.go b/encoding/gocode/testdata/pkg1/cue_gen.go index bcf40efbf..d903dffc0 100644 --- a/encoding/gocode/testdata/pkg1/cue_gen.go +++ b/encoding/gocode/testdata/pkg1/cue_gen.go @@ -84,5 +84,5 @@ func cuegenMake(name string, x interface{}) cue.Value { return v } -// Data size: 603 bytes. -var cuegenInstanceData = []byte("\x01\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xff\x94RMo\xd3J\x14\x9dq\xf2\xa4\x97Q\u07d3\xde\x0fx\xd2eV\t*v\x12\t\x16V\r\xfd\xa0\xa0.\xdaD\xb4 \x04b1\xb5o\x9cQ'3&\x1e\x97F\xd0\x02\xa5\xf4g\xd7h\x1c\xbb\r\xec\x9a\xd5\u044d\xcf=g\xce=\xff\x94?=\xea\x95\u05c4\x96\xdf\by\xf2\xb5E\xe9\x9a\u0539\x15:\xc6\xe7\xc2\n7\xa6-\xda~e\x8c\xa5\x1e\xa1\xed\xb1\xb0S\xbaF\xe8_/\xa4\u009c\x96W\x84\x90\xff\xcb\x1f\x1e\xa5\xff\xbe\xff\x10\x17\xe8O\xa4\xaa\x99W\x84\x96\x97\x84t\xcb\xef-J\xff\xbe\x9b_\x12\xea\xd1\xf6\x81\x98\xa1[\u052e\x86\x8c\x10r\xd3:*\xaf\x89G)\r\xe2\x02\x95\u0429o\xe6i\x90\x9a\x00ul\x12\xa9\x1d\x8eM\x82\x81\xc5\xdc&\u008a ;I\a\x9b\xa7}J\xe9\x7f\x0e\x06\x8du?.\x90\xdex\xef2\x11\x9f\x88\x14\xc1\xfd\u0258\x9cefn\xa1\xcb:\xfc\x1e\x02C\xce:<\xb7s\xa9\xd3\xdc\xc1\x99\xb0S\xcez\x8c\xed/\x0e\xed\xbc\x88m\b\x9fYg+\x04\u0608\x06}\xd6\xd9\x0e\x01\xa2\v\x1e\v\xcb\xe1\v<\xe4\x89I9\ub31e\x850\xb2S\x9c/9\xac\xb3\x17\x82\xb35\xf4\xf7*W\xfb\xc8\xcea35\xdd\xf5\xd8\xcc2\x85\x16\xa3\x9d\x1a\xf4\xd8\n\xb1\x11\xab\r\xf9;F[!u\xbe\xa5\x17]\xfe\x96\xf7Xg\x1c.\xf7\x8ee|\u2db2\xc3\xea\xd3\x10\xea\u07c3\x88\xf3\x06W\x82\xa7B\xc9DX\x8c\xde\xd4`\xe7\xf5n\x8f\x1df\x18K\xa1\x1art\xc1\xf3\xe5\x84/Yv\x91a\xb4t\xd1c{\xa96s<\x9a\u02bc\x92\x89.\xf8\xc4\x18\xceF3iou\x01\xa4\xb6\x15\xf7Q\x8f\xb1 \x80\x03\xa3w\xcfdn\xa5N\xe1\x93T\n\x8e\x11\xccLZ\x8b\t\x88\x1c\u071b\x11d\x0e\xda\x00~,\xe4\xa9P\xa8-\xbc4\xe0\xa4}\xb6B\xafB\xd9nB\xa9\x83\xacUde\r\n\x8dg.gL\xa0\xd0\n\xf3\x1c\xf0,S2\x96V-\x00\xb58V\x98\xf8lbL\xe8l\xb2\xb1\x9d7I\xbb{\xfb\xfb\x85\xb22S8\x9at\a\xfd\x1e;g\x84x\xeb\xf7)Q]\xd1\xe1\xef\x15\x15+\x05\x1d\xde\x16\xf4\xaem\xac)Gcfc\xd0\xef\xaf<\xf5\x8f\xfb\x8b\xe3\x98;s\xcb\u04c7\xf0\xf41#\xe4W\x00\x00\x00\xff\xff{\xa57\xb4\xe3\x03\x00\x00") +// Data size: 605 bytes. +var cuegenInstanceData = []byte("\x01\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xff\x94RMo\xd3J\x14\x9dq\xf2\xa4\u7afe'\xbd\x1f\xf0\xa4\u02ec\x12T\xec$\x12,\xac\x1a\xfaAA]\xb4\x89hA\b\xc4bb\xdf8\xa3:3&\x1e\x97F\xd0\x02\xa5\xf4g\xd7\u020e\u04d6\x05\x8bzut\xeds\xcf\xf1\xb9\xe7\x9f\xf2\xa7\u00dd\xf2\x8a\xf1\xf2\x1bcO\xbe\xb68_S:\xb7RG\xf4\\ZY\x8dy\x8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x82\xca&\x8c\xec|\x95tuoo\xbfH\xad\xcaR\x1aN:\xfd^\x17\u03801g\xfd>%j*:\xf8\xbd\xa2\xf2NA\a7\x05\xbdm\x1b\xac\xcaQ\x9b\x91\x01n\xf4{=p\xc7\x7f\xb8\xbf\x1cG\xa22\xb7<}\x80O\x1f\x03c\xbf\x02\x00\x00\xff\xff'\xd5\x1b\xf3\xe3\x03\x00\x00") diff --git a/encoding/gocode/testdata/pkg2/cue_gen.go b/encoding/gocode/testdata/pkg2/cue_gen.go index 31d1f3870..9eb07413b 100644 --- a/encoding/gocode/testdata/pkg2/cue_gen.go +++ b/encoding/gocode/testdata/pkg2/cue_gen.go @@ -58,5 +58,5 @@ func cuegenMake(name string, x interface{}) cue.Value { return v } -// Data size: 278 bytes. -var cuegenInstanceData = []byte("\x01\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xffD\x8e\xc1J31\x14\x85\xef\x99\xce\x0f\x7fC\x15|\x00a\x98U\xdd\xccTA\x17E\u012a\b.\x94\xe2V\\\\\xd3\x18C\u06e44\x19AD\xd4Z}\x1f\x9f0\x92Rqw\xf8\xee=\x87o#~f\xc8\xe2\x17!\xbe\x11\x1d\xbc\xb6\x80\x8e\xb1>\xb0\x95\xea\x8c\x03'\x8c\x16\xf2k\xe7\x022B>\xe4\xf0\x80\x0e\xe1\u07f9\x99(\x8f\xb8$\xa2\xed\xf8\x91\x01\x9b7\xb7\xb2Q\u057d\x99\xac\x9bKB\\\x10u\xe3{\v\xf8\xff\xc7\x17\x84\f\xf9\x15OU\x1a\xcaWP\x10Q\xfcN\x1e\x00j\u0668\t[]\xb9\xb9\xae\xb5\xab\x95\x95ndl\xca\u048dT\x1d\x94\x0f#\x0e\\\xcf\xc6z\xef\xf8\xb1\a`+\xc5\xfa\u05fc\x92\x8d\x02\xcfX\x8eY\xab\"\x9d\x840\u04d9\x9b\x87\xa2\xf4an\xac\xf6\xa5\x10\x17+r\xa9\xfa\u0173h\x0f\xfa\xc5\xe1n\xaf'\xda'\xfdb\xfdR\x9d:\x1b\xd8X?\xb0O\u0752\xefd\xb9#^\xc4\xd0\xc8q\xea\x1c\xed\v\xa2\x9f\x00\x00\x00\xff\xff\nc\x81w?\x01\x00\x00") +// Data size: 276 bytes. +var cuegenInstanceData = []byte("\x01\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xffD\x8e\xc1J\x031\x14E\u07dd\x8e`C\x15\xfc\x00a\x98U\xdd\xccTA\x17EDQ\x04\x17Jq+.^\xd3\x18C\u06e44\x19AD\xd4Z\xfd\x1f\xbf0\x92Rqw9\xef\xdd\xcb\u064a_\x19\xb2\xf8M\x88\xefDGo-\xa0c\xac\x0fl\xa5\xba\xe0\xc0\t\xa3\x85\xfc\u05b9\x80\x8c\x90\x0f8<\xa2C\u06384\x13\xe5\x11\x97D\xb4\x1b?3`\xfb\xee^6\xaaz0\x93usI\x88\v\xa2n\xfch\x01\x9b\xff|A\u0210\xdf\xf0T\xa5\xa1|\x05\x05\x11\u015f\xe4\x01\xa0\x96\x8d\x9a\xb0\u0555\x9b\xebZ\xbbZY\xe9F\u01a6,\xddH\xd5A\xf90\xe2\xc0\xf5l\xac\x0fN\x9fz\x00vR\xac\xff\xcc+\xd9(\xf0\x8c\u5635*\xd2I\b3\x9d\xb9y(J\x1f\xe6\xc6j_\nq\xb5\"\u05ea_\xbc\x886\xf7\x8b\xe3\xfd^O\xb4\x87\xfdb\xfdR\x9d;\x1b\xd8X\x7ff\x9f\xbb%\x0fe\xb9'^\xc5\xc0\xc8q\xea\x9c\x1c\n\xa2\xdf\x00\x00\x00\xff\xffV\x13\xad0?\x01\x00\x00") diff --git a/encoding/gocode/testdata/pkg2/instance.cue b/encoding/gocode/testdata/pkg2/instance.cue index 5a6e60654..aec23ffff 100644 --- a/encoding/gocode/testdata/pkg2/instance.cue +++ b/encoding/gocode/testdata/pkg2/instance.cue @@ -3,8 +3,8 @@ package pkg2 import "strings" ImportMe: { - A: <100 - B: strings.ContainsAny("abc") + a: <100 + b: strings.ContainsAny("abc") } PickMe: >5 -- 2.51.2