github.com/0xKiwi/rules_go@v0.24.3/tests/core/output_groups/compilation_outputs_test.go (about)

     1  package output_groups
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"runtime"
     7  	"sort"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/bazelbuild/rules_go/go/tools/bazel"
    12  )
    13  
    14  func TestCompilationOutputs(t *testing.T) {
    15  	runfiles, err := bazel.ListRunfiles()
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  
    20  	exe := ""
    21  	if runtime.GOOS == "windows" {
    22  		exe = ".exe"
    23  	}
    24  	expectedFiles := map[string]bool{
    25  		"compilation_outputs_test" + exe: true, // test binary; not relevant
    26  
    27  		"lib.a":               false, // :lib archive
    28  		"lib_test.internal.a": false, // :lib_test archive
    29  		"bin.a":               false, // :bin archive
    30  	}
    31  	for _, rf := range runfiles {
    32  		info, err := os.Stat(rf.Path)
    33  		if err != nil {
    34  			t.Error(err)
    35  			continue
    36  		}
    37  		if info.IsDir() {
    38  			continue
    39  		}
    40  
    41  		base := filepath.Base(rf.Path)
    42  		if seen, ok := expectedFiles[base]; !ok {
    43  			t.Errorf("unexpected runfile: %s %s", rf.Path, base)
    44  		} else if !seen {
    45  			expectedFiles[base] = true
    46  		}
    47  	}
    48  
    49  	missingFiles := make([]string, 0, len(expectedFiles))
    50  	for path, seen := range expectedFiles {
    51  		if !seen {
    52  			missingFiles = append(missingFiles, path)
    53  		}
    54  	}
    55  	sort.Strings(missingFiles)
    56  	if len(missingFiles) > 0 {
    57  		t.Errorf("did not find expected files: %s", strings.Join(missingFiles, " "))
    58  	}
    59  }