TestVM_SortBy_NonStringOrder tests that sortBy with non-string order returns a proper error instead of panicking (regression test for OSS-Fuzz #477658245).
(t *testing.T)
| 516 | // TestVM_SortBy_NonStringOrder tests that sortBy with non-string order |
| 517 | // returns a proper error instead of panicking (regression test for OSS-Fuzz #477658245). |
| 518 | func TestVM_SortBy_NonStringOrder(t *testing.T) { |
| 519 | env := map[string]any{} |
| 520 | fn := expr.Function("fn", func(params ...any) (any, error) { |
| 521 | return fmt.Sprintf("fn(%v)", params), nil |
| 522 | }) |
| 523 | |
| 524 | // This expression passes a function result as the order argument to sortBy. |
| 525 | // The function returns a string that is not "asc" or "desc", which should |
| 526 | // produce a proper error rather than a panic. |
| 527 | program, err := expr.Compile(`sortBy([1, 2, 3], #, fn($env))`, expr.Env(env), fn) |
| 528 | require.NoError(t, err) |
| 529 | |
| 530 | testVM := &vm.VM{} |
| 531 | _, err = testVM.Run(program, env) |
| 532 | require.Error(t, err) |
| 533 | require.Contains(t, err.Error(), "unknown order") |
| 534 | } |
| 535 | |
| 536 | // TestVM_ProfileOperations tests the profiling opcodes |
| 537 | func TestVM_ProfileOperations(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…