MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Programs

Method Programs

tools/celtest/test_runner.go:574–607  ·  view source on GitHub ↗

Programs creates a list of CEL programs from the input expressions configured in the test runner using the provided program options.

(t *testing.T, opts ...cel.ProgramOption)

Source from the content-addressed store, hash-verified

572// Programs creates a list of CEL programs from the input expressions configured in the test runner
573// using the provided program options.
574func (tr *TestRunner) Programs(t *testing.T, opts ...cel.ProgramOption) ([]Program, error) {
575 t.Helper()
576 if tr.Compiler == nil {
577 return nil, fmt.Errorf("compiler is not set")
578 }
579 e, err := tr.CreateEnv()
580 if err != nil {
581 return nil, err
582 }
583 programs := make([]Program, 0, len(tr.Expressions))
584 for _, expr := range tr.Expressions {
585 ast, policyMetadata, err := expr.CreateAST(tr.Compiler)
586 if err != nil {
587 if strings.Contains(err.Error(), "invalid file extension") ||
588 strings.Contains(err.Error(), "invalid raw expression") {
589 continue
590 }
591 return nil, err
592 }
593 if enableDebug {
594 t.Logf("Loaded AST:\n%s", DebugAST(ast))
595 }
596 prg, err := e.Program(ast, opts...)
597 if err != nil {
598 return nil, err
599 }
600 programs = append(programs, Program{
601 Program: prg,
602 PolicyMetadata: policyMetadata,
603 Ast: ast,
604 })
605 }
606 return programs, nil
607}
608
609// Tests creates a list of tests from the test suite file and test suite parser configured in the
610// test runner.

Callers 3

TestCoverageStatsFunction · 0.95
TriggerTestsFunction · 0.95
runTestSuiteFunction · 0.95

Calls 6

DebugASTFunction · 0.85
ProgramMethod · 0.80
CreateEnvMethod · 0.65
CreateASTMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by 2

TestCoverageStatsFunction · 0.76
runTestSuiteFunction · 0.76