cuelang.org/go@v0.10.1/internal/cuetdtest/cuetdtest.go (about) 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. 17 package cuetdtest 18 19 import ( 20 "testing" 21 22 "cuelang.org/go/internal/cuetest" 23 "cuelang.org/go/internal/tdtest" 24 ) 25 26 func init() { 27 tdtest.UpdateTests = cuetest.UpdateGoldenFiles 28 } 29 30 type T struct { 31 *tdtest.T 32 M *M 33 } 34 35 // Run creates a new table-driven test using the CUE testing defaults. 36 func Run[TC any](t *testing.T, table []TC, fn func(t *T, tc *TC)) { 37 FullMatrix.Do(t, func(m *M) { 38 tdtest.Run(m.T, table, func(t *tdtest.T, tc *TC) { 39 m.T = t.T 40 if !m.IsDefault() { 41 // Do not update table-driven tests if this is not the default 42 // test. 43 t.Update(false) 44 } 45 fn(&T{t, m}, tc) 46 }) 47 }) 48 }