File: inline_test.go

package info (click to toggle)
golang-k8s-kube-openapi 0.0~git20241212.2c72e55-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,396 kB
  • sloc: sh: 50; makefile: 5
file content (102 lines) | stat: -rw-r--r-- 3,130 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
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
// Copyright 2020 The Go 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 json

import (
	"os"
	"os/exec"
	"strings"
	"testing"
)

// Whether a function is inlineable is dependent on the Go compiler version
// and also relies on the presence of the Go toolchain itself being installed.
// This test is disabled by default and explicitly enabled with an
// environment variable that is specified in our integration tests,
// which have fine control over exactly which Go version is being tested.
var testInline = os.Getenv("TEST_INLINE") != ""

func TestInline(t *testing.T) {
	if !testInline {
		t.SkipNow()
	}

	fncs := func() map[string]bool {
		m := make(map[string]bool)
		for _, s := range []string{
			"Encoder.needFlush",
			"Decoder.ReadValue", // thin wrapper over Decoder.readValue
			"decodeBuffer.needMore",
			"consumeWhitespace",
			"consumeNull",
			"consumeFalse",
			"consumeTrue",
			"consumeSimpleString",
			"consumeString", // thin wrapper over consumeStringResumable
			"consumeSimpleNumber",
			"consumeNumber",         // thin wrapper over consumeNumberResumable
			"unescapeStringMayCopy", // thin wrapper over unescapeString
			"hasSuffixByte",
			"trimSuffixByte",
			"trimSuffixString",
			"trimSuffixWhitespace",
			"stateMachine.appendLiteral",
			"stateMachine.appendNumber",
			"stateMachine.appendString",
			"stateMachine.depth",
			"stateMachine.reset",
			"stateMachine.mayAppendDelim",
			"stateMachine.needDelim",
			"stateMachine.popArray",
			"stateMachine.popObject",
			"stateMachine.pushArray",
			"stateMachine.pushObject",
			"stateEntry.increment",
			"stateEntry.decrement",
			"stateEntry.isArray",
			"stateEntry.isObject",
			"stateEntry.length",
			"stateEntry.needImplicitColon",
			"stateEntry.needImplicitComma",
			"stateEntry.needObjectName",
			"stateEntry.needObjectValue",
			"objectNameStack.reset",
			"objectNameStack.length",
			"objectNameStack.getUnquoted",
			"objectNameStack.push",
			"objectNameStack.replaceLastQuotedOffset",
			"objectNameStack.replaceLastUnquotedName",
			"objectNameStack.pop",
			"objectNameStack.ensureCopiedBuffer",
			"objectNamespace.insertQuoted",   // thin wrapper over objectNamespace.insert
			"objectNamespace.insertUnquoted", // thin wrapper over objectNamespace.insert
			"Token.String",                   // thin wrapper over Token.string
			"foldName",                       // thin wrapper over appendFoldedName
			"hash64",
		} {
			m[s] = true
		}
		return m
	}()

	cmd := exec.Command("go", "build", "-gcflags=-m")
	b, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatalf("exec.Command error: %v\n\n%s", err, b)
	}
	for _, line := range strings.Split(string(b), "\n") {
		const phrase = ": can inline "
		if i := strings.Index(line, phrase); i >= 0 {
			fnc := line[i+len(phrase):]
			fnc = strings.ReplaceAll(fnc, "(", "")
			fnc = strings.ReplaceAll(fnc, "*", "")
			fnc = strings.ReplaceAll(fnc, ")", "")
			delete(fncs, fnc)
		}
	}
	for fnc := range fncs {
		t.Errorf("%v is not inlineable, expected it to be", fnc)
	}
}