Debian Codegraph @

pass/util_test.go

raw symbols SCIP
1 package pass_test
2
3 import (
4 "testing"
5
6 "github.com/mmcloughlin/avo/build"
7 "github.com/mmcloughlin/avo/internal/test"
8 "github.com/mmcloughlin/avo/ir"
9 "github.com/mmcloughlin/avo/pass"
10 )
11
12 // BuildFunction is a helper to compile a build context containing a single
13 // function and (optionally) apply a list of FunctionPasses to it.
14 func BuildFunction(t *testing.T, ctx *build.Context, passes ...pass.FunctionPass) *ir.Function {
15 t.Helper()
16
17 f, err := ctx.Result()
18 if err != nil {
19 build.LogError(test.Logger(t), err, 0)
20 t.FailNow()
21 }
22
23 fns := f.Functions()
24 if len(fns) != 1 {
25 t.Fatalf("expect 1 function")
26 }
27 fn := fns[0]
28
29 for _, p := range passes {
30 if err := p(fn); err != nil {
31 t.Fatal(err)
32 }
33 }
34
35 return fn
36 }