Skip to content

Commit 6258b77

Browse files
add test case for installed executable
1 parent f6762ba commit 6258b77

6 files changed

Lines changed: 24 additions & 11 deletions

File tree

examples/git_gem/.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.1
1+
../../.bazelversion

examples/git_gem/BUILD

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
load("@rules_ruby//ruby:defs.bzl", "rb_binary", "rb_test")
22

3-
# A simple binary that uses the Git-sourced hello_world gem
43
rb_binary(
54
name = "greeter",
65
srcs = ["greeter.rb"],
76
deps = ["@bundle"],
87
)
98

10-
# Test that verifies the Git-sourced gem works correctly
119
rb_test(
1210
name = "greeter_test",
1311
srcs = ["greeter_test.rb"],
1412
deps = ["@bundle"],
1513
)
14+
15+
rb_test(
16+
name = "hello_world_bin_test",
17+
srcs = ["hello_world_bin_test.rb"],
18+
args = ["$(rlocationpath @bundle//bin:hello_world)"],
19+
data = ["@bundle//bin:hello_world"],
20+
main = "hello_world_bin_test.rb",
21+
)

examples/git_gem/Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ source "https://rubygems.org"
44

55
# Reference hello_world gem from the rules_ruby repository on GitHub
66
gem "hello_world",
7-
git: "https://github.com/bazel-contrib/rules_ruby.git",
7+
git: "https://github.com/withered-magic/rules_ruby.git",
88
glob: "examples/deep_gem/hello_world/*.gemspec",
9-
ref: "2c98fcaf4d60007a351c6e9a15678d64e1cc4cda"
9+
ref: "f6762ba5610170f69f28cdd5523697c357ed95e2"

examples/git_gem/Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GIT
2-
remote: https://github.com/bazel-contrib/rules_ruby.git
3-
revision: 2c98fcaf4d60007a351c6e9a15678d64e1cc4cda
4-
ref: 2c98fcaf4d60007a351c6e9a15678d64e1cc4cda
2+
remote: https://github.com/withered-magic/rules_ruby.git
3+
revision: f6762ba5610170f69f28cdd5523697c357ed95e2
4+
ref: f6762ba5610170f69f28cdd5523697c357ed95e2
55
glob: examples/deep_gem/hello_world/*.gemspec
66
specs:
77
hello_world (0.0.0)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
binary = File.join(ENV["TEST_SRCDIR"], ARGV[0])
2+
output = `#{binary} 2>&1`
3+
raise "Binary exited with code #{$?.exitstatus}: #{output}" unless $?.success?
4+
raise "Expected 'Hello, World', got '#{output.strip}'" unless output.include?("Hello, World")
5+
puts "PASS: Got expected output 'Hello, World'"

ruby/private/bundle_fetch.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ def _get_executables_from_dir(contents):
127127

128128
def _process_git_gem_directory(rctx, directory):
129129
# type: (repository_ctx, string) -> list[string]
130-
"""Walk git gem directory to find executables and delete BUILD files.
130+
"""Walk git gem directory to find executables and delete conflicting files.
131131
132132
This function iteratively traverses the directory tree to:
133-
1. Delete BUILD and BUILD.bazel files (so glob can traverse the directory)
133+
1. Delete BUILD, BUILD.bazel, and workspace marker files that could
134+
conflict with or confuse Bazel (e.g. .bazelversion, WORKSPACE,
135+
WORKSPACE.bazel, MODULE.bazel)
134136
2. Find directories containing .gemspec files
135137
3. Collect executables from bin/exe directories near gemspec files
136138
@@ -149,7 +151,7 @@ def _process_git_gem_directory(rctx, directory):
149151
break
150152
current = dirs_to_visit[i]
151153
for child in current.readdir():
152-
if child.basename in ("BUILD", "BUILD.bazel"):
154+
if child.basename in ("BUILD", "BUILD.bazel", ".bazelversion", "WORKSPACE", "WORKSPACE.bazel", "MODULE.bazel"):
153155
rctx.delete(child)
154156
elif child.is_dir:
155157
dirs_to_visit.append(child)

0 commit comments

Comments
 (0)