Skip to content

Commit

Permalink
cue/load: don't load from $PWD in the integration tests
Browse files Browse the repository at this point in the history
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í <[email protected]>
Change-Id: I16abcee509afb677bc4f66d55dc01cd5eed58524
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194419
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed May 8, 2024
1 parent 91223e3 commit bd9e49f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
8 changes: 1 addition & 7 deletions cue/load/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package load

import (
"fmt"
"os"
"path/filepath"
"reflect"
"testing"
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 7 additions & 4 deletions cue/load/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
}
Expand Down
3 changes: 0 additions & 3 deletions cue/load/test.cue

This file was deleted.

0 comments on commit bd9e49f

Please sign in to comment.