this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: replace MainTest entrypoint with testing.Testing

On Go tip on linux/amd64, this slightly increases the size of cmd/cue
binaries from 27418181 bytes to 27439100, where that ~20KiB represents
a 0.07% increase over the current size of ~27MiB.

Importing the testing package doesn't seem like a concern in itself,
given that this is just the cmd/cue/cmd package.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ie881ae302c77fa9e9c0b3608662ca3767a64156b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1188432
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+16 -27
+2 -3
cmd/cue/cmd/common.go
··· 22 22 "regexp" 23 23 "strconv" 24 24 "strings" 25 + "testing" 25 26 26 27 "github.com/spf13/pflag" 27 28 "golang.org/x/text/language" ··· 73 74 }, nil 74 75 } 75 76 76 - var inTest = false 77 - 78 77 func getLang() language.Tag { 79 78 loc := os.Getenv("LC_ALL") 80 79 if loc == "" { ··· 101 100 errors.Print(w, err, &errors.Config{ 102 101 Format: format, 103 102 Cwd: cwd, 104 - ToSlash: inTest, 103 + ToSlash: testing.Testing(), 105 104 }) 106 105 107 106 b := w.Bytes()
+3 -13
cmd/cue/cmd/root.go
··· 20 20 "io" 21 21 "os" 22 22 "runtime" 23 + "testing" 23 24 24 25 "github.com/spf13/cobra" 25 26 ··· 106 107 // due to the inherent behavior of memory pools like sync.Pool, 107 108 // we support supplying MemStats as a JSON file in the tests. 108 109 var m runtime.MemStats 109 - if name := os.Getenv("CUE_TEST_MEMSTATS"); name != "" && inTest { 110 + if name := os.Getenv("CUE_TEST_MEMSTATS"); name != "" && testing.Testing() { 110 111 bs, err := os.ReadFile(name) 111 112 if err != nil { 112 113 return err ··· 227 228 228 229 var rootContextOptions []cuecontext.Option 229 230 230 - // MainTest is like Main, runs the cue tool and returns the code for passing to os.Exit. 231 - func MainTest() int { 232 - // Setting inTest causes filenames printed in error messages 233 - // to be normalized so the output looks the same on Unix 234 - // as Windows. 235 - // TODO: replace with testing.Testing once we can require Go 1.21 or later, 236 - // per the accepted proposal at https://go.dev/issue/52600. 237 - inTest = true 238 - return Main() 239 - } 240 - 241 231 // Main runs the cue tool and returns the code for passing to os.Exit. 242 232 func Main() int { 243 233 cwd, _ := os.Getwd() ··· 246 236 if err != ErrPrintedError { 247 237 errors.Print(os.Stderr, err, &errors.Config{ 248 238 Cwd: cwd, 249 - ToSlash: inTest, 239 + ToSlash: testing.Testing(), 250 240 }) 251 241 } 252 242 return 1
+6 -7
cmd/cue/cmd/script_test.go
··· 297 297 298 298 func TestMain(m *testing.M) { 299 299 os.Exit(testscript.RunMain(m, map[string]func() int{ 300 - "cue": MainTest, 300 + "cue": Main, 301 301 // Until https://github.com/rogpeppe/go-internal/issues/93 is fixed, 302 302 // or we have some other way to use "exec" without caring about success, 303 303 // this is an easy way for us to mimic `? exec cue`. 304 304 "cue_exitzero": func() int { 305 - MainTest() 305 + Main() 306 306 return 0 307 307 }, 308 308 "cue_stdinpipe": func() int { 309 309 cwd, _ := os.Getwd() 310 - if err := mainTestStdinPipe(); err != nil { 310 + if err := mainStdinPipe(); err != nil { 311 311 if err != ErrPrintedError { // print errors like Main 312 312 errors.Print(os.Stderr, err, &errors.Config{ 313 313 Cwd: cwd, 314 - ToSlash: inTest, 314 + ToSlash: testing.Testing(), 315 315 }) 316 316 } 317 317 return 1 ··· 334 334 }) 335 335 } 336 336 337 - func mainTestStdinPipe() error { 338 - // Like MainTest, but sets stdin to a pipe, 337 + func mainStdinPipe() error { 338 + // Like Main, but sets stdin to a pipe, 339 339 // to emulate stdin reads like a terminal. 340 - inTest = true 341 340 cmd, _ := New(os.Args[1:]) 342 341 pr, pw, err := os.Pipe() 343 342 if err != nil {
+3 -2
cmd/cue/cmd/version.go
··· 21 21 "os" 22 22 "runtime" 23 23 "runtime/debug" 24 + "testing" 24 25 25 26 "github.com/spf13/cobra" 26 27 ··· 77 78 // as can reasonably be determined. If no version can be 78 79 // determined, it returns the empty string. 79 80 func cueVersion() string { 80 - if inTest { 81 + if testing.Testing() { 81 82 if v := os.Getenv("CUE_VERSION_OVERRIDE"); v != "" { 82 83 return v 83 84 } ··· 91 92 92 93 func readBuildInfo() (*debug.BuildInfo, bool) { 93 94 bi, ok := debug.ReadBuildInfo() 94 - if !ok || !inTest { 95 + if !ok || !testing.Testing() { 95 96 return bi, ok 96 97 } 97 98 // test-based overrides
+1 -1
cue/interpreter/wasm/exe_test.go
··· 35 35 // works as expected with the command-line tool. 36 36 func TestMain(m *testing.M) { 37 37 os.Exit(testscript.RunMain(m, map[string]func() int{ 38 - "cue": cmd.MainTest, 38 + "cue": cmd.Main, 39 39 })) 40 40 } 41 41
+1 -1
doc/tutorial/basics/script_test.go
··· 76 76 77 77 func TestMain(m *testing.M) { 78 78 os.Exit(testscript.RunMain(m, map[string]func() int{ 79 - "cue": cmd.MainTest, 79 + "cue": cmd.Main, 80 80 })) 81 81 }