about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-10-20 00:03:43 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-20 00:09:04 +0000
commit808e6c6269c6f83675273d7bd5a2998a09637e3f (patch)
treeac97321c21eaea209a16a5292546265cb2f7bc83
parent04b664092b02e021a6b43f1869fe0ed2efc12dd8 (diff)
downloadyahns-808e6c6269c6f83675273d7bd5a2998a09637e3f.tar.gz
Since we fork in tests, at_exit handlers may run in children
and cause strange test failures.  This seems necessary in
minitest 5.0.8, but not 4.3.2.  We also cannot use exit! in
forked children because apps hosted on yahns will probably expect
at_exit handlers they register to run.
-rw-r--r--test/helper.rb40
1 files changed, 18 insertions, 22 deletions
diff --git a/test/helper.rb b/test/helper.rb
index 626a046..5fa9599 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -51,33 +51,29 @@ if ENV["COVERAGE"]
 end
 
 gem 'minitest'
-require 'minitest/autorun'
-require "tempfile"
-
-Testcase = begin
-  Minitest::Test # minitest 5
-rescue NameError
-  Minitest::Unit::TestCase # minitest 4
+begin # favor minitest 5
+  require 'minitest'
+  Testcase = Minitest::Test
+  mtobj = Minitest
+rescue NameError, LoadError # but support minitest 4
+  require 'minitest/unit'
+  Testcase = Minitest::Unit::TestCase
+  mtobj = MiniTest::Unit.new
 end
 
-FIFOS = []
-def tmpfifo
-  tmp = Tempfile.new(%w(yahns-test .fifo))
-  path = tmp.path
-  tmp.close!
-  assert system(*%W(mkfifo #{path})), "mkfifo #{path}"
-
-  GTL.synchronize do
-    if FIFOS.empty?
-      at_exit do
-        FIFOS.each { |(pid,_path)| File.unlink(_path) if $$ == pid }
-      end
-    end
-    FIFOS << [ $$, path ]
+# Not using minitest/autorun because that doesn't guard against redundant
+# extra runs with fork.  We cannot use exit! in the tests either
+# (since users/apps hosted on yahns _should_ expect exit, not exit!).
+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
   end
-  path
 end
 
+require "tempfile"
 require 'tmpdir'
 class Dir
   require 'fileutils'