Skip to content

Commit

Permalink
In golang v1.13, parse flags in package initialization will fail. See h…
Browse files Browse the repository at this point in the history
…ttps://tip.golang.org/doc/go1.13#testing (#177)

Fixed by move the init func into a TestMain func.
  • Loading branch information
bbiao authored and xiang90 committed Sep 25, 2019
1 parent 14ae445 commit 72c1660
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion quick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"os"
"reflect"
"testing"
"testing/quick"
"time"
)
Expand All @@ -23,7 +24,7 @@ import (

var qcount, qseed, qmaxitems, qmaxksize, qmaxvsize int

func init() {
func TestMain(m *testing.M) {
flag.IntVar(&qcount, "quick.count", 5, "")
flag.IntVar(&qseed, "quick.seed", int(time.Now().UnixNano())%100000, "")
flag.IntVar(&qmaxitems, "quick.maxitems", 1000, "")
Expand All @@ -32,6 +33,8 @@ func init() {
flag.Parse()
fmt.Fprintln(os.Stderr, "seed:", qseed)
fmt.Fprintf(os.Stderr, "quick settings: count=%v, items=%v, ksize=%v, vsize=%v\n", qcount, qmaxitems, qmaxksize, qmaxvsize)

m.Run()
}

func qconfig() *quick.Config {
Expand Down

0 comments on commit 72c1660

Please sign in to comment.