1// Copyright 2024 The CUE Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Package testing is a helper package for test packages in the CUE project.
16// As such it should only be imported in _test.go files.
17package cuetdtest
18
19import (
20 "testing"
21
22 "cuelang.org/go/internal/cuetest"
23 "cuelang.org/go/internal/tdtest"
24)
25
26func init() {
27 tdtest.UpdateTests = cuetest.UpdateGoldenFiles
28}
29
30type T struct {
31 *tdtest.T
32 M *M
33}
34
35// Run creates a new table-driven test using the CUE testing defaults.
36func Run[TC any](t *testing.T, table []TC, fn func(t *T, tc *TC)) {
37 FullMatrix.Do(t, func(t *testing.T, m *M) {
38 tdtest.Run(t, table, func(t *tdtest.T, tc *TC) {
39 if !m.IsDefault() {
40 // Do not update table-driven tests if this is not the default
41 // test.
42 t.Update(false)
43 }
44 fn(&T{t, m}, tc)
45 })
46 })
47}