aboutsummaryrefslogtreecommitdiff
path: root/tests/core/cgo/cc_libs_common.go
blob: 40a04ed560eb6b7a8a61b01d3fcc05f365ae2531 (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
package cc_libs_test

import (
	"bytes"
	"github.com/bazelbuild/rules_go/go/tools/bazel"
	"io/ioutil"
	"testing"
)

// A distinctive substring contained in every absolute path pointing into the
// Bazel cache.
const execPathIndicator = "/execroot/io_bazel_rules_go"

func verifyNoCachePaths(t *testing.T, shortPath string) {
	binPath, err := bazel.Runfile(shortPath)
	if err != nil {
		t.Error(err)
	}
	binBytes, err := ioutil.ReadFile(binPath)
	if err != nil {
		t.Error(err)
	}
	if pos := bytes.Index(binBytes, []byte(execPathIndicator)); pos != -1 {
		begin := pos - 150
		if begin < 0 {
			begin = 0
		}
		end := pos + 150
		if end > len(binBytes) {
			end = len(binBytes)
		}
		t.Errorf("%s leaks an absolute path:\n%q", shortPath, binBytes[begin:end])
	}
}