Skip to content

Commit

Permalink
Use the same file and directory structures for ruby core testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jul 23, 2019
1 parent 817243a commit f067f7d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
33 changes: 30 additions & 3 deletions test/lib/core_assertions.rb
@@ -1,10 +1,36 @@
# frozen_string_literal: true

require_relative 'envutil'

module Test
module Unit
module CoreAssertions
if defined?(MiniTest)
require_relative '../../envutil'
# for ruby core testing
include MiniTest::Assertions
else
require 'pp'
require_relative 'envutil'
include Test::Unit::Assertions

def _assertions= n # :nodoc:
@_assertions = n
end

def _assertions # :nodoc:
@_assertions ||= 0
end

##
# Returns a proc that will output +msg+ along with the default message.

def message msg = nil, ending = nil, &default
proc {
msg = msg.call.chomp(".") if Proc === msg
custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
"#{custom_message}#{default.call}#{ending || "."}"
}
end
end

def mu_pp(obj) #:nodoc:
obj.pretty_inspect.chomp
Expand Down Expand Up @@ -98,7 +124,7 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
end
src = <<eom
# -*- coding: #{line += __LINE__; src.encoding}; -*-
require #{__dir__.dump};include Test::Unit::Assertions
require "test/unit";include Test::Unit::Assertions;require #{(__dir__ + "/core_assertions").dump};include Test::Unit::CoreAssertions
END {
puts [Marshal.dump($!)].pack('m'), "assertions=\#{self._assertions}"
}
Expand All @@ -107,6 +133,7 @@ class Test::Unit::Runner
@@stop_auto_run = true
end
eom

args = args.dup
args.insert((Hash === args.first ? 1 : 0), "-w", "--disable=gems", *$:.map {|l| "-I#{l}"})
stdout, stderr, status = EnvUtil.invoke_ruby(args, src, true, true, **opt)
Expand Down
4 changes: 3 additions & 1 deletion test/helper.rb → test/logger/helper.rb
Expand Up @@ -3,4 +3,6 @@
$LOAD_PATH.unshift File.join(ROOT_DIR, 'test', 'lib') # to use custom test-unit in this repo
require 'logger'
require 'test/unit'
require 'assertions'
require 'core_assertions'

Test::Unit::TestCase.include Test::Unit::CoreAssertions
2 changes: 1 addition & 1 deletion test/logger/test_logdevice.rb
@@ -1,6 +1,6 @@
# coding: US-ASCII
# frozen_string_literal: false
require_relative '../helper'
require_relative 'helper'
require 'tempfile'
require 'tmpdir'

Expand Down
2 changes: 1 addition & 1 deletion test/logger/test_logger.rb
@@ -1,6 +1,6 @@
# coding: US-ASCII
# frozen_string_literal: false
require_relative '../helper'
require_relative 'helper'
require 'tempfile'

class TestLogger < Test::Unit::TestCase
Expand Down
2 changes: 1 addition & 1 deletion test/logger/test_severity.rb
@@ -1,6 +1,6 @@
# coding: US-ASCII
# frozen_string_literal: false
require_relative '../helper'
require_relative 'helper'

class TestLoggerSeverity < Test::Unit::TestCase
def test_enum
Expand Down

0 comments on commit f067f7d

Please sign in to comment.