2019-09-16 11:01:48 -07:00
|
|
|
package printer_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-03-06 20:14:02 +00:00
|
|
|
"sources.truenas.cloud/code/avo/build"
|
|
|
|
|
"sources.truenas.cloud/code/avo/buildtags"
|
|
|
|
|
"sources.truenas.cloud/code/avo/printer"
|
2019-09-16 11:01:48 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)",
|
|
|
|
|
"",
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-10-29 01:08:02 -07:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|