aboutsummaryrefslogtreecommitdiff
path: root/tests/core/output_groups/compilation_outputs_test.go
blob: 25daced7bdeb7ea4cf5b92dfe2268b584746ac0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package output_groups

import (
	"os"
	"path/filepath"
	"runtime"
	"sort"
	"strings"
	"testing"

	"github.com/bazelbuild/rules_go/go/tools/bazel"
)

func TestCompilationOutputs(t *testing.T) {
	runfiles, err := bazel.ListRunfiles()
	if err != nil {
		t.Fatal(err)
	}

	exe := ""
	if runtime.GOOS == "windows" {
		exe = ".exe"
	}
	expectedFiles := map[string]bool{
		"compilation_outputs_test" + exe: true, // test binary; not relevant

		"lib.a":               false, // :lib archive
		"lib_test.internal.a": false, // :lib_test archive
		"bin.a":               false, // :bin archive
	}
	for _, rf := range runfiles {
		info, err := os.Stat(rf.Path)
		if err != nil {
			t.Error(err)
			continue
		}
		if info.IsDir() {
			continue
		}

		base := filepath.Base(rf.Path)
		if seen, ok := expectedFiles[base]; !ok {
			t.Errorf("unexpected runfile: %s %s", rf.Path, base)
		} else if !seen {
			expectedFiles[base] = true
		}
	}

	missingFiles := make([]string, 0, len(expectedFiles))
	for path, seen := range expectedFiles {
		if !seen {
			missingFiles = append(missingFiles, path)
		}
	}
	sort.Strings(missingFiles)
	if len(missingFiles) > 0 {
		t.Errorf("did not find expected files: %s", strings.Join(missingFiles, " "))
	}
}