Skip to content

Commit 3d83c25

Browse files
committed
normalize runtime chunk and typed-block error assertions
1 parent 1def059 commit 3d83c25

1 file changed

Lines changed: 10 additions & 36 deletions

File tree

vibes/runtime_test.go

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,7 @@ func TestArrayChunkWindowValidation(t *testing.T) {
594594
end
595595
`)
596596

597-
_, err := script.Call(context.Background(), "bad_chunk", nil, CallOptions{})
598-
if err == nil || !strings.Contains(err.Error(), "array.chunk size must be a positive integer") {
599-
t.Fatalf("expected chunk validation error, got %v", err)
600-
}
597+
requireCallErrorContains(t, script, "bad_chunk", nil, CallOptions{}, "array.chunk size must be a positive integer")
601598
nativeMaxInt := int64(^uint(0) >> 1)
602599
hugeChunk := callFunc(t, script, "huge_chunk", []Value{NewInt(nativeMaxInt)})
603600
if hugeChunk.Kind() != KindArray {
@@ -608,30 +605,18 @@ func TestArrayChunkWindowValidation(t *testing.T) {
608605
t.Fatalf("expected one chunk for oversized chunk size, got %d", len(chunks))
609606
}
610607
compareArrays(t, chunks[0], []Value{NewInt(1), NewInt(2)})
611-
_, err = script.Call(context.Background(), "bad_window", nil, CallOptions{})
612-
if err == nil || !strings.Contains(err.Error(), "array.window size must be a positive integer") {
613-
t.Fatalf("expected window validation error, got %v", err)
614-
}
608+
requireCallErrorContains(t, script, "bad_window", nil, CallOptions{}, "array.window size must be a positive integer")
615609
hugeWindow := callFunc(t, script, "huge_window", []Value{NewInt(nativeMaxInt)})
616610
if hugeWindow.Kind() != KindArray || len(hugeWindow.Array()) != 0 {
617611
t.Fatalf("expected huge window size to return empty array, got %v", hugeWindow)
618612
}
619613

620614
overflowSize := int64(1 << 62)
621615
if nativeMaxInt < overflowSize {
622-
_, err = script.Call(context.Background(), "huge_chunk", []Value{NewInt(overflowSize)}, CallOptions{})
623-
if err == nil || !strings.Contains(err.Error(), "array.chunk size must be a positive integer") {
624-
t.Fatalf("expected chunk overflow validation error, got %v", err)
625-
}
626-
_, err = script.Call(context.Background(), "huge_window", []Value{NewInt(overflowSize)}, CallOptions{})
627-
if err == nil || !strings.Contains(err.Error(), "array.window size must be a positive integer") {
628-
t.Fatalf("expected window overflow validation error, got %v", err)
629-
}
630-
}
631-
_, err = script.Call(context.Background(), "bad_group_by_stable", nil, CallOptions{})
632-
if err == nil || !strings.Contains(err.Error(), "array.group_by_stable requires a block") {
633-
t.Fatalf("expected group_by_stable block error, got %v", err)
616+
requireCallErrorContains(t, script, "huge_chunk", []Value{NewInt(overflowSize)}, CallOptions{}, "array.chunk size must be a positive integer")
617+
requireCallErrorContains(t, script, "huge_window", []Value{NewInt(overflowSize)}, CallOptions{}, "array.window size must be a positive integer")
634618
}
619+
requireCallErrorContains(t, script, "bad_group_by_stable", nil, CallOptions{}, "array.group_by_stable requires a block")
635620
}
636621

637622
func TestArrayConcatAndSubtract(t *testing.T) {
@@ -756,24 +741,13 @@ func TestTypedBlockSignatures(t *testing.T) {
756741
})
757742
compareArrays(t, untouched, []Value{NewInt(1), NewString("two")})
758743

759-
_, err := script.Call(context.Background(), "increment_all", []Value{
744+
requireCallErrorContains(t, script, "increment_all", []Value{
760745
NewArray([]Value{NewInt(1), NewString("oops")}),
761-
}, CallOptions{})
762-
if err == nil || !strings.Contains(err.Error(), "argument n expected int, got string") {
763-
t.Fatalf("expected typed block argument error, got %v", err)
764-
}
765-
766-
_, err = script.Call(context.Background(), "typed_union", []Value{
746+
}, CallOptions{}, "argument n expected int, got string")
747+
requireCallErrorContains(t, script, "typed_union", []Value{
767748
NewArray([]Value{NewBool(true)}),
768-
}, CallOptions{})
769-
if err == nil || !strings.Contains(err.Error(), "argument v expected int | string, got bool") {
770-
t.Fatalf("expected typed union block argument error, got %v", err)
771-
}
772-
773-
_, err = script.Call(context.Background(), "enforce_yield_type", []Value{NewString("bad")}, CallOptions{})
774-
if err == nil || !strings.Contains(err.Error(), "argument n expected int, got string") {
775-
t.Fatalf("expected typed yield argument error, got %v", err)
776-
}
749+
}, CallOptions{}, "argument v expected int | string, got bool")
750+
requireCallErrorContains(t, script, "enforce_yield_type", []Value{NewString("bad")}, CallOptions{}, "argument n expected int, got string")
777751
}
778752

779753
func TestArraySumRejectsNonNumeric(t *testing.T) {

0 commit comments

Comments
 (0)