Skip to content

cmd/go: in 1.15: change in "go test" argument parsing #40763

Closed
@ianlancetaylor

Description

@ianlancetaylor

Reported at https://groups.google.com/forum/?oldui=1#!topic/golang-dev/2O4EdN7XNZ0 👍

all_test.go:

        package foo
        import (
            "flag"
            "os"
            "testing"
            "time"
        )
        var oFoo = flag.Duration("foo", time.Second, "")
        func TestMain(m *testing.M) {
            flag.Parse()
            os.Exit(m.Run())
        }
        func Test(t *testing.T) {
            t.Log("ok")
        }
        jnml@3900x:~/src/tmp$ go test -v -foo 1s
        === RUN   Test
            all_test.go:18: ok
        --- PASS: Test (0.00s)
        PASS
        ok      tmp 0.001s
        jnml@3900x:~/src/tmp$ go test -v -timeout 1h
        === RUN   Test
            all_test.go:18: ok
        --- PASS: Test (0.00s)
        PASS
        ok      tmp 0.002s
        jnml@3900x:~/src/tmp$ go test -v -timeout 1h -foo 1s
        === RUN   Test
            all_test.go:18: ok
        --- PASS: Test (0.00s)
        PASS
        ok      tmp 0.002s
        jnml@3900x:~/src/tmp$ go test -v -foo 1s -timeout 1h
        flag provided but not defined: -timeout
        Usage of /tmp/go-build167035760/b001/tmp.test:
          -foo duration
                 (default 1s)
          -test.bench regexp
                run only benchmarks matching regexp
          -test.benchmem
                print memory allocations for benchmarks
          -test.benchtime d
                run each benchmark for duration d (default 1s)
          -test.blockprofile file
                write a goroutine blocking profile to file
          -test.blockprofilerate rate
                set blocking profile rate (see
runtime.SetBlockProfileRate) (default 1)
          -test.count n
                run tests and benchmarks n times (default 1)
          -test.coverprofile file
                write a coverage profile to file
          -test.cpu list
                comma-separated list of cpu counts to run each test with
          -test.cpuprofile file
                write a cpu profile to file
          -test.failfast
                do not start new tests after the first test failure
          -test.list regexp
                list tests, examples, and benchmarks matching regexp then exit
          -test.memprofile file
                write an allocation profile to file
          -test.memprofilerate rate
                set memory allocation profiling rate (see
runtime.MemProfileRate)
          -test.mutexprofile string
                write a mutex contention profile to the named file
after execution
          -test.mutexprofilefraction int
                if >= 0, calls runtime.SetMutexProfileFraction() (default 1)
          -test.outputdir dir
                write profiles to dir
          -test.parallel n
                run at most n tests in parallel (default 24)
          -test.run regexp
                run only tests and examples matching regexp
          -test.short
                run smaller test suite to save time
          -test.testlogfile file
                write test action log to file (for use only by cmd/go)
          -test.timeout d
                panic test binary after duration d (default 0, timeout disabled)
          -test.trace file
                write an execution trace to file
          -test.v
                verbose: print additional output
        exit status 2
        FAIL    tmp 0.002s

In Go 1.14, the last command does this:

> ~/go1.14/bin/go test -v -foo 1s -timeout 1h
=== RUN   Test
    foo_test.go:17: ok
--- PASS: Test (0.00s)
PASS
ok  	command-line-arguments	0.010s

I see some comments in the release notes about flag parsing, but I don't see anything that says that this case that used to work no longer works. I'm not sure precisely what changed here, but this needs to either be fixed or be clearly documented in the release notes. (My personal preference would be to fix it to work as it did previously.)

CC @bcmills @jayconrod

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions