| 1 | package printer_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/mmcloughlin/avo/build" |
| 7 | "github.com/mmcloughlin/avo/buildtags" |
| 8 | "github.com/mmcloughlin/avo/printer" |
| 9 | ) |
| 10 | |
| 11 | func TestStubsPragmas(t *testing.T) { |
| 12 | ctx := build.NewContext() |
| 13 | ctx.Function("f") |
| 14 | ctx.Pragma("noescape") |
| 15 | ctx.Pragma("linkname f remote.f") |
| 16 | ctx.SignatureExpr("func(x *uint64)") |
| 17 | ctx.RET() |
| 18 | |
| 19 | AssertPrintsLines(t, ctx, printer.NewStubs, []string{ |
| 20 | "// Code generated by avo. DO NOT EDIT.", |
| 21 | "", |
| 22 | "package printer", |
| 23 | "", |
| 24 | "//go:noescape", |
| 25 | "//go:linkname f remote.f", |
| 26 | "func f(x *uint64)", |
| 27 | "", |
| 28 | }) |
| 29 | } |
| 30 | |
| 31 | func TestStubsConstraints(t *testing.T) { |
| 32 | ctx := build.NewContext() |
| 33 | ctx.ConstraintExpr("linux darwin") |
| 34 | ctx.ConstraintExpr("amd64 arm64 mips64x ppc64x") |
| 35 | |
| 36 | expect := []string{ |
| 37 | "// Code generated by avo. DO NOT EDIT.", |
| 38 | "", |
| 39 | } |
| 40 | if buildtags.GoBuildSyntaxSupported() { |
| 41 | expect = append(expect, |
| 42 | "//go:build (linux || darwin) && (amd64 || arm64 || mips64x || ppc64x)", |
| 43 | ) |
| 44 | } |
| 45 | if buildtags.PlusBuildSyntaxSupported() { |
| 46 | expect = append(expect, |
| 47 | "// +build linux darwin", |
| 48 | "// +build amd64 arm64 mips64x ppc64x", |
| 49 | ) |
| 50 | } |
| 51 | expect = append(expect, |
| 52 | "", |
| 53 | "package printer", |
| 54 | "", |
| 55 | ) |
| 56 | |
| 57 | AssertPrintsLines(t, ctx, printer.NewStubs, expect) |
| 58 | } |