This repository has been archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
inlining_test.go
126 lines (122 loc) · 2.55 KB
/
inlining_test.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2020 The Inet.Af AUTHORS. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package netaddr
import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
)
func TestInlining(t *testing.T) {
if v := runtime.Version(); strings.HasPrefix(v, "go1.14") ||
strings.HasPrefix(v, "go1.13") ||
strings.HasPrefix(v, "go1.12") ||
strings.HasPrefix(v, "go1.11") {
t.Skipf("skipping test on old Go version %q", v)
}
if testing.Short() {
t.Skip("skipping in short mode")
}
t.Parallel()
var exe string
if runtime.GOOS == "windows" {
exe = ".exe"
}
out, err := exec.Command(
filepath.Join(runtime.GOROOT(), "bin", "go"+exe),
"build",
"--gcflags=-m",
"inet.af/netaddr").CombinedOutput()
if err != nil {
t.Fatalf("go build: %v, %s", err, out)
}
got := map[string]bool{}
regexp.MustCompile(` can inline (\S+)`).ReplaceAllFunc(out, func(match []byte) []byte {
got[strings.TrimPrefix(string(match), " can inline ")] = true
return nil
})
for _, want := range []string{
"(*IPSetBuilder).Clone",
"(*IPSet).Ranges",
"(*uint128).halves",
"IP.BitLen",
"IP.hasZone",
"IP.IPAddr",
"IP.Is4",
"IP.Is4in6",
"IP.Is6",
"IP.IsLoopback",
"IP.IsMulticast",
"IP.IsInterfaceLocalMulticast",
"IP.IsZero",
"IP.Less",
"IP.lessOrEq",
"IP.Next",
"IP.Prior",
"IP.Unmap",
"IP.Zone",
"IP.v4",
"IP.v6",
"IP.v6u16",
"IP.withoutZone",
"IPPort.IsZero",
"IPPort.TCPAddr",
"IPPort.UDPAddr",
"IPPort.UDPAddrAt",
"IPPortFrom",
"IPPort.IP",
"IPPort.Port",
"IPPort.Valid",
"IPPort.WithIP",
"IPPort.WithPort",
"IPPrefix.IsSingleIP",
"IPPrefix.IsZero",
"IPPrefix.Masked",
"IPPrefix.Valid",
"IPPrefixFrom",
"IPPrefix.IP",
"IPPrefix.Bits",
"IPRange.Prefixes",
"IPRange.prefixFrom128AndBits",
"IPRange.entirelyBefore",
"IPRangeFrom",
"IPRange.To",
"IPRange.From",
"IPv4",
"IPFrom4",
"IPv6LinkLocalAllNodes",
"IPv6Unspecified",
"MustParseIP",
"MustParseIPPort",
"MustParseIPPrefix",
"appendDecimal",
"appendHex",
"discardf",
"u64CommonPrefixLen",
"uint128.addOne",
"uint128.and",
"uint128.bitsClearedFrom",
"uint128.bitsSetFrom",
"uint128.commonPrefixLen",
"uint128.isZero",
"uint128.not",
"uint128.or",
"uint128.subOne",
"uint128.xor",
} {
if !got[want] {
t.Errorf("%q is no longer inlinable", want)
continue
}
delete(got, want)
}
for sym := range got {
if strings.Contains(sym, ".func") {
continue
}
t.Logf("not in expected set, but also inlinable: %q", sym)
}
}