Skip to content

Commit dc940e9

Browse files
committed
Add test
1 parent 16f3e4b commit dc940e9

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

examples/bzlmod/other_module/other_module/pkg/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@rules_python//python:py_binary.bzl", "py_binary")
22
load("@rules_python//python:py_library.bzl", "py_library")
3+
load("@rules_python//python/zipapp:py_zipapp_binary.bzl", "py_zipapp_binary")
34

45
py_library(
56
name = "lib",
@@ -26,4 +27,13 @@ py_binary(
2627
],
2728
)
2829

30+
# This is used for regression testing runfiles paths in submodules.
31+
# https://github.com/bazel-contrib/rules_python/issues/3563.
32+
py_zipapp_binary(
33+
name = "bin_zipapp",
34+
testonly = True,
35+
binary = ":bin",
36+
visibility = ["//visibility:public"],
37+
)
38+
2939
exports_files(["data/data.txt"])

examples/bzlmod/tests/other_module/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
# in the root module.
66

77
load("@bazel_skylib//rules:build_test.bzl", "build_test")
8+
load("@rules_python//python:py_test.bzl", "py_test")
89

910
build_test(
1011
name = "other_module_bin_build_test",
1112
targets = [
1213
"@our_other_module//other_module/pkg:bin",
1314
],
1415
)
16+
17+
py_test(
18+
name = "other_module_import_test",
19+
srcs = ["other_module_import_test.py"],
20+
data = ["@our_other_module//other_module/pkg:bin_zipapp"],
21+
env = {"ZIPAPP_PATH": "$(location @our_other_module//other_module/pkg:bin_zipapp)"},
22+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Regression test for https://github.com/bazel-contrib/rules_python/issues/3563"""
2+
import os
3+
import subprocess
4+
import sys
5+
6+
def main():
7+
# The rlocation path for the bin_zipapp. It is in the "our_other_module" repository.
8+
zipapp_path = os.environ.get("ZIPAPP_PATH")
9+
print(f"Running bin_zipapp at: {zipapp_path}")
10+
11+
result = subprocess.run([zipapp_path], capture_output=True, text=True)
12+
print("--- bin_zippapp stdout ---")
13+
print(result.stdout)
14+
print("--- bin_zippapp stderr ---")
15+
print(result.stderr)
16+
17+
if result.returncode != 0:
18+
print(f"bin_zippapp failed with return code {result.returncode}")
19+
sys.exit(result.returncode)
20+
21+
if __name__ == "__main__":
22+
main()

0 commit comments

Comments
 (0)