Skip to content

Commit

Permalink
internal/tdtest: make compatible with cuetdtest
Browse files Browse the repository at this point in the history
The introduction of the use of the matrix in cuetdtest
broke the automatic update of this test. Fix this.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I7879117127f23efc87ac625f7c0c4caebe31988d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1204364
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Nov 20, 2024
1 parent 44696c3 commit 672755c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions internal/tdtest/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ func (s *set[T]) getInfo(file string) *info {
// t.Fatalf("could not find test package")
// }

// In cuetdtest the function of the test may be a subtest, like TestFoo/v3.
// We need to strip the last part.
testName := strings.SplitN(t.Name(), "/", 2)[0]

// Find function declaration of this test.
var fn *ast.FuncDecl
for _, d := range f.Decls {
if fd, ok := d.(*ast.FuncDecl); ok && fd.Name.Name == t.Name() {
if fd, ok := d.(*ast.FuncDecl); ok && fd.Name.Name == testName {
fn = fd
}
}
if fn == nil {
t.Fatalf("could not find test %q in file %q", t.Name(), file)
t.Fatalf("could not find test %q in file %q", testName, file)
}

// Find CompositLit table used for the test:
Expand Down Expand Up @@ -199,7 +203,11 @@ func findFileAndPackage(path string, pkgs []*packages.Package) (*ast.File, *pack
return nil, nil
}

const typeT = "*cuelang.org/go/internal/tdtest.T"
func isT(s string) bool {
// TODO: parametrize this so that tdtest does not have to know of cuetdtest.
return s == "*cuelang.org/go/internal/tdtest.T" ||
s == "*cuelang.org/go/internal/cuetdtest.T"
}

// findCalls finds all call expressions within a given block for functions
// or methods defined within the tdtest package.
Expand All @@ -222,7 +230,7 @@ func (i *info) findCalls(block *ast.BlockStmt, names ...string) []*callInfo {
for _, name := range names {
if sel.Sel.Name == name {
receiver := info.TypeOf(sel.X).String()
if receiver == typeT {
if isT(receiver) {
// Method.
} else if len(c.Args) == 3 {
// Run function.
Expand All @@ -231,7 +239,7 @@ func (i *info) findCalls(block *ast.BlockStmt, names ...string) []*callInfo {
return true
}
argType := info.TypeOf(fn.Type.Params.List[0].Type).String()
if argType != typeT {
if !isT(argType) {
return true
}
} else {
Expand Down

0 comments on commit 672755c

Please sign in to comment.