From abf461a0493582a5fd355652eb3119f53c59886d Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 8 Jun 2024 15:17:49 +0800 Subject: [PATCH] TestErrBuiltin --- cl/builtin_test.go | 64 +++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 46 deletions(-) diff --git a/cl/builtin_test.go b/cl/builtin_test.go index 160aa1b3..a25d6548 100644 --- a/cl/builtin_test.go +++ b/cl/builtin_test.go @@ -80,52 +80,24 @@ func TestErrCompileInstrOrValue(t *testing.T) { ctx.compileInstrOrValue(nil, &ssa.Call{}, true) } -func TestErrAdvance(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("advance: no error?") - } - }() - var ctx context - ctx.advance(nil, nil) -} - -func TestErrAlloca(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("alloca: no error?") - } - }() - var ctx context - ctx.alloca(nil, nil) -} - -func TestErrAllocaCStr(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("allocaCStr: no error?") - } - }() - var ctx context - ctx.allocaCStr(nil, nil) -} - -func TestCStrNoArgs(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("cstr: no error?") - } - }() - cstr(nil, nil) -} - -func TestCStrNonconst(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("cstr: no error?") - } - }() - cstr(nil, []ssa.Value{&ssa.Parameter{}}) +func TestErrBuiltin(t *testing.T) { + test := func(builtin string, fn func(ctx *context)) { + defer func() { + if r := recover(); r == nil { + t.Fatal(builtin, ": no error?") + } + }() + var ctx context + fn(&ctx) + } + test("advance", func(ctx *context) { ctx.advance(nil, nil) }) + test("alloca", func(ctx *context) { ctx.alloca(nil, nil) }) + test("allocaCStr", func(ctx *context) { ctx.allocaCStr(nil, nil) }) + test("stringData", func(ctx *context) { ctx.stringData(nil, nil) }) + test("sigsetjmp", func(ctx *context) { ctx.sigsetjmp(nil, nil) }) + test("siglongjmp", func(ctx *context) { ctx.siglongjmp(nil, nil) }) + test("cstr(NoArgs)", func(ctx *context) { cstr(nil, nil) }) + test("cstr(Nonconst)", func(ctx *context) { cstr(nil, []ssa.Value{&ssa.Parameter{}}) }) } func TestPkgNoInit(t *testing.T) {