1# -*- coding: us-ascii -*- 2require 'test/unit' 3 4require 'tmpdir' 5require 'tempfile' 6require 'pathname' 7 8require_relative 'envutil' 9 10class TestRubyOptions < Test::Unit::TestCase 11 def write_file(filename, content) 12 File.open(filename, "w") {|f| 13 f << content 14 } 15 end 16 17 def with_tmpchdir 18 Dir.mktmpdir {|d| 19 d = Pathname.new(d).realpath.to_s 20 Dir.chdir(d) { 21 yield d 22 } 23 } 24 end 25 26 def test_source_file 27 assert_in_out_err([], "", [], []) 28 end 29 30 def test_usage 31 assert_in_out_err(%w(-h)) do |r, e| 32 assert_operator(r.size, :<=, 24) 33 longer = r[1..-1].select {|x| x.size > 80} 34 assert_equal([], longer) 35 assert_equal([], e) 36 end 37 end 38 39 def test_usage_long 40 assert_in_out_err(%w(--help)) do |r, e| 41 longer = r[1..-1].select {|x| x.size > 80} 42 assert_equal([], longer) 43 assert_equal([], e) 44 end 45 end 46 47 def test_option_variables 48 assert_in_out_err(["-e", 'p [$-p, $-l, $-a]']) do |r, e| 49 assert_equal(["[false, false, false]"], r) 50 assert_equal([], e) 51 end 52 53 assert_in_out_err(%w(-p -l -a -e) + ['p [$-p, $-l, $-a]'], 54 "foo\nbar\nbaz\n") do |r, e| 55 assert_equal( 56 [ '[true, true, true]', 'foo', 57 '[true, true, true]', 'bar', 58 '[true, true, true]', 'baz' ], r) 59 assert_equal([], e) 60 end 61 end 62 63 def test_warning 64 save_rubyopt = ENV['RUBYOPT'] 65 ENV['RUBYOPT'] = nil 66 assert_in_out_err(%w(-W0 -e) + ['p $-W'], "", %w(0), []) 67 assert_in_out_err(%w(-W1 -e) + ['p $-W'], "", %w(1), []) 68 assert_in_out_err(%w(-Wx -e) + ['p $-W'], "", %w(1), []) 69 assert_in_out_err(%w(-W -e) + ['p $-W'], "", %w(2), []) 70 ensure 71 ENV['RUBYOPT'] = save_rubyopt 72 end 73 74 def test_safe_level 75 assert_in_out_err(%w(-T -e) + [""], "", [], 76 /no -e allowed in tainted mode \(SecurityError\)/) 77 78 assert_in_out_err(%w(-T4 -S foo.rb), "", [], 79 /no -S allowed in tainted mode \(SecurityError\)/) 80 end 81 82 def test_debug 83 assert_in_out_err(["--disable-gems", "-de", "p $DEBUG"], "", %w(true), []) 84 85 assert_in_out_err(["--disable-gems", "--debug", "-e", "p $DEBUG"], 86 "", %w(true), []) 87 end 88 89 def test_verbose 90 assert_in_out_err(["-vve", ""]) do |r, e| 91 assert_match(/^ruby #{RUBY_VERSION}(?:[p ]|dev).*? \[#{RUBY_PLATFORM}\]$/, r.join) 92 assert_equal RUBY_DESCRIPTION, r.join.chomp 93 assert_equal([], e) 94 end 95 96 assert_in_out_err(%w(--verbose -e) + ["p $VERBOSE"], "", %w(true), []) 97 98 assert_in_out_err(%w(--verbose), "", [], []) 99 end 100 101 def test_copyright 102 assert_in_out_err(%w(--copyright), "", 103 /^ruby - Copyright \(C\) 1993-\d+ Yukihiro Matsumoto$/, []) 104 105 assert_in_out_err(%w(--verbose -e) + ["p $VERBOSE"], "", %w(true), []) 106 end 107 108 def test_enable 109 assert_in_out_err(%w(--enable all -e) + [""], "", [], []) 110 assert_in_out_err(%w(--enable-all -e) + [""], "", [], []) 111 assert_in_out_err(%w(--enable=all -e) + [""], "", [], []) 112 assert_in_out_err(%w(--enable foobarbazqux -e) + [""], "", [], 113 /unknown argument for --enable: `foobarbazqux'/) 114 assert_in_out_err(%w(--enable), "", [], /missing argument for --enable/) 115 end 116 117 def test_disable 118 assert_in_out_err(%w(--disable all -e) + [""], "", [], []) 119 assert_in_out_err(%w(--disable-all -e) + [""], "", [], []) 120 assert_in_out_err(%w(--disable=all -e) + [""], "", [], []) 121 assert_in_out_err(%w(--disable foobarbazqux -e) + [""], "", [], 122 /unknown argument for --disable: `foobarbazqux'/) 123 assert_in_out_err(%w(--disable), "", [], /missing argument for --disable/) 124 end 125 126 def test_kanji 127 assert_in_out_err(%w(-KU), "p '\u3042'") do |r, e| 128 assert_equal("\"\u3042\"", r.join.force_encoding(Encoding::UTF_8)) 129 end 130 line = '-eputs"\xc2\xa1".encoding' 131 env = {'RUBYOPT' => nil} 132 assert_in_out_err([env, '-Ke', line], "", ["EUC-JP"], []) 133 assert_in_out_err([env, '-KE', line], "", ["EUC-JP"], []) 134 assert_in_out_err([env, '-Ks', line], "", ["Windows-31J"], []) 135 assert_in_out_err([env, '-KS', line], "", ["Windows-31J"], []) 136 assert_in_out_err([env, '-Ku', line], "", ["UTF-8"], []) 137 assert_in_out_err([env, '-KU', line], "", ["UTF-8"], []) 138 assert_in_out_err([env, '-Kn', line], "", ["ASCII-8BIT"], []) 139 assert_in_out_err([env, '-KN', line], "", ["ASCII-8BIT"], []) 140 assert_in_out_err([env, '-wKe', line], "", ["EUC-JP"], /-K/) 141 end 142 143 def test_version 144 assert_in_out_err(%w(--version)) do |r, e| 145 assert_match(/^ruby #{RUBY_VERSION}(?:[p ]|dev).*? \[#{RUBY_PLATFORM}\]$/, r.join) 146 assert_equal RUBY_DESCRIPTION, r.join.chomp 147 assert_equal([], e) 148 end 149 end 150 151 def test_eval 152 assert_in_out_err(%w(-e), "", [], /no code specified for -e \(RuntimeError\)/) 153 end 154 155 def test_require 156 require "pp" 157 assert_in_out_err(%w(-r pp -e) + ["pp 1"], "", %w(1), []) 158 assert_in_out_err(%w(-rpp -e) + ["pp 1"], "", %w(1), []) 159 assert_in_out_err(%w(-ep\ 1 -r), "", %w(1), []) 160 assert_in_out_err(%w(-r), "", [], []) 161 rescue LoadError 162 end 163 164 def test_include 165 d = Dir.tmpdir 166 assert_in_out_err(["-I" + d, "-e", ""], "", [], []) 167 assert_in_out_err(["-I", d, "-e", ""], "", [], []) 168 end 169 170 def test_separator 171 assert_in_out_err(%w(-000 -e) + ["print gets"], "foo\nbar\0baz", %W(foo bar\0baz), []) 172 173 assert_in_out_err(%w(-0141 -e) + ["print gets"], "foo\nbar\0baz", %w(foo ba), []) 174 175 assert_in_out_err(%w(-0e) + ["print gets"], "foo\nbar\0baz", %W(foo bar\0), []) 176 end 177 178 def test_autosplit 179 assert_in_out_err(%w(-an -F: -e) + ["p $F"], "foo:bar:baz\nqux:quux:quuux\n", 180 ['["foo", "bar", "baz\n"]', '["qux", "quux", "quuux\n"]'], []) 181 end 182 183 def test_chdir 184 assert_in_out_err(%w(-C), "", [], /Can't chdir/) 185 186 assert_in_out_err(%w(-C test_ruby_test_rubyoptions_foobarbazqux), "", [], /Can't chdir/) 187 188 d = Dir.tmpdir 189 assert_in_out_err(["-C", d, "-e", "puts Dir.pwd"]) do |r, e| 190 assert(File.identical?(r.join, d)) 191 assert_equal([], e) 192 end 193 end 194 195 def test_yydebug 196 assert_in_out_err(["-ye", ""]) do |r, e| 197 assert_equal([], r) 198 assert_not_equal([], e) 199 end 200 201 assert_in_out_err(%w(--yydebug -e) + [""]) do |r, e| 202 assert_equal([], r) 203 assert_not_equal([], e) 204 end 205 end 206 207 def test_encoding 208 assert_in_out_err(%w(--encoding), "", [], /missing argument for --encoding/) 209 210 assert_in_out_err(%w(--encoding test_ruby_test_rubyoptions_foobarbazqux), "", [], 211 /unknown encoding name - test_ruby_test_rubyoptions_foobarbazqux \(RuntimeError\)/) 212 213 if /mswin|mingw/ =~ RUBY_PLATFORM && 214 (str = "\u3042".force_encoding(Encoding.find("locale"))).valid_encoding? 215 # This result depends on locale because LANG=C doesn't affect locale 216 # on Windows. 217 out, err = [str], [] 218 else 219 out, err = [], /invalid multibyte char/ 220 end 221 assert_in_out_err(%w(-Eutf-8), "puts '\u3042'", out, err) 222 assert_in_out_err(%w(--encoding utf-8), "puts '\u3042'", out, err) 223 end 224 225 def test_syntax_check 226 assert_in_out_err(%w(-c -e a=1+1 -e !a), "", ["Syntax OK"], []) 227 end 228 229 def test_invalid_option 230 assert_in_out_err(%w(--foobarbazqux), "", [], /invalid option --foobarbazqux/) 231 232 assert_in_out_err(%W(-\r -e) + [""], "", [], []) 233 234 assert_in_out_err(%W(-\rx), "", [], /invalid option -\\x0D \(-h will show valid options\) \(RuntimeError\)/) 235 236 assert_in_out_err(%W(-\x01), "", [], /invalid option -\\x01 \(-h will show valid options\) \(RuntimeError\)/) 237 238 assert_in_out_err(%w(-Z), "", [], /invalid option -Z \(-h will show valid options\) \(RuntimeError\)/) 239 end 240 241 def test_rubyopt 242 rubyopt_orig = ENV['RUBYOPT'] 243 244 ENV['RUBYOPT'] = ' - -' 245 assert_in_out_err([], "", [], []) 246 247 ENV['RUBYOPT'] = '-e "p 1"' 248 assert_in_out_err([], "", [], /invalid switch in RUBYOPT: -e \(RuntimeError\)/) 249 250 ENV['RUBYOPT'] = '-T1' 251 assert_in_out_err(["--disable-gems"], "", [], /no program input from stdin allowed in tainted mode \(SecurityError\)/) 252 253 ENV['RUBYOPT'] = '-T4' 254 assert_in_out_err(["--disable-gems"], "", [], /no program input from stdin allowed in tainted mode \(SecurityError\)/) 255 256 ENV['RUBYOPT'] = '-Eus-ascii -KN' 257 assert_in_out_err(%w(-Eutf-8 -KU), "p '\u3042'") do |r, e| 258 assert_equal("\"\u3042\"", r.join.force_encoding(Encoding::UTF_8)) 259 assert_equal([], e) 260 end 261 262 ensure 263 if rubyopt_orig 264 ENV['RUBYOPT'] = rubyopt_orig 265 else 266 ENV.delete('RUBYOPT') 267 end 268 end 269 270 def test_search 271 rubypath_orig = ENV['RUBYPATH'] 272 path_orig = ENV['PATH'] 273 274 t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"]) 275 t.puts "p 1" 276 t.close 277 278 @verbose = $VERBOSE 279 $VERBOSE = nil 280 281 ENV['PATH'] = File.dirname(t.path) 282 283 assert_in_out_err(%w(-S) + [File.basename(t.path)], "", %w(1), []) 284 285 ENV['RUBYPATH'] = File.dirname(t.path) 286 287 assert_in_out_err(%w(-S) + [File.basename(t.path)], "", %w(1), []) 288 289 ensure 290 if rubypath_orig 291 ENV['RUBYPATH'] = rubypath_orig 292 else 293 ENV.delete('RUBYPATH') 294 end 295 if path_orig 296 ENV['PATH'] = path_orig 297 else 298 ENV.delete('PATH') 299 end 300 t.close(true) if t 301 $VERBOSE = @verbose 302 end 303 304 def test_shebang 305 assert_in_out_err([], "#! /test_r_u_b_y_test_r_u_b_y_options_foobarbazqux\r\np 1\r\n", 306 [], /: no Ruby script found in input/) 307 308 assert_in_out_err([], "#! /test_r_u_b_y_test_r_u_b_y_options_foobarbazqux -foo -bar\r\np 1\r\n", 309 [], /: no Ruby script found in input/) 310 311 assert_in_out_err([{'RUBYOPT' => nil}], "#!ruby -KU -Eutf-8\r\np \"\u3042\"\r\n") do |r, e| 312 assert_equal("\"\u3042\"", r.join.force_encoding(Encoding::UTF_8)) 313 assert_equal([], e) 314 end 315 316 bug4118 = '[ruby-dev:42680]' 317 assert_in_out_err(%w[], "#!/bin/sh\n""#!shebang\n""#!ruby\n""puts __LINE__\n", 318 %w[4], [], bug4118) 319 assert_in_out_err(%w[-x], "#!/bin/sh\n""#!shebang\n""#!ruby\n""puts __LINE__\n", 320 %w[4], [], bug4118) 321 end 322 323 def test_sflag 324 assert_in_out_err(%w(- -abc -def=foo -ghi-jkl -- -xyz), 325 "#!ruby -s\np [$abc, $def, $ghi_jkl, defined?($xyz)]\n", 326 ['[true, "foo", true, nil]'], []) 327 328 assert_in_out_err(%w(- -#), "#!ruby -s\n", [], 329 /invalid name for global variable - -# \(NameError\)/) 330 331 assert_in_out_err(%w(- -#=foo), "#!ruby -s\n", [], 332 /invalid name for global variable - -# \(NameError\)/) 333 end 334 335 def test_assignment_in_conditional 336 t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"]) 337 t.puts "if a = 1" 338 t.puts "end" 339 t.puts "0.times do" 340 t.puts " if b = 2" 341 t.puts " a += b" 342 t.puts " end" 343 t.puts "end" 344 t.close 345 warning = ' warning: found = in conditional, should be ==' 346 err = ["#{t.path}:1:#{warning}", 347 "#{t.path}:4:#{warning}", 348 ] 349 bug2136 = '[ruby-dev:39363]' 350 assert_in_out_err(["-w", t.path], "", [], err, bug2136) 351 assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, bug2136) 352 353 t.open 354 t.truncate(0) 355 t.puts "if a = ''; end" 356 t.puts "if a = []; end" 357 t.puts "if a = [1]; end" 358 t.puts "if a = [a]; end" 359 t.puts "if a = {}; end" 360 t.puts "if a = {1=>2}; end" 361 t.puts "if a = {3=>a}; end" 362 t.close 363 err = ["#{t.path}:1:#{warning}", 364 "#{t.path}:2:#{warning}", 365 "#{t.path}:3:#{warning}", 366 "#{t.path}:5:#{warning}", 367 "#{t.path}:6:#{warning}", 368 ] 369 feature4299 = '[ruby-dev:43083]' 370 assert_in_out_err(["-w", t.path], "", [], err, feature4299) 371 assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, feature4299) 372 ensure 373 t.close(true) if t 374 end 375 376 def test_indentation_check 377 t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"]) 378 t.puts "begin" 379 t.puts " end" 380 t.close 381 err = ["#{t.path}:2: warning: mismatched indentations at 'end' with 'begin' at 1"] 382 assert_in_out_err(["-w", t.path], "", [], err) 383 assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err) 384 385 t.open 386 t.puts "# -*- warn-indent: false -*-" 387 t.puts "begin" 388 t.puts " end" 389 t.close 390 assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]') 391 392 err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 3"] 393 t.open 394 t.puts "# -*- warn-indent: false -*-" 395 t.puts "# -*- warn-indent: true -*-" 396 t.puts "begin" 397 t.puts " end" 398 t.close 399 assert_in_out_err(["-w", t.path], "", [], err, '[ruby-core:25442]') 400 401 err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 2"] 402 t.open 403 t.puts "# -*- warn-indent: true -*-" 404 t.puts "begin" 405 t.puts "# -*- warn-indent: false -*-" 406 t.puts " end" 407 t.close 408 assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]') 409 ensure 410 t.close(true) if t 411 end 412 413 def test_notfound 414 notexist = "./notexist.rb" 415 rubybin = Regexp.quote(EnvUtil.rubybin) 416 pat = Regexp.quote(notexist) 417 bug1573 = '[ruby-core:23717]' 418 assert_file.not_exist?(notexist) 419 assert_in_out_err(["-r", notexist, "-ep"], "", [], /.* -- #{pat} \(LoadError\)/, bug1573) 420 assert_in_out_err([notexist], "", [], /#{rubybin}:.* -- #{pat} \(LoadError\)/, bug1573) 421 end 422 423 def test_program_name 424 ruby = EnvUtil.rubybin 425 IO.popen([ruby, '-e', 'print $0']) {|f| 426 assert_equal('-e', f.read) 427 } 428 IO.popen([ruby, '-'], 'r+') {|f| 429 f << 'print $0' 430 f.close_write 431 assert_equal('-', f.read) 432 } 433 Dir.mktmpdir {|d| 434 n1 = File.join(d, 't1') 435 open(n1, 'w') {|f| f << 'print $0' } 436 IO.popen([ruby, n1]) {|f| 437 assert_equal(n1, f.read) 438 } 439 if File.respond_to? :symlink 440 n2 = File.join(d, 't2') 441 File.symlink(n1, n2) 442 IO.popen([ruby, n2]) {|f| 443 assert_equal(n2, f.read) 444 } 445 end 446 Dir.chdir(d) { 447 n3 = '-e' 448 open(n3, 'w') {|f| f << 'print $0' } 449 IO.popen([ruby, '--', n3]) {|f| 450 assert_equal(n3, f.read) 451 } 452 n4 = '-' 453 IO.popen([ruby, '--', n4], 'r+') {|f| 454 f << 'print $0' 455 f.close_write 456 assert_equal(n4, f.read) 457 } 458 } 459 } 460 end 461 462 def test_set_program_name 463 skip "platform dependent feature" if /linux|freebsd|netbsd|openbsd|darwin/ !~ RUBY_PLATFORM 464 465 with_tmpchdir do 466 write_file("test-script", "$0 = 'hello world'; sleep 60") 467 468 pid = spawn(EnvUtil.rubybin, "test-script") 469 sleep 0.1 470 ps = `ps -p #{pid} -o command` 471 assert_match(/hello world/, ps) 472 Process.kill :KILL, pid 473 end 474 end 475 476 def test_segv_test 477 opts = {} 478 if /mswin|mingw/ =~ RUBY_PLATFORM 479 additional = '[\s\w\.\']*' 480 else 481 opts[:rlimit_core] = 0 482 additional = "" 483 end 484 expected_stderr = 485 %r(\A 486 -e:(?:1:)?\s\[BUG\]\sSegmentation\sfault\n 487 #{ Regexp.quote(RUBY_DESCRIPTION) }\n\n 488 (?:--\s(?:.+\n)*\n)? 489 --\sControl\sframe\sinformation\s-+\n 490 (?:c:.*\n)* 491 (?: 492 --\sRuby\slevel\sbacktrace\sinformation\s----------------------------------------\n 493 -e:1:in\s\`<main>\'\n 494 -e:1:in\s\`kill\'\n 495 )? 496 \n 497 (?: 498 --\sC\slevel\sbacktrace\sinformation\s-------------------------------------------\n 499 (?:(?:.*\s)?\[0x\h+\]\n)*\n 500 )? 501 (?m:.*) 502 \[NOTE\]\n 503 You\smay\shave\sencountered\sa\sbug\sin\sthe\sRuby\sinterpreter\sor\sextension\slibraries.\n 504 Bug\sreports\sare\swelcome.\n 505 For\sdetails:\shttp:\/\/www.ruby-lang.org/bugreport.html\n 506 \n 507 (?:#{additional}) 508 \z 509 )x 510 assert_in_out_err(["-e", "Process.kill :SEGV, $$"], "", [], expected_stderr, nil, opts) 511 512 bug7402 = '[ruby-core:49573]' 513 status = assert_in_out_err(['-e', 'class Bogus; def to_str; exit true; end; end', 514 '-e', '$".unshift Bogus.new', 515 '-e', 'Process.kill :SEGV, $$'], 516 "", //, /#<Bogus:/, 517 nil, 518 opts) 519 assert_not_predicate(status, :success?, "segv but success #{bug7402}") 520 521 bug7597 = '[ruby-dev:46786]' 522 t = Tempfile.new(["test_ruby_test_bug7597", ".rb"]) 523 t.write "f" * 100 524 t.flush 525 assert_in_out_err(["-e", "$0=ARGV[0]; Process.kill :SEGV, $$", t.path], 526 "", [], expected_stderr, bug7597, opts) 527 t.close(true) 528 end 529 530 def test_DATA 531 t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"]) 532 t.puts "puts DATA.read.inspect" 533 t.puts "__END__" 534 t.puts "foo" 535 t.puts "bar" 536 t.puts "baz" 537 t.close 538 assert_in_out_err([t.path], "", %w("foo\\nbar\\nbaz\\n"), []) 539 ensure 540 t.close(true) if t 541 end 542 543 def test_unused_variable 544 feature3446 = '[ruby-dev:41620]' 545 assert_in_out_err(["-we", "a=1"], "", [], [], feature3446) 546 assert_in_out_err(["-we", "def foo\n a=1\nend"], "", [], ["-e:2: warning: assigned but unused variable - a"], feature3446) 547 assert_in_out_err(["-we", "def foo\n eval('a=1')\nend"], "", [], [], feature3446) 548 assert_in_out_err(["-we", "1.times do\n a=1\nend"], "", [], [], feature3446) 549 assert_in_out_err(["-we", "def foo\n 1.times do\n a=1\n end\nend"], "", [], ["-e:3: warning: assigned but unused variable - a"], feature3446) 550 assert_in_out_err(["-we", "def foo\n"" 1.times do |a| end\n""end"], "", [], []) 551 feature6693 = '[ruby-core:46160]' 552 assert_in_out_err(["-we", "def foo\n _a=1\nend"], "", [], [], feature6693) 553 bug7408 = '[ruby-core:49659]' 554 assert_in_out_err(["-we", "def foo\n a=1\n :a\nend"], "", [], ["-e:2: warning: assigned but unused variable - a"], bug7408) 555 feature7730 = '[ruby-core:51580]' 556 assert_in_out_err(["-w", "-"], "a=1", [], ["-:1: warning: assigned but unused variable - a"], feature7730) 557 assert_in_out_err(["-w", "-"], "eval('a=1')", [], [], feature7730) 558 end 559 560 def test_shadowing_variable 561 bug4130 = '[ruby-dev:42718]' 562 assert_in_out_err(["-we", "def foo\n"" a=1\n"" 1.times do |a| end\n"" a\n""end"], 563 "", [], ["-e:3: warning: shadowing outer local variable - a"], bug4130) 564 assert_in_out_err(["-we", "def foo\n"" a=1\n"" 1.times do |a| end\n""end"], 565 "", [], 566 ["-e:3: warning: shadowing outer local variable - a", 567 "-e:2: warning: assigned but unused variable - a", 568 ], bug4130) 569 feature6693 = '[ruby-core:46160]' 570 assert_in_out_err(["-we", "def foo\n"" _a=1\n"" 1.times do |_a| end\n""end"], 571 "", [], [], feature6693) 572 end 573 574 def test_script_from_stdin 575 begin 576 require 'pty' 577 require 'io/console' 578 rescue LoadError 579 return 580 end 581 require 'timeout' 582 result = nil 583 IO.pipe {|r, w| 584 begin 585 PTY.open {|m, s| 586 s.echo = false 587 m.print("\C-d") 588 pid = spawn(EnvUtil.rubybin, :in => s, :out => w) 589 w.close 590 assert_nothing_raised('[ruby-dev:37798]') do 591 result = Timeout.timeout(3) {r.read} 592 end 593 Process.wait pid 594 } 595 rescue RuntimeError 596 skip $! 597 end 598 } 599 assert_equal("", result, '[ruby-dev:37798]') 600 IO.pipe {|r, w| 601 PTY.open {|m, s| 602 s.echo = false 603 pid = spawn(EnvUtil.rubybin, :in => s, :out => w) 604 w.close 605 m.print("$stdin.read; p $stdin.gets\n\C-d") 606 m.print("abc\n\C-d") 607 m.print("zzz\n") 608 result = r.read 609 Process.wait pid 610 } 611 } 612 assert_equal("\"zzz\\n\"\n", result, '[ruby-core:30910]') 613 end 614 615 def test_unmatching_glob 616 bug3851 = '[ruby-core:32478]' 617 a = "a[foo" 618 Dir.mktmpdir do |dir| 619 open(File.join(dir, a), "w") {|f| f.puts("p 42")} 620 assert_in_out_err(["-C", dir, a], "", ["42"], [], bug3851) 621 File.unlink(File.join(dir, a)) 622 assert_in_out_err(["-C", dir, a], "", [], /LoadError/, bug3851) 623 end 624 end 625 626 def test_script_is_directory 627 feature2408 = '[ruby-core:26925]' 628 assert_in_out_err(%w[.], "", [], /Is a directory -- \./, feature2408) 629 end 630 631 def test_pflag_gsub 632 bug7157 = '[ruby-core:47967]' 633 assert_in_out_err(['-p', '-e', 'gsub(/t.*/){"TEST"}'], %[test], %w[TEST], [], bug7157) 634 end 635 636 def test_pflag_sub 637 bug7157 = '[ruby-core:47967]' 638 assert_in_out_err(['-p', '-e', 'sub(/t.*/){"TEST"}'], %[test], %w[TEST], [], bug7157) 639 end 640end 641