printer: constraints formatting (#209)
Uses `buildtag.Format` to format constraints in the assembly and stub file printers. This will ensure `// + build` and `//go:build` syntax are used consistent with the current Go version. Updates #183
This commit is contained in:
committed by
GitHub
parent
55d98ccf77
commit
79bee1a316
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mmcloughlin/avo/build"
|
||||
"github.com/mmcloughlin/avo/buildtags"
|
||||
"github.com/mmcloughlin/avo/printer"
|
||||
)
|
||||
|
||||
@@ -26,3 +27,32 @@ func TestStubsPragmas(t *testing.T) {
|
||||
"",
|
||||
})
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user