File: stubs_test.go

package info (click to toggle)
golang-github-mmcloughlin-avo 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,024 kB
  • sloc: xml: 71,029; asm: 14,862; sh: 194; makefile: 21; ansic: 11
file content (58 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package printer_test

import (
	"testing"

	"github.com/mmcloughlin/avo/build"
	"github.com/mmcloughlin/avo/buildtags"
	"github.com/mmcloughlin/avo/printer"
)

func TestStubsPragmas(t *testing.T) {
	ctx := build.NewContext()
	ctx.Function("f")
	ctx.Pragma("noescape")
	ctx.Pragma("linkname f remote.f")
	ctx.SignatureExpr("func(x *uint64)")
	ctx.RET()

	AssertPrintsLines(t, ctx, printer.NewStubs, []string{
		"// Code generated by avo. DO NOT EDIT.",
		"",
		"package printer",
		"",
		"//go:noescape",
		"//go:linkname f remote.f",
		"func f(x *uint64)",
		"",
	})
}

func TestStubsConstraints(t *testing.T) {
	ctx := build.NewContext()
	ctx.ConstraintExpr("linux darwin")
	ctx.ConstraintExpr("amd64 arm64 mips64x ppc64x")

	expect := []string{
		"// Code generated by avo. DO NOT EDIT.",
		"",
	}
	if buildtags.GoBuildSyntaxSupported() {
		expect = append(expect,
			"//go:build (linux || darwin) && (amd64 || arm64 || mips64x || ppc64x)",
		)
	}
	if buildtags.PlusBuildSyntaxSupported() {
		expect = append(expect,
			"// +build linux darwin",
			"// +build amd64 arm64 mips64x ppc64x",
		)
	}
	expect = append(expect,
		"",
		"package printer",
		"",
	)

	AssertPrintsLines(t, ctx, printer.NewStubs, expect)
}