44 "ruby_test" ,
55)
66
7+ # Checks if args are correctly passed to the ruby script.
8+ ruby_test (
9+ name = "args_check_ruby_test" ,
10+ srcs = ["args_check.rb" ],
11+ args = [
12+ "foo" ,
13+ "bar" ,
14+ "baz" ,
15+ ],
16+ main = "args_check.rb" ,
17+ )
18+
19+ ruby_binary (
20+ name = "args_check" ,
21+ srcs = ["args_check.rb" ],
22+ )
23+
24+ # Checks if a ruby_binary is a valid src in sh_* rules
25+ sh_test (
26+ name = "args_check_sh_test" ,
27+ srcs = ["args_check" ],
28+ args = [
29+ "foo" ,
30+ "bar" ,
31+ "baz" ,
32+ ],
33+ )
34+
35+ ruby_test (
36+ name = "include_order_check" ,
37+ srcs = ["include_order_check.rb" ],
38+ deps = [
39+ "//ruby/tests/testdata:a" ,
40+ "//ruby/tests/testdata:b" ,
41+ "//ruby/tests/testdata:c" ,
42+ "//ruby/tests/testdata:f" ,
43+ ],
44+ )
45+
746# Tests if :ruby_bin can run in sh_binary
847sh_test (
948 name = "runtime_run_ruby_test" ,
@@ -36,46 +75,52 @@ genrule(
3675 "@org_ruby_lang_ruby_host//:ruby_bin" ,
3776 "@org_ruby_lang_ruby_host//:runtime" ,
3877 ],
78+ message = "Running ruby_bin in genrule" ,
3979)
4080
4181sh_test (
4282 name = "genrule_run_ruby_test" ,
4383 srcs = ["genrules_run_ruby_test.sh" ],
4484)
4585
46- ruby_binary (
47- name = "args_check" ,
48- srcs = ["args_check.rb" ],
49- )
50-
51- sh_test (
52- name = "args_test" ,
53- srcs = ["args_check" ],
54- args = [
55- "foo" ,
56- "bar" ,
57- "baz" ,
58- ],
59- )
86+ ## Runfiles resolution tests
87+ #
88+ # As explained in
89+ # https://github.com/bazelbuild/rules_nodejs/blob/be7232ecfd487432072938f3a39886be32f02606/internal/node/node_launcher.sh#L49,
90+ # the runfiles resolution in a program X need to support the following cases
91+ #
92+ # 1a) directly by a user, with $0 in the output tree
93+ # 1b) via 'bazel run' (similar to case 1a)
94+ # 2) directly by a user, with $0 in X's runfiles
95+ # 3) by another program Y which has a data dependency on X, with $0 in Y's
96+ # runfiles
97+ # 4a) via 'bazel test'
98+ # 4b) case 3 in the context of a test
99+ # 5a) by a genrule cmd, with $0 in the output tree
100+ # 6a) case 3 in the context of a genrule
101+ #
102+ # Also all of the cases above must correctly configure environment variables
103+ # so that their subprocesses whose binaries are generated by Bazel can run with
104+ # their runfiles.
60105
61106ruby_binary (
62- name = "include_order_check" ,
63- srcs = ["include_order_check.rb" ],
107+ name = "load_path_in_runfiles" ,
108+ srcs = ["load_path_in_runfiles_test.rb" ],
109+ main = "load_path_in_runfiles_test.rb" ,
64110 deps = [
65- "//ruby/tests/testdata:a" ,
66- "//ruby/tests/testdata:b" ,
67- "//ruby/tests/testdata:c" ,
68- "//ruby/tests/testdata:f" ,
111+ "//ruby/tests/testdata:g" ,
112+ "@bazelruby_ruby_rules_ruby_tests_testdata_another_workspace//baz/qux:j" ,
69113 ],
70114)
71115
72- sh_test (
73- name = "include_order_test " ,
74- srcs = ["include_order_check " ],
116+ sh_binary (
117+ name = "load_path_in_runfiles_sh_binary " ,
118+ srcs = [":load_path_in_runfiles " ],
75119)
76120
121+ # runfiles resolution test (case 4a)
77122ruby_test (
78- name = "load_path_in_runfiles " ,
123+ name = "load_path_in_runfiles_test_4a " ,
79124 srcs = ["load_path_in_runfiles_test.rb" ],
80125 main = "load_path_in_runfiles_test.rb" ,
81126 deps = [
@@ -84,6 +129,46 @@ ruby_test(
84129 ],
85130)
86131
132+ # runfiles resolution test (case 4b)
133+ sh_test (
134+ name = "load_path_in_runfiles_test_4b" ,
135+ srcs = ["load_path_in_runfiles_test_3.sh" ],
136+ data = [":load_path_in_runfiles_sh_binary" ],
137+ )
138+
139+ genrule (
140+ name = "generate_loadpath_test_driver_3" ,
141+ outs = ["load_path_in_runfiles_test_3.sh" ],
142+ cmd = " && " .join ([
143+ "echo '#!/bin/sh -e' > $@" ,
144+ "echo 'exec ruby/tests/load_path_in_runfiles' >> $@" ,
145+ ]),
146+ executable = True ,
147+ )
148+
149+ # runfiles resolution test (case 5a)
150+ sh_test (
151+ name = "load_path_in_runfiles_test_5a" ,
152+ srcs = ["load_path_in_runfiles_test_5a.sh" ],
153+ )
154+
155+ genrule (
156+ name = "dummy_genfile_load_path_in_runfiles" ,
157+ message = "Running :load_path_in_runfiles in genrule" ,
158+ outs = ["load_path_in_runfiles_test_5a.sh" ],
159+ tools = [":load_path_in_runfiles" ],
160+ cmd = " && " .join ([
161+ "$(location :load_path_in_runfiles)" ,
162+ "echo '#!/bin/sh -e' > $@" ,
163+ "echo 'true' >> $@" ,
164+ ]),
165+ executable = True ,
166+ )
167+
168+ # TODO(yugui) Add a test for case 6a.
169+
170+ ## end of Runfiles resolution tests
171+
87172cc_binary (
88173 name = "example_ext.so" ,
89174 testonly = True ,
0 commit comments