Skip to content

Commit 690b564

Browse files
committed
Use File.write instead of Kernel#open
1 parent e500222 commit 690b564

File tree

5 files changed

+27
-35
lines changed

5 files changed

+27
-35
lines changed

bootstraptest/runner.rb

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -704,23 +704,19 @@ def assert_normal_exit(testsrc, *rest, timeout: BT.timeout, **opt)
704704
timeout_signaled = false
705705
logfile = "assert_normal_exit.#{as.path}.#{as.lineno}.log"
706706

707-
begin
708-
err = open(logfile, "w")
709-
io = IO.popen("#{BT.ruby} -W0 #{filename}", err: err)
710-
pid = io.pid
711-
th = Thread.new {
712-
io.read
713-
io.close
714-
$?
715-
}
716-
if !th.join(timeout)
717-
Process.kill :KILL, pid
718-
timeout_signaled = true
719-
end
720-
status = th.value
721-
ensure
722-
err.close
707+
io = IO.popen("#{BT.ruby} -W0 #{filename}", err: logfile)
708+
pid = io.pid
709+
th = Thread.new {
710+
io.read
711+
io.close
712+
$?
713+
}
714+
if !th.join(timeout)
715+
Process.kill :KILL, pid
716+
timeout_signaled = true
723717
end
718+
status = th.value
719+
724720
if status && status.signaled?
725721
signo = status.termsig
726722
signame = Signal.list.invert[signo]

bootstraptest/test_autoload.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}, '[ruby-dev:43816]'
1212

1313
assert_equal 'ok', %q{
14-
open('zzz2.rb', 'w') {|f| f.puts '' }
14+
File.write('zzz2.rb', '')
1515
instance_eval do
1616
autoload :ZZZ, './zzz2.rb'
1717
begin
@@ -23,28 +23,28 @@
2323
}, '[ruby-dev:43816]'
2424

2525
assert_equal 'ok', %q{
26-
open('zzz3.rb', 'w') {|f| f.puts 'class ZZZ; def self.ok;:ok;end;end'}
26+
File.write('zzz3.rb', "class ZZZ; def self.ok;:ok;end;end\n")
2727
instance_eval do
2828
autoload :ZZZ, './zzz3.rb'
2929
ZZZ.ok
3030
end
3131
}, '[ruby-dev:43816]'
3232

3333
assert_equal 'ok', %q{
34-
open("zzz4.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
34+
File.write("zzz4.rb", "class ZZZ; def self.ok;:ok;end;end\n")
3535
autoload :ZZZ, "./zzz4.rb"
3636
ZZZ.ok
3737
}
3838

3939
assert_equal 'ok', %q{
40-
open("zzz5.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
40+
File.write("zzz5.rb", "class ZZZ; def self.ok;:ok;end;end\n")
4141
autoload :ZZZ, "./zzz5.rb"
4242
require "./zzz5.rb"
4343
ZZZ.ok
4444
}
4545

4646
assert_equal 'okok', %q{
47-
open("zzz6.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
47+
File.write("zzz6.rb", "class ZZZ; def self.ok;:ok;end;end\n")
4848
autoload :ZZZ, "./zzz6.rb"
4949
t1 = Thread.new {ZZZ.ok}
5050
t2 = Thread.new {ZZZ.ok}
@@ -60,7 +60,7 @@
6060
}, '[ruby-core:21696]'
6161

6262
assert_equal 'A::C', %q{
63-
open("zzz7.rb", "w") {}
63+
File.write("zzz7.rb", "")
6464
class A
6565
autoload :C, "./zzz7"
6666
class C

bootstraptest/test_io.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
at_exit { p :foo }
9292
9393
megacontent = "abc" * 12345678
94-
#File.open("megasrc", "w") {|f| f << megacontent }
94+
#File.write("megasrc", megacontent)
9595
9696
t0 = Thread.main
9797
Thread.new { sleep 0.001 until t0.stop?; Process.kill(:INT, $$) }

bootstraptest/test_load.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
assert_equal 'ok', %q{
2-
open("require-lock-test.rb", "w") {|f|
3-
f.puts "sleep 0.1"
4-
f.puts "module M"
5-
f.puts "end"
6-
}
2+
File.write("require-lock-test.rb", <<-END)
3+
sleep 0.1
4+
module M
5+
end
6+
END
77
$:.unshift Dir.pwd
88
vs = (1..2).map {|i|
99
Thread.start {
@@ -16,7 +16,7 @@
1616

1717
assert_equal 'ok', %q{
1818
%w[a a/foo b].each {|d| Dir.mkdir(d)}
19-
open("b/foo", "w") {|f| f.puts "$ok = :ok"}
19+
File.write("b/foo", "$ok = :ok\n")
2020
$:.replace(%w[a b])
2121
begin
2222
load "foo"

bootstraptest/test_thread.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@
257257
}
258258

259259
assert_equal 'ok', %{
260-
open("zzz_t1.rb", "w") do |f|
261-
f.puts <<-END
260+
File.write("zzz_t1.rb", <<-END)
262261
begin
263262
Thread.new { fork { GC.start } }.join
264263
pid, status = Process.wait2
@@ -267,7 +266,6 @@
267266
$result = :ok
268267
end
269268
END
270-
end
271269
require "./zzz_t1.rb"
272270
$result
273271
}
@@ -422,8 +420,7 @@ def m
422420
}
423421

424422
assert_equal 'ok', %{
425-
open("zzz_t2.rb", "w") do |f|
426-
f.puts <<-'end;' # do
423+
File.write("zzz_t2.rb", <<-'end;') # do
427424
begin
428425
m = Thread::Mutex.new
429426
parent = Thread.current
@@ -445,7 +442,6 @@ def m
445442
$result = :ok
446443
end
447444
end;
448-
end
449445
require "./zzz_t2.rb"
450446
$result
451447
}

0 commit comments

Comments
 (0)