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
60
61
62
63
64
65
66
67
|
package runfiles
import (
"os"
"testing"
"github.com/bazelbuild/rules_go/go/runfiles"
)
func TestRunfilesApparent(t *testing.T) {
path, err := runfiles.Rlocation("other_module/bar.txt")
if err != nil {
t.Fatalf("runfiles.Path: %v", err)
}
assertRunfile(t, path)
}
func TestRunfilesApparentSourceRepositoryOption(t *testing.T) {
r, err := runfiles.New(runfiles.SourceRepo(runfiles.CurrentRepository()))
if err != nil {
t.Fatalf("runfiles.New: %v", err)
}
path, err := r.Rlocation("other_module/bar.txt")
if err != nil {
t.Fatalf("runfiles.Path: %v", err)
}
assertRunfile(t, path)
}
func TestRunfilesApparentWithSourceRepository(t *testing.T) {
r, err := runfiles.New()
if err != nil {
t.Fatalf("runfiles.New: %v", err)
}
r = r.WithSourceRepo(runfiles.CurrentRepository())
path, err := r.Rlocation("other_module/bar.txt")
if err != nil {
t.Fatalf("runfiles.Path: %v", err)
}
assertRunfile(t, path)
}
func TestRunfilesFromApparent(t *testing.T) {
path, err := runfiles.RlocationFrom("other_module/bar.txt", runfiles.CurrentRepository())
if err != nil {
t.Fatalf("runfiles.Path: %v", err)
}
assertRunfile(t, path)
}
func TestRunfilesCanonical(t *testing.T) {
path, err := runfiles.Rlocation(os.Args[1])
if err != nil {
t.Fatalf("runfiles.Path: %v", err)
}
assertRunfile(t, path)
}
func assertRunfile(t *testing.T, path string) {
content, err := os.ReadFile(path)
if err != nil {
t.Fatalf("os.ReadFile: %v", err)
}
if string(content) != "hello\n" {
t.Fatalf("got %q; want %q", content, "hello\n")
}
}
|