diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-07-09 13:01:44 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2024-07-09 13:01:44 +0900 |
commit | 690b56440beaa32873a8311451033bb4bd34e94c (patch) | |
tree | 9b607e87c325231e3eb28a7e4e7c7deddbd01b42 | |
parent | e500222de1a8d5e7a844209a7e912b03db8cdf76 (diff) |
Use `File.write` instead of `Kernel#open`
-rwxr-xr-x | bootstraptest/runner.rb | 28 | ||||
-rw-r--r-- | bootstraptest/test_autoload.rb | 12 | ||||
-rw-r--r-- | bootstraptest/test_io.rb | 2 | ||||
-rw-r--r-- | bootstraptest/test_load.rb | 12 | ||||
-rw-r--r-- | bootstraptest/test_thread.rb | 8 |
5 files changed, 27 insertions, 35 deletions
diff --git a/bootstraptest/runner.rb b/bootstraptest/runner.rb index c0638ffc9a..2e2a3611de 100755 --- a/bootstraptest/runner.rb +++ b/bootstraptest/runner.rb @@ -704,23 +704,19 @@ def assert_normal_exit(testsrc, *rest, timeout: BT.timeout, **opt) timeout_signaled = false logfile = "assert_normal_exit.#{as.path}.#{as.lineno}.log" - begin - err = open(logfile, "w") - io = IO.popen("#{BT.ruby} -W0 #{filename}", err: err) - pid = io.pid - th = Thread.new { - io.read - io.close - $? - } - if !th.join(timeout) - Process.kill :KILL, pid - timeout_signaled = true - end - status = th.value - ensure - err.close + io = IO.popen("#{BT.ruby} -W0 #{filename}", err: logfile) + pid = io.pid + th = Thread.new { + io.read + io.close + $? + } + if !th.join(timeout) + Process.kill :KILL, pid + timeout_signaled = true end + status = th.value + if status && status.signaled? signo = status.termsig signame = Signal.list.invert[signo] diff --git a/bootstraptest/test_autoload.rb b/bootstraptest/test_autoload.rb index 9e0850bc52..de66f1f3ee 100644 --- a/bootstraptest/test_autoload.rb +++ b/bootstraptest/test_autoload.rb @@ -11,7 +11,7 @@ assert_equal 'ok', %q{ }, '[ruby-dev:43816]' assert_equal 'ok', %q{ - open('zzz2.rb', 'w') {|f| f.puts '' } + File.write('zzz2.rb', '') instance_eval do autoload :ZZZ, './zzz2.rb' begin @@ -23,7 +23,7 @@ assert_equal 'ok', %q{ }, '[ruby-dev:43816]' assert_equal 'ok', %q{ - open('zzz3.rb', 'w') {|f| f.puts 'class ZZZ; def self.ok;:ok;end;end'} + File.write('zzz3.rb', "class ZZZ; def self.ok;:ok;end;end\n") instance_eval do autoload :ZZZ, './zzz3.rb' ZZZ.ok @@ -31,20 +31,20 @@ assert_equal 'ok', %q{ }, '[ruby-dev:43816]' assert_equal 'ok', %q{ - open("zzz4.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"} + File.write("zzz4.rb", "class ZZZ; def self.ok;:ok;end;end\n") autoload :ZZZ, "./zzz4.rb" ZZZ.ok } assert_equal 'ok', %q{ - open("zzz5.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"} + File.write("zzz5.rb", "class ZZZ; def self.ok;:ok;end;end\n") autoload :ZZZ, "./zzz5.rb" require "./zzz5.rb" ZZZ.ok } assert_equal 'okok', %q{ - open("zzz6.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"} + File.write("zzz6.rb", "class ZZZ; def self.ok;:ok;end;end\n") autoload :ZZZ, "./zzz6.rb" t1 = Thread.new {ZZZ.ok} t2 = Thread.new {ZZZ.ok} @@ -60,7 +60,7 @@ assert_finish 5, %q{ }, '[ruby-core:21696]' assert_equal 'A::C', %q{ - open("zzz7.rb", "w") {} + File.write("zzz7.rb", "") class A autoload :C, "./zzz7" class C diff --git a/bootstraptest/test_io.rb b/bootstraptest/test_io.rb index 666e5a011b..4e5d6d59c9 100644 --- a/bootstraptest/test_io.rb +++ b/bootstraptest/test_io.rb @@ -91,7 +91,7 @@ assert_normal_exit %q{ at_exit { p :foo } megacontent = "abc" * 12345678 - #File.open("megasrc", "w") {|f| f << megacontent } + #File.write("megasrc", megacontent) t0 = Thread.main Thread.new { sleep 0.001 until t0.stop?; Process.kill(:INT, $$) } diff --git a/bootstraptest/test_load.rb b/bootstraptest/test_load.rb index 3253582a32..5046d4fcea 100644 --- a/bootstraptest/test_load.rb +++ b/bootstraptest/test_load.rb @@ -1,9 +1,9 @@ assert_equal 'ok', %q{ - open("require-lock-test.rb", "w") {|f| - f.puts "sleep 0.1" - f.puts "module M" - f.puts "end" - } + File.write("require-lock-test.rb", <<-END) + sleep 0.1 + module M + end + END $:.unshift Dir.pwd vs = (1..2).map {|i| Thread.start { @@ -16,7 +16,7 @@ assert_equal 'ok', %q{ assert_equal 'ok', %q{ %w[a a/foo b].each {|d| Dir.mkdir(d)} - open("b/foo", "w") {|f| f.puts "$ok = :ok"} + File.write("b/foo", "$ok = :ok\n") $:.replace(%w[a b]) begin load "foo" diff --git a/bootstraptest/test_thread.rb b/bootstraptest/test_thread.rb index a4d46e2f10..4040b68a27 100644 --- a/bootstraptest/test_thread.rb +++ b/bootstraptest/test_thread.rb @@ -257,8 +257,7 @@ assert_equal 'true', %{ } assert_equal 'ok', %{ - open("zzz_t1.rb", "w") do |f| - f.puts <<-END + File.write("zzz_t1.rb", <<-END) begin Thread.new { fork { GC.start } }.join pid, status = Process.wait2 @@ -267,7 +266,6 @@ assert_equal 'ok', %{ $result = :ok end END - end require "./zzz_t1.rb" $result } @@ -422,8 +420,7 @@ assert_equal 'ok', %q{ } assert_equal 'ok', %{ - open("zzz_t2.rb", "w") do |f| - f.puts <<-'end;' # do + File.write("zzz_t2.rb", <<-'end;') # do begin m = Thread::Mutex.new parent = Thread.current @@ -445,7 +442,6 @@ assert_equal 'ok', %{ $result = :ok end end; - end require "./zzz_t2.rb" $result } |