@@ -23,8 +23,11 @@ import (
2323 "github.com/google/cel-go/common/types"
2424 "github.com/google/cel-go/common/types/ref"
2525 "github.com/google/cel-go/policy"
26+ "github.com/google/cel-go/test"
2627 "github.com/google/cel-go/tools/compiler"
2728 "gopkg.in/yaml.v3"
29+
30+ conformancepb "cel.dev/expr/conformance/test"
2831)
2932
3033type testCase struct {
@@ -116,10 +119,7 @@ func TestTriggerTestsWithRunnerOptions(t *testing.T) {
116119 if err != nil {
117120 t .Fatalf ("compiler.NewCompiler() failed: %v" , err )
118121 }
119- compilerOpt := TestRunnerOption (func (tr * TestRunner ) (* TestRunner , error ) {
120- tr .Compiler = c
121- return tr , nil
122- })
122+ compilerOpt := CustomTestCompiler (c )
123123 opts := []TestRunnerOption {compilerOpt , testSuiteParser , testCELPolicy }
124124 TriggerTests (t , opts ... )
125125 })
@@ -210,3 +210,49 @@ func TestTriggerTests(t *testing.T) {
210210 })
211211 }
212212}
213+
214+ // TestCustomTestSuiteParser triggers the test runner where the tests are provided by a custom
215+ // test suite parser configured using TestSuiteParserOption.
216+ func TestCustomTestSuiteParser (t * testing.T ) {
217+ t .Run ("test custom test suite parser" , func (t * testing.T ) {
218+ celExpr := "a || i + fn(j) == 42"
219+ compilerOpts := []any {compiler .EnvironmentFile ("testdata/config.yaml" ), fnEnvOption ()}
220+ testRunnerOpts := []TestRunnerOption {
221+ TestCompiler (compilerOpts ... ),
222+ TestExpression (celExpr ),
223+ TestSuiteParserOption (& tsparser {}),
224+ }
225+ TriggerTests (t , testRunnerOpts ... )
226+ })
227+ }
228+
229+ type tsparser struct {
230+ TestSuiteParser
231+ }
232+
233+ // ParseTextproto implements the ParseTextproto method of the TestSuiteParser interface.
234+ func (p * tsparser ) ParseTextproto (_ string ) (* conformancepb.TestSuite , error ) {
235+ return nil , nil
236+ }
237+
238+ // ParseYAML implements the ParseYAML method of the TestSuiteParser interface.
239+ func (p * tsparser ) ParseYAML (_ string ) (* test.Suite , error ) {
240+ testCase := & test.Case {
241+ Name : "sample test case" ,
242+ Input : map [string ]* test.InputValue {
243+ "i" : {Value : 21 },
244+ "j" : {Value : 42 },
245+ "a" : {Value : false },
246+ },
247+ Output : & test.Output {Value : true },
248+ }
249+ testSection := & test.Section {
250+ Name : "sample test section" ,
251+ Tests : []* test.Case {testCase },
252+ }
253+ suite := & test.Suite {
254+ Description : "sample test suite" ,
255+ Sections : []* test.Section {testSection },
256+ }
257+ return suite , nil
258+ }
0 commit comments