test/helper.rb in yahns-0.0.1 vs test/helper.rb in yahns-0.0.2
- old
+ new
@@ -1,25 +1,31 @@
# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
$stdout.sync = $stderr.sync = Thread.abort_on_exception = true
$-w = true if RUBY_VERSION.to_f >= 2.0
require 'thread'
+require 'fileutils'
+def rubyv
+ puts RUBY_DESCRIPTION
+end
+
# Global Test Lock, to protect:
# Process.wait*, Dir.chdir, ENV, trap, require, etc...
GTL = Mutex.new
# fork-aware coverage data gatherer, see also test/covshow.rb
if ENV["COVERAGE"]
require "coverage"
- COVMATCH = %r{/lib/yahns\b.*rb\z}
+ COVMATCH = %r{(/lib/yahns\b|extras/).*rb\z}
+ COVDUMPFILE = File.expand_path("coverage.dump")
def __covmerge
res = Coverage.result
- # do not create the file, Makefile does htis before any tests run
- File.open("coverage.dump", IO::RDWR) do |covtmp|
+ # do not create the file, Makefile does this before any tests run
+ File.open(COVDUMPFILE, IO::RDWR) do |covtmp|
covtmp.binmode
covtmp.sync = true
# we own this file (at least until somebody tries to use NFS :x)
covtmp.flock(File::LOCK_EX)
@@ -67,24 +73,24 @@
TSTART_PID = $$
at_exit do
# skipping @@after_run stuff in minitest since we don't need it
case $!
when nil, SystemExit
- mtobj.run(ARGV) if $$ == TSTART_PID
+ exit(mtobj.run(ARGV)) if $$ == TSTART_PID
end
end
require "tempfile"
require 'tmpdir'
class Dir
- require 'fileutils'
def Dir.mktmpdir
begin
d = "#{Dir.tmpdir}/#$$.#{rand}"
Dir.mkdir(d)
rescue Errno::EEXIST
end while true
+ return d unless block_given?
begin
yield d
ensure
FileUtils.remove_entry(d)
end
@@ -106,9 +112,13 @@
buf = "\0" * 8
ioctl(0x541B, buf)
buf.unpack("l_")[0]
end
end if ! IO.method_defined?(:nread) && RUBY_PLATFORM =~ /linux/
+
+def cloexec_pipe
+ IO.pipe.each { |io| io.close_on_exec = true }
+end
require 'yahns'
# needed for parallel (MT) tests)
require 'yahns/rack'