github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/go/test/flagdefs_test.go (about)

     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  	"maps"
     9  	"os"
    10  	"testing"
    11  
    12  	"github.com/go-asm/go/cmd/go/cfg"
    13  	"github.com/go-asm/go/cmd/go/test/internal/genflags"
    14  	"github.com/go-asm/go/testenv"
    15  )
    16  
    17  func TestMain(m *testing.M) {
    18  	cfg.SetGOROOT(testenv.GOROOT(nil), false)
    19  	os.Exit(m.Run())
    20  }
    21  
    22  func TestPassFlagToTest(t *testing.T) {
    23  	wantNames := genflags.ShortTestFlags()
    24  
    25  	missing := map[string]bool{}
    26  	for _, name := range wantNames {
    27  		if !passFlagToTest[name] {
    28  			missing[name] = true
    29  		}
    30  	}
    31  	if len(missing) > 0 {
    32  		t.Errorf("passFlagToTest is missing entries: %v", missing)
    33  	}
    34  
    35  	extra := maps.Clone(passFlagToTest)
    36  	for _, name := range wantNames {
    37  		delete(extra, name)
    38  	}
    39  	if len(extra) > 0 {
    40  		t.Errorf("passFlagToTest contains extra entries: %v", extra)
    41  	}
    42  
    43  	if t.Failed() {
    44  		t.Logf("To regenerate:\n\tgo generate github.com/go-asm/go/cmd/go/test")
    45  	}
    46  }
    47  
    48  func TestPassAnalyzersToVet(t *testing.T) {
    49  	testenv.MustHaveGoBuild(t) // runs 'go tool vet -flags'
    50  
    51  	wantNames, err := genflags.VetAnalyzers()
    52  	if err != nil {
    53  		t.Fatal(err)
    54  	}
    55  
    56  	missing := map[string]bool{}
    57  	for _, name := range wantNames {
    58  		if !passAnalyzersToVet[name] {
    59  			missing[name] = true
    60  		}
    61  	}
    62  	if len(missing) > 0 {
    63  		t.Errorf("passAnalyzersToVet is missing entries: %v", missing)
    64  	}
    65  
    66  	extra := maps.Clone(passAnalyzersToVet)
    67  	for _, name := range wantNames {
    68  		delete(extra, name)
    69  	}
    70  	if len(extra) > 0 {
    71  		t.Errorf("passFlagToTest contains extra entries: %v", extra)
    72  	}
    73  
    74  	if t.Failed() {
    75  		t.Logf("To regenerate:\n\tgo generate github.com/go-asm/go/cmd/go/test")
    76  	}
    77  }