aboutsummaryrefslogtreecommitdiff
path: root/tests/bcr/runfiles/runfiles_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bcr/runfiles/runfiles_test.go')
-rw-r--r--tests/bcr/runfiles/runfiles_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/bcr/runfiles/runfiles_test.go b/tests/bcr/runfiles/runfiles_test.go
new file mode 100644
index 00000000..ea82e976
--- /dev/null
+++ b/tests/bcr/runfiles/runfiles_test.go
@@ -0,0 +1,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")
+ }
+}