Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf31921f

Browse files
committed
perf(cli): optimize help
This change reduces the CPU consumption of --help by ~50%.Also, this change removes ANSI escape codes from our golden files. Idon't those were worth the inability to parallelize golden file tests andglobal state fragility.
1 parentb3c9839 commitf31921f

File tree

88 files changed

+881
-860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+881
-860
lines changed

‎cli/clitest/clitest.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// New creates a CLI instance with a configuration pointed to a
3131
// temporary testing directory.
32-
funcNew(t*testing.T,args...string) (*clibase.Invocation, config.Root) {
32+
funcNew(t testing.TB,args...string) (*clibase.Invocation, config.Root) {
3333
varroot cli.RootCmd
3434

3535
cmd,err:=root.Command(root.AGPL())
@@ -56,7 +56,7 @@ func (l *logWriter) Write(p []byte) (n int, err error) {
5656
}
5757

5858
funcNewWithCommand(
59-
t*testing.T,cmd*clibase.Cmd,args...string,
59+
t testing.TB,cmd*clibase.Cmd,args...string,
6060
) (*clibase.Invocation, config.Root) {
6161
configDir:=config.Root(t.TempDir())
6262
logger:=slogtest.Make(t,nil)

‎cli/clitest/golden.go‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import (
1111
"strings"
1212
"testing"
1313

14-
"github.com/muesli/termenv"
1514
"github.com/stretchr/testify/require"
1615

1716
"github.com/coder/coder/v2/cli/clibase"
18-
"github.com/coder/coder/v2/cli/cliui"
1917
"github.com/coder/coder/v2/cli/config"
2018
"github.com/coder/coder/v2/coderd/coderdtest"
2119
"github.com/coder/coder/v2/coderd/database/dbtestutil"
@@ -50,12 +48,7 @@ func DefaultCases() []CommandHelpCase {
5048

5149
// TestCommandHelp will test the help output of the given commands
5250
// using golden files.
53-
//
54-
//nolint:tparallel,paralleltest
5551
funcTestCommandHelp(t*testing.T,getRootfunc(t*testing.T)*clibase.Cmd,cases []CommandHelpCase) {
56-
// ANSI256 escape codes are far easier for humans to parse in a diff,
57-
// but TrueColor is probably more popular with modern terminals.
58-
cliui.TestColor(t,termenv.ANSI)
5952
rootClient,replacements:=prepareTestData(t)
6053

6154
root:=getRoot(t)

‎cli/cliui/cliui.go‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package cliui
22

33
import (
4+
"flag"
45
"os"
5-
"testing"
66
"time"
77

88
"github.com/muesli/termenv"
@@ -30,25 +30,14 @@ type Styles struct {
3030
Wrap pretty.Style
3131
}
3232

33-
varcolor=termenv.NewOutput(os.Stdout).ColorProfile()
34-
35-
// TestColor sets the color profile to the given profile for the duration of the
36-
// test.
37-
// WARN: Must not be used in parallel tests.
38-
funcTestColor(t*testing.T,tprofile termenv.Profile) {
39-
old:=color
40-
color=tprofile
41-
t.Cleanup(func() {
42-
color=old
43-
})
44-
}
33+
varcolor termenv.Profile
4534

4635
var (
47-
Green=color.Color("#04B575")
48-
Red=color.Color("#ED567A")
49-
Fuchsia=color.Color("#EE6FF8")
50-
Yellow=color.Color("#ECFD65")
51-
Blue=color.Color("#5000ff")
36+
Green=Color("#04B575")
37+
Red=Color("#ED567A")
38+
Fuchsia=Color("#EE6FF8")
39+
Yellow=Color("#ECFD65")
40+
Blue=Color("#5000ff")
5241
)
5342

5443
// Color returns a color for the given string.
@@ -116,6 +105,12 @@ func ifTerm(fmt pretty.Formatter) pretty.Formatter {
116105
}
117106

118107
funcinit() {
108+
color=termenv.NewOutput(os.Stdout).ColorProfile()
109+
ifflag.Lookup("test.v")!=nil {
110+
// Use a consistent colorless profile in tests so that results
111+
// are deterministic.
112+
color=termenv.Ascii
113+
}
119114
// We do not adapt the color based on whether the terminal is light or dark.
120115
// Doing so would require a round-trip between the program and the terminal
121116
// due to the OSC query and response.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp