Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/go/internal/test/flagdefs_test.go

Documentation: cmd/go/internal/test

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package test
     6  
     7  import (
     8  	"flag"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  func TestPassFlagToTestIncludesAllTestFlags(t *testing.T) {
    14  	flag.VisitAll(func(f *flag.Flag) {
    15  		if !strings.HasPrefix(f.Name, "test.") {
    16  			return
    17  		}
    18  		name := strings.TrimPrefix(f.Name, "test.")
    19  		switch name {
    20  		case "testlogfile", "paniconexit0":
    21  			// These are internal flags.
    22  		default:
    23  			if !passFlagToTest[name] {
    24  				t.Errorf("passFlagToTest missing entry for %q (flag test.%s)", name, name)
    25  				t.Logf("(Run 'go generate cmd/go/internal/test' if it should be added.)")
    26  			}
    27  		}
    28  	})
    29  
    30  	for name := range passFlagToTest {
    31  		if flag.Lookup("test."+name) == nil {
    32  			t.Errorf("passFlagToTest contains %q, but flag -test.%s does not exist in test binary", name, name)
    33  		}
    34  
    35  		if CmdTest.Flag.Lookup(name) == nil {
    36  			t.Errorf("passFlagToTest contains %q, but flag -%s does not exist in 'go test' subcommand", name, name)
    37  		}
    38  	}
    39  }
    40  

View as plain text