From bd9e49fcd7ee5b34ffb75e6faffbaf16c0fb7960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 7 May 2024 16:23:38 +0100 Subject: [PATCH] cue/load: don't load from $PWD in the integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This required us to have a "test.cue" file in cue/load even though it has nothing to do with the non-test code in cue/load. That was confusing to me in the past, and such files belong in testdata. We already have a "hello" package there too, so we can just use it. TestLoadInstancesConcurrent ignored errors, so removing test.cue would have silently made it do nothing. Make it more robust first. Signed-off-by: Daniel Martí Change-Id: I16abcee509afb677bc4f66d55dc01cd5eed58524 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194419 Unity-Result: CUE porcuepine Reviewed-by: Paul Jolly TryBot-Result: CUEcueckoo --- cue/load/import_test.go | 8 +------- cue/load/loader_test.go | 11 +++++++---- cue/load/test.cue | 3 --- 3 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 cue/load/test.cue diff --git a/cue/load/import_test.go b/cue/load/import_test.go index d431cf46bbc..032eae65a31 100644 --- a/cue/load/import_test.go +++ b/cue/load/import_test.go @@ -16,7 +16,6 @@ package load import ( "fmt" - "os" "path/filepath" "reflect" "testing" @@ -81,12 +80,7 @@ func TestMultiplePackageImport(t *testing.T) { } func TestLocalDirectory(t *testing.T) { - cwd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - - p, err := getInst(".", cwd) + p, err := getInst(".", testdata("testmod", "hello")) if err != nil { t.Fatal(err) } diff --git a/cue/load/loader_test.go b/cue/load/loader_test.go index 01b13a42327..ae7cfd8ca2b 100644 --- a/cue/load/loader_test.go +++ b/cue/load/loader_test.go @@ -466,17 +466,20 @@ func TestLoadInstancesConcurrent(t *testing.T) { // This test is designed to fail when run with the race detector // if there's an underlying race condition. // See https://cuelang.org/issue/1746 - race(func() { - Instances([]string{"."}, nil) + race(t, func() error { + _, err := getInst(".", testdata("testmod", "hello")) + return err }) } -func race(f func()) { +func race(t *testing.T, f func() error) { var wg sync.WaitGroup for i := 0; i < 2; i++ { wg.Add(1) go func() { - f() + if err := f(); err != nil { + t.Error(err) + } wg.Done() }() } diff --git a/cue/load/test.cue b/cue/load/test.cue deleted file mode 100644 index 446ff7b13c6..00000000000 --- a/cue/load/test.cue +++ /dev/null @@ -1,3 +0,0 @@ -package test - -"Hello world!"