From 3f52195cede4fde07fcc1ac215f0292064a43b28 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Wed, 1 May 2024 12:41:55 +0200 Subject: [PATCH] internal/core/export: use matrix for SelfContained MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests that do not update due to errors have been excluded. Issue #3060 Signed-off-by: Marcel van Lohuizen Change-Id: I5f56ae29e9dda5b4de9b6d651afdb2b161469f1d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194184 Reviewed-by: Daniel Martí Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo --- internal/core/export/self_test.go | 14 ++- .../testdata/selfcontained/import.txtar | 97 +++++++++++++++++++ .../testdata/selfcontained/issue2247.txtar | 55 +++++++++++ 3 files changed, 164 insertions(+), 2 deletions(-) diff --git a/internal/core/export/self_test.go b/internal/core/export/self_test.go index 55b06a9a0c7..fd583f339a9 100644 --- a/internal/core/export/self_test.go +++ b/internal/core/export/self_test.go @@ -26,6 +26,7 @@ import ( "cuelang.org/go/cue/errors" "cuelang.org/go/cue/format" "cuelang.org/go/internal/core/export" + "cuelang.org/go/internal/cuetdtest" "cuelang.org/go/internal/cuetxtar" "cuelang.org/go/internal/diff" "cuelang.org/go/internal/types" @@ -36,11 +37,20 @@ func TestSelfContained(t *testing.T) { test := cuetxtar.TxTarTest{ Name: "self", Root: "./testdata/selfcontained", - } - r := cuecontext.New() + Matrix: cuetdtest.FullMatrix, + + ToDo: map[string]string{ + "self-v3/selfcontained/errors": "reordering", + "self-v3/selfcontained/import": `wa: reference "_hidden_567475F3" not found:`, + "self-v3/selfcontained/splitcomprehension": "reference not found", + "self-v3-noshare/selfcontained/splitcomprehension": "reference not found", + }, + } test.Run(t, func(t *cuetxtar.Test) { + r := t.Context() + a := t.Instances() v := buildFile(t.T, r, a[0]) diff --git a/internal/core/export/testdata/selfcontained/import.txtar b/internal/core/export/testdata/selfcontained/import.txtar index 6485c6dc436..7904d9e7fca 100644 --- a/internal/core/export/testdata/selfcontained/import.txtar +++ b/internal/core/export/testdata/selfcontained/import.txtar @@ -74,6 +74,103 @@ wa: pkg.w.a // Never expand builtin packages. run: exec.Run _hidden: int +-- out/self-v3-noshare/expand_imports -- +import "tool/exec" + +// Can be inlined. +v: V + +// Do not simplify because of multiple usages of enclosing struct. +x: B.c +y: B + +// Cannot simplify because of definition. +z: F.#x + +// Two references to package, but since the second is a scalar, it can be +// hoisted and only one reference remains. So there is still no need for +// a helper. +// TODO: fix this to eliminate the helper. +w: W +wa: W.a + +// Never expand builtin packages. +run: exec.Run +_hidden: int + +//cue:path: "mod.test/a/pkg".v.v +let V = { + x: 3 + y: x +} + +//cue:path: "mod.test/a/pkg".a.b +let B = { + c: { + d: int + } +} + +//cue:path: "mod.test/a/pkg".#Def.f +let F = { + #x: { + g: int + } +} + +//cue:path: "mod.test/a/pkg".w +let W = { + a: _hidden_567475F3 + _hidden_567475F3: { + a: b + } + b: 1 + x: { + _hidden2_567475F3: _hidden_567475F3 + y: _hidden2_567475F3 + } +} +-- diff/-out/self-v3-noshare/expand_imports<==>+out/self/expand_imports -- +diff old new +--- old ++++ new +@@ -1,10 +1,7 @@ + import "tool/exec" + + // Can be inlined. +-v: { +- x: 3 +- y: x +-} ++v: V + + // Do not simplify because of multiple usages of enclosing struct. + x: B.c +@@ -24,6 +21,12 @@ + run: exec.Run + _hidden: int + ++//cue:path: "mod.test/a/pkg".v.v ++let V = { ++ x: 3 ++ y: x ++} ++ + //cue:path: "mod.test/a/pkg".a.b + let B = { + c: { +@@ -42,7 +45,7 @@ + let W = { + a: _hidden_567475F3 + _hidden_567475F3: { +- a: 1 ++ a: b + } + b: 1 + x: { +-- diff/self/todo/p2 -- +Investigate differences. +We assign p2, because the differences only appear with sharing off. -- out/self/expand_imports -- import "tool/exec" diff --git a/internal/core/export/testdata/selfcontained/issue2247.txtar b/internal/core/export/testdata/selfcontained/issue2247.txtar index a48ef5da2f8..38e8332edb3 100644 --- a/internal/core/export/testdata/selfcontained/issue2247.txtar +++ b/internal/core/export/testdata/selfcontained/issue2247.txtar @@ -34,6 +34,61 @@ r: {out: k: l: string}.out import "example.com/t" f: t.p +-- out/self-v3-noshare/expand_imports -- +f: P + +//cue:path: "example.com/t".p +let P = { + c: [int] + d: [c][0] + // TODO: simplify these: + e: { + out: c + }.out + f: { + out: Q + }.out + g: { + out: Q + }.out + h: { + out: { + r: { + s: string + } + } + }.out + i: h.r + j: h.r.s + k: K + l: K.l +} + +//cue:path: "example.com/t".q +let Q = { + x: [...int] +} + +//cue:path: "example.com/t".r.k +let K = { + l: string +} +-- diff/-out/self-v3-noshare/expand_imports<==>+out/self/expand_imports -- +diff old new +--- old ++++ new +@@ -1,4 +1,7 @@ +-f: { ++f: P ++ ++//cue:path: "example.com/t".p ++let P = { + c: [int] + d: [c][0] + // TODO: simplify these: +-- diff/self/todo/p2 -- +Unnecessary let indirection. +We assign p2, because the differences only appear with sharing off. -- out/self/expand_imports -- f: { c: [int]