-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlauncher_spec.rb
263 lines (218 loc) · 9.14 KB
/
launcher_spec.rb
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
require File.expand_path('../spec_helper.rb', __FILE__)
load File.expand_path('../../lib/jruby-launcher.rb', __FILE__)
describe "JRuby native launcher" do
it "should run org.jruby.Main" do
expect(jruby_launcher_args("").last).to eq "org/jruby/Main"
end
it "should pass unrecognized arguments to JRuby" do
expect(jruby_launcher_args("-J-Dsome.option -v --help")[-3..-1]).to eq ["org/jruby/Main", "-v", "--help"]
end
it "should print help message" do
args = jruby_launcher_args("-Xhelp 2>&1")
expect(args.select {|l| l =~ /JRuby Launcher usage/}).not_to be_empty
expect(args).to include("-X")
args = jruby_launcher_args("-X 2>&1")
expect(args.detect {|l| l =~ /JRuby Launcher usage/}).not_to be_empty
expect(args).to include("-X")
end
it "should use $JAVACMD when JAVACMD is specified" do
with_environment "JAVACMD" => File.join("jato") do
if windows?
expect(jruby_launcher_args("-v 2>&1").join).to match %r{jato}
else
expect(jruby_launcher_args("-v").first).to eq File.join("jato")
end
end
end
it "should use $JAVA_HOME/bin/java when JAVA_HOME is specified" do
with_environment "JAVA_HOME" => File.join("some", "java", "home") do
if windows?
expect(jruby_launcher_args("-v 2>&1").join).to match %r{some/java/home}
else
expect(jruby_launcher_args("-v").first).to eq File.join("some", "java", "home", "bin", "java")
end
end
end
it "should use -Xjdkhome argument above JAVA_HOME" do
with_environment "JAVA_HOME" => File.join("env", "java", "home") do
if windows?
expect(jruby_launcher_args("-Xjdkhome some/java/home 2>&1").join).to match %r{some/java/home}
else
expect(jruby_launcher_args("-Xjdkhome some/java/home").first).to eq File.join("some", "java", "home", "bin", "java")
end
end
end
it "should drop the backslashes at the end of JAVA_HOME" do
with_environment "JAVA_HOME" => File.join("some", "java", "home\\\\") do
if windows?
expect(jruby_launcher_args("").join).to match %r{some/java/home}
else
expect(jruby_launcher_args("").first).to eq File.join("some", "java", "home", "bin", "java")
end
end
end
it "should complain about a missing log argument" do
expect(jruby_launcher("-Xtrace 2>&1")).to match /Argument is missing for "-Xtrace"/
expect(jruby_launcher("-Xtrace -- 2>&1")).to match /Argument is missing for "-Xtrace"/
end
it "should complain about a missing jdkhome argument" do
expect(jruby_launcher("-Xjdkhome 2>&1")).to match /Argument is missing/
expect(jruby_launcher("-Xjdkhome -- 2>&1")).to match /Argument is missing/
end
it "should complain about a missing classpath append argument" do
expect(jruby_launcher("-Xcp:a 2>&1")).to match /Argument is missing/
expect(jruby_launcher("-Xcp:a -- 2>&1")).to match /Argument is missing/
end
it "should run nailgun server with --ng-server option" do
expect(jruby_launcher_args("--ng-server").last).to eq "com/martiansoftware/nailgun/NGServer"
end
it "should run nailgun client with --ng option" do
expect(jruby_launcher_args('--ng -e "puts 1"')).to eq ["org.jruby.util.NailMain", "-e", "puts 1"]
end
it "should handle -J JVM options" do
expect(jruby_launcher_args("-J-Darg1=value1 -J-Darg2=value2")).to include("-Darg1=value1", "-Darg2=value2")
end
it "should pass -Xprop.erty=value as -J-Djruby.prop.erty=value" do
expect(jruby_launcher_args("-Xprop.erty=value")).to include("-Djruby.prop.erty=value")
end
it "should pass -Xproperties as --properties" do
expect(jruby_launcher_args("-Xproperties")).to include("--properties")
end
it "should default to 500m max heap" do
expect(jruby_launcher_args("")).to include("-Xmx500m")
end
it "should allow max heap to be overridden" do
expect(jruby_launcher_args("-J-Xmx256m")).to include("-Xmx256m")
end
it "should default to 2048k max stack" do
expect(jruby_launcher_args("")).to include("-Xss2048k")
end
it "should allow max stack to be overridden" do
expect(jruby_launcher_args("-J-Xss512k")).to include("-Xss512k")
end
it "should add the contents of the CLASSPATH environment variable" do
with_environment "CLASSPATH" => "some.jar" do
expect(classpath_arg(jruby_launcher_args(""))).to match /some.jar/
end
end
it "should add the classpath elements in proper order" do
s = File::PATH_SEPARATOR
with_environment "CLASSPATH" => "some-env.jar" do
args = jruby_launcher_args("-Xcp:a some-other.jar -Xcp:p some.jar")
expect(classpath_arg(args)).to match /some.jar.*#{s}some-env.jar#{s}some-other.jar/
end
end
it "should use the --server compiler" do
expect(jruby_launcher_args("--server")).to include("-server")
end
it "should use the --client compiler" do
expect(jruby_launcher_args("--client")).to include("-client")
end
it "should set the JMX settings when --manage is present" do
expect(jruby_launcher_args("--manage")).to include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
end
it "should set the headless flag when --headless is present" do
expect(jruby_launcher_args("--headless")).to include("-Djava.awt.headless=true")
end
it "should pass -Xprof when --sample is present" do
expect(jruby_launcher_args("--sample")).to include("-Xprof")
end
it "should stop argument processing when a -- is seen" do
expect(jruby_launcher_args("-- -Xhelp -Xtrace --headless")).to include("-Xhelp", "-Xtrace", "--headless")
end
# JRUBY-4151
it "should properly handle single quotes" do
expect(jruby_launcher_args("-e 'ABC DEF'")).to include("ABC DEF")
end
# JRUBY-4581
it "should prepend JRUBY_OPTS to the start of the argument list to process" do
with_environment "JRUBY_OPTS" => "--server -J-Dsome.key=val -rubygems" do
expect(jruby_launcher_args("-e 'ABC DEF'")).to include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
end
end
# JRUBY-4611
it "stops argument processing on first non-option argument" do
expect(jruby_launcher_args("foo.rb --sample")[-2..-1]).to eq ["foo.rb", "--sample"]
end
# JRUBY-4608
if RbConfig::CONFIG['target_os'] =~ /darwin/i
it "includes file.encoding=UTF-8 on Mac if JAVA_ENCODING is not set" do
expect(jruby_launcher_args("-e true")).to include("-Dfile.encoding=UTF-8")
with_environment "JAVA_ENCODING" => "MacRoman" do
expect(jruby_launcher_args("-e true")).not_to include("-Dfile.encoding=UTF-8")
end
end
end
it "does not crash on empty args" do
expect(jruby_launcher_args("-e ''")).to include("-e")
expect(jruby_launcher("-Xtrace '' 2>&1")).to match /-Xtrace/
expect(jruby_launcher("-Xjdkhome '' 2>&1")).to match /-Xjdkhome/
end
# JRUBY-4706
it "should put JRuby on regular classpath when -Xnobootclasspath is used" do
args = jruby_launcher_args("-e true")
expect(args.grep(/Xbootclasspath/)).not_to be_empty
args = jruby_launcher_args("-Xnobootclasspath -e true")
expect(args.grep(/Xbootclasspath/)).to be_empty
end
it "should put JRuby on regular classpath when VERIFY_JRUBY is set" do
with_environment "VERIFY_JRUBY" => "true" do
args = jruby_launcher_args("-e true")
expect(args.grep(/Xbootclasspath/)).to be_empty
end
end
# JRUBY-4709
it "should include a bare : or ; at the end of the classpath, to include PWD in the path" do
end_of_path_pattern = if windows?
/;$/
else
/:$/
end
expect(classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true"))).to match end_of_path_pattern
end
# JRUBY-6016
it "should honor JAVA_MEM" do
with_environment "JAVA_MEM" => "-Xmx768m" do
expect(jruby_launcher_args("")).to include("-Xmx768m")
end
end
it "should honor JAVA_STACK" do
with_environment "JAVA_STACK" => "-Xss3072k" do
expect(jruby_launcher_args("")).to include("-Xss3072k")
end
end
it "should honor JRUBY_HOME" do
with_environment "JRUBY_HOME" => "/tmp" do
expect(jruby_launcher_args("")).to include("-Djruby.home=/tmp")
end
end
context "JRUBY_HOME set and JRUBY_HOME/lib/jruby.jar exists" do
let(:jruby_home) do
require 'tempfile'
t = Tempfile.new("jruby_home")
t.path.tap { t.close! }
end
before do
FileUtils.mkdir_p(File.join(jruby_home, "lib"))
FileUtils.touch(File.join(jruby_home, "lib", "jruby.jar"))
end
after { FileUtils.rm_rf jruby_home }
it "should add jruby.jar to the bootclasspath" do
with_environment "JRUBY_HOME" => jruby_home do
expect(jruby_launcher_args("")).to include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
end
end
end
it "should place user-supplied options after default options" do
args = jruby_launcher_args("-J-Djruby.home=/tmp")
home_args = args.select {|x| x =~ /^-Djruby\.home/ }
expect(home_args.length).to eq 2
expect(home_args.last).to eq "-Djruby.home=/tmp"
end
it "should print the version" do
expect(jruby_launcher("-Xversion 2>&1")).to match /Launcher Version #{JRubyLauncher::VERSION}/
end
it "should not crash on format-strings" do
expect(jruby_launcher_args("-e %s%s%s%s%s 2>&1")).to include('-e', '%s%s%s%s%s')
end
end