Use `File.write` instead of `Kernel#open`

This commit is contained in:
Nobuyoshi Nakada 2024-07-09 13:01:44 +09:00
Родитель e500222de1
Коммит 690b56440b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 3582D74E1FEE4465
5 изменённых файлов: 27 добавлений и 35 удалений

Просмотреть файл

@ -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]

Просмотреть файл

@ -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

Просмотреть файл

@ -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, $$) }

Просмотреть файл

@ -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"

Просмотреть файл

@ -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
}