@@ -243,24 +243,25 @@ func (r *runner) run(t *testing.T) {
243243 input := map [string ]any {}
244244 var err error
245245 var activation interpreter.Activation
246- for k , v := range tc .Input {
247- if v .Expr != "" {
248- input [k ] = r .eval (t , v .Expr )
249- continue
246+ if tc .InputContext != nil && tc .InputContext .ContextExpr != "" {
247+ ctxExpr := tc .InputContext .ContextExpr
248+ ctx , err := r .eval (t , ctxExpr ).ConvertToNative (
249+ reflect .TypeOf (((* proto .Message )(nil ))).Elem ())
250+ if err != nil {
251+ t .Fatalf ("context variable is not a valid proto: %v" , err )
250252 }
251- if v . ContextExpr != "" {
252- ctx , err := r . eval ( t , v . ContextExpr ). ConvertToNative (
253- reflect . TypeOf ((( * proto . Message )( nil ))). Elem () )
254- if err != nil {
255- t . Fatalf ( "context variable is not a valid proto: %v" , err )
256- }
257- activation , err = cel . ContextProtoVars ( ctx .(proto. Message ))
258- if err != nil {
259- t . Fatalf ( "cel.ContextProtoVars() failed: %v" , err )
253+ activation , err = cel . ContextProtoVars ( ctx .(proto. Message ))
254+ if err != nil {
255+ t . Fatalf ( "cel.ContextProtoVars() failed: %v" , err )
256+ }
257+ } else if len ( tc . Input ) != 0 {
258+ for k , v := range tc . Input {
259+ if v . Expr != "" {
260+ input [ k ] = r . eval ( t , v . Expr )
261+ continue
260262 }
261- break
263+ input [ k ] = v . Value
262264 }
263- input [k ] = v .Value
264265 }
265266 if activation == nil {
266267 activation , err = interpreter .NewActivation (input )
@@ -272,7 +273,12 @@ func (r *runner) run(t *testing.T) {
272273 if err != nil {
273274 t .Fatalf ("prg.Eval(input) failed: %v" , err )
274275 }
275- testOut := r .eval (t , tc .Output )
276+ var testOut ref.Val
277+ if tc .Output .Expr != "" {
278+ testOut = r .eval (t , tc .Output .Expr )
279+ } else if tc .Output .Value != nil {
280+ testOut = r .env .CELTypeAdapter ().NativeToValue (tc .Output .Value )
281+ }
276282 if optOut , ok := out .(* types.Optional ); ok {
277283 if optOut .Equal (types .OptionalNone ) == types .True {
278284 if testOut .Equal (types .OptionalNone ) != types .True {
@@ -299,24 +305,25 @@ func (r *runner) bench(b *testing.B) {
299305 input := map [string ]any {}
300306 var err error
301307 var activation interpreter.Activation
302- for k , v := range tc .Input {
303- if v .Expr != "" {
304- input [k ] = r .eval (b , v .Expr )
305- continue
308+ if tc .InputContext != nil && tc .InputContext .ContextExpr != "" {
309+ ctxExpr := tc .InputContext .ContextExpr
310+ ctx , err := r .eval (b , ctxExpr ).ConvertToNative (
311+ reflect .TypeOf (((* proto .Message )(nil ))).Elem ())
312+ if err != nil {
313+ b .Fatalf ("context variable is not a valid proto: %v" , err )
306314 }
307- if v . ContextExpr != "" {
308- ctx , err := r . eval ( b , v . ContextExpr ). ConvertToNative (
309- reflect . TypeOf ((( * proto . Message )( nil ))). Elem () )
310- if err != nil {
311- b . Fatalf ( "context variable is not a valid proto: %v" , err )
312- }
313- activation , err = cel . ContextProtoVars ( ctx .(proto. Message ))
314- if err != nil {
315- b . Fatalf ( "cel.ContextProtoVars() failed: %v" , err )
315+ activation , err = cel . ContextProtoVars ( ctx .(proto. Message ))
316+ if err != nil {
317+ b . Fatalf ( "cel.ContextProtoVars() failed: %v" , err )
318+ }
319+ } else if tc . Input != nil {
320+ for k , v := range tc . Input {
321+ if v . Expr != "" {
322+ input [ k ] = r . eval ( b , v . Expr )
323+ continue
316324 }
317- break
325+ input [ k ] = v . Value
318326 }
319- input [k ] = v .Value
320327 }
321328 if activation == nil {
322329 activation , err = interpreter .NewActivation (input )
0 commit comments