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
|
require 'test/unit'
require 'test/test_helper'
class TestLaunchingByShellScript < Test::Unit::TestCase
include TestHelper
def test_minus_e
assert_equal "true", jruby('-e "puts true"').chomp
assert_equal 0, $?.exitstatus
end
def test_launch_script
jruby "test/fib.rb"
assert_equal 0, $?.exitstatus
end
# JRUBY-4042
def test_jruby_without_args
jruby_with_pipe("echo puts 1")
assert_equal 0, $?.exitstatus
end
# JRUBY-4045
def test_with_pipe_chars
out = jruby('-e "(1..3).each{|f| print f}"') # no space after each
assert_equal 0, $?.exitstatus
assert_equal "123", out
out = jruby('-e "(1..3).each {|f| print f}"') # space after each
assert_equal 0, $?.exitstatus
assert_equal "123", out
end
# JRUBY-3159
def test_escaping_chars_in_vmopts_processing
out = jruby(%{-e "a = 'sq'; print a; (1..3).each {|f| print f}"})
assert_equal 0, $?.exitstatus
assert_equal "sq123", out
end
# JRUBY-3524
def test_with_less_and_more
out = jruby('-e "print 2 > 1; print 1<2; print 1== 2"')
assert_equal 0, $?.exitstatus
assert_equal "truetruefalse", out
end
# JRUBY-4055
def test_with_question_and_caret
out = jruby('-e "print nil.nil?; print 1 ^ 2"')
assert_equal 0, $?.exitstatus
assert_equal "true3", out
end
# JRUBY-4058
def test_with_percent
out = jruby(%{-e "print '%A%%B%%%C%%%%D'"})
assert_equal 0, $?.exitstatus
assert_equal "%A%%B%%%C%%%%D", out
end
if WINDOWS
def test_system_call_without_stdin_data_doesnt_hang
out = jruby(%q{-e "system 'dir test'"})
assert(out =~ /fib.rb/)
end
def test_system_call_with_stdin_data_doesnt_hang_on_windows
out = jruby_with_pipe("echo echo 'one_two_three_test'", %q{-e "system 'cmd'"})
assert(out =~ /one_two_three_test/)
end
else
def test_system_call_with_stdin_data_doesnt_hang
out = jruby_with_pipe("echo 'vvs'", %q{-e "system 'cat'"})
assert_equal("vvs\n", out)
end
end
if (!WINDOWS)
# JRUBY-2295
def test_java_props_with_spaces
res = jruby(%q{-J-Dfoo='a b c' -e "require 'java'; puts java.lang.System.getProperty('foo')"}).chomp
assert_equal("a b c", res)
end
# JRUBY-2615, and see JRUBY-JRUBY-3040 on the IBM JVM disabling
require 'rbconfig'
unless IBM_JVM
def test_interactive_child_process
lines = []
IO.popen(%q{sh -c 'echo enter something:; read value; echo got: $value; read value'}, 'r+') do |handle|
begin
while (line = handle.readline)
lines << line
handle.puts('foobar')
end
rescue EOFError
lines << "STDIN closed"
end
end
assert_equal(["enter something:\n", "got: foobar\n", "STDIN closed"], lines)
end
end
end
def test_at_exit
assert_equal "", jruby('-e "at_exit { exit 0 }"').chomp
assert_equal 0, $?.exitstatus
assert_equal "", jruby('-e "at_exit { exit 1 }"').chomp
assert_equal 1, $?.exitstatus
end
# JRUBY-2809
def test_mulitple_at_exit
assert_equal "", jruby('-e "at_exit { exit 1 }; at_exit { exit 2 }"').chomp
# first exit status wins
assert_equal 1, $?.exitstatus
# exception in one at_exit doesn't affect other at_exit blocks
result = with_temp_script(%Q{
at_exit { exit 111 }
at_exit { raise ArgumentError }
at_exit { exit 222 }
at_exit { raise RuntimeError }
}) do |s|
jruby("#{s.path} 2>&1")
end
# first goes RuntimeError, then ArgumentError
assert_match(/RuntimeError.*ArgumentError/m, result)
# the first exit status wins
assert_equal 111, $?.exitstatus
# exit status from exception is 1
result = with_temp_script(%Q{
at_exit { raise ArgumentError }
at_exit { exit 222 }
}) do |s|
jruby("#{s.path} 2>&1")
end
# first goes RuntimeError, then ArgumentError
assert_match(/ArgumentError/m, result)
# the first exit status wins
assert_equal 1, $?.exitstatus
# exit in one block doesn't stop other blocks from executing
result = with_temp_script(%Q{
at_exit { exit 111 }
at_exit { print "one" }
at_exit { exit 222 }
at_exit { print "two" }
}) do |s|
jruby("#{s.path}")
end
assert_equal "twoone", result
assert_equal 111, $?.exitstatus
# exit! in one block prevents execution of others
result = with_temp_script(%Q{
at_exit { exit! 1 }
at_exit { print "one" }
at_exit { exit! 2 }
at_exit { print "two" }
}) do |s|
jruby("#{s.path}")
end
assert_equal "two", result
assert_equal 2, $?.exitstatus
end
# JRUBY-4238
def test_run_script_from_jar
file = "file:" + File.expand_path("test/jar_with_ruby_files.jar") + "!/run_hello_from_jar.rb"
out = jruby(file)
assert_equal 0, $?.exitstatus
assert_equal "hello", out.strip
end
end
|