Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some how all sorts of test argument flags showing up in go program usage

Tags:

go

I have a small go command line utility that I am building in the usual way:

go build

I use the flag package to add command line flags. And all was going swimmingly until I started getting a lot of test flags showing up. Now when I print the usage using flag.Usage I see lots of extra flags:

  -test.bench string
        regular expression to select benchmarks to run
  -test.benchmem
        print memory allocations for benchmarks
  -test.benchtime duration
        approximate run time for each benchmark (default 1s)
  -test.blockprofile string
        write a goroutine blocking profile to the named file after execution
  -test.blockprofilerate int
        if >= 0, calls runtime.SetBlockProfileRate() (default 1)

There are a lot more than this.

I am using the main flag set and adding flags with flag.IntVar and the like.

I can't figure out what I did or how this could have been enabled. None of my other programs include these test flags in the default usage message. I appreciate any pointers.

like image 253
Kevin Bullaughey Avatar asked Mar 13 '23 07:03

Kevin Bullaughey


1 Answers

The testing package's init() adds command line arguments to your app using the flags package.

You are likely referencing testing from some bit of non-testing code.

like image 177
David Budworth Avatar answered May 10 '23 08:05

David Budworth