Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GitHub Actions tests #1

Merged
merged 3 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: macos

on: [push, pull_request]

jobs:
build:
runs-on: macos-latest
strategy:
matrix:
ruby: [ 'head' ]
steps:
- uses: actions/checkout@master
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Set up Bundler
run: gem install rake-compiler --no-document
- name: Run test
run: rake
20 changes: 20 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: ubuntu

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [ 'head' ]
steps:
- uses: actions/checkout@master
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Set up Bundler
run: gem install rake-compiler --no-document
- name: Run test
run: rake
20 changes: 20 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: windows

on: [push, pull_request]

jobs:
build:
runs-on: windows-latest
strategy:
matrix:
ruby: [ 'head' ]
steps:
- uses: actions/checkout@master
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Set up Bundler
run: gem install rake-compiler --no-document
- name: Run test
run: rake
88 changes: 88 additions & 0 deletions test/lib/core_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,78 @@ def assert_raise_with_message(exception, expected, msg = nil, &block)
ex
end

MINI_DIR = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), "minitest") #:nodoc:

# :call-seq:
# assert(test, [failure_message])
#
#Tests if +test+ is true.
#
#+msg+ may be a String or a Proc. If +msg+ is a String, it will be used
#as the failure message. Otherwise, the result of calling +msg+ will be
#used as the message if the assertion fails.
#
#If no +msg+ is given, a default message will be used.
#
# assert(false, "This was expected to be true")
def assert(test, *msgs)
case msg = msgs.first
when String, Proc
when nil
msgs.shift
else
bt = caller.reject { |s| s.start_with?(MINI_DIR) }
raise ArgumentError, "assertion message must be String or Proc, but #{msg.class} was given.", bt
end unless msgs.empty?
super
end

# :call-seq:
# assert_respond_to( object, method, failure_message = nil )
#
#Tests if the given Object responds to +method+.
#
#An optional failure message may be provided as the final argument.
#
# assert_respond_to("hello", :reverse) #Succeeds
# assert_respond_to("hello", :does_not_exist) #Fails
def assert_respond_to(obj, (meth, *priv), msg = nil)
unless priv.empty?
msg = message(msg) {
"Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}#{" privately" if priv[0]}"
}
return assert obj.respond_to?(meth, *priv), msg
end
#get rid of overcounting
if caller_locations(1, 1)[0].path.start_with?(MINI_DIR)
return if obj.respond_to?(meth)
end
super(obj, meth, msg)
end

# :call-seq:
# assert_not_respond_to( object, method, failure_message = nil )
#
#Tests if the given Object does not respond to +method+.
#
#An optional failure message may be provided as the final argument.
#
# assert_not_respond_to("hello", :reverse) #Fails
# assert_not_respond_to("hello", :does_not_exist) #Succeeds
def assert_not_respond_to(obj, (meth, *priv), msg = nil)
unless priv.empty?
msg = message(msg) {
"Expected #{mu_pp(obj)} (#{obj.class}) to not respond to ##{meth}#{" privately" if priv[0]}"
}
return assert !obj.respond_to?(meth, *priv), msg
end
#get rid of overcounting
if caller_locations(1, 1)[0].path.start_with?(MINI_DIR)
return unless obj.respond_to?(meth)
end
refute_respond_to(obj, meth, msg)
end

# pattern_list is an array which contains regexp and :*.
# :* means any sequence.
#
Expand Down Expand Up @@ -635,6 +707,22 @@ def message(msg = nil, *args, &default) # :nodoc:
super
end
end

def diff(exp, act)
require 'pp'
q = PP.new(+"")
q.guard_inspect_key do
q.group(2, "expected: ") do
q.pp exp
end
q.text q.newline
q.group(2, "actual: ") do
q.pp act
end
q.flush
end
q.output
end
end
end
end
5 changes: 4 additions & 1 deletion test/lib/envutil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ def rubybin
class << self
attr_accessor :timeout_scale
attr_reader :original_internal_encoding, :original_external_encoding,
:original_verbose
:original_verbose, :original_warning

def capture_global_values
@original_internal_encoding = Encoding.default_internal
@original_external_encoding = Encoding.default_external
@original_verbose = $VERBOSE
@original_warning = %i[deprecated experimental].to_h {|i| [i, Warning[i]]}
end
end

Expand Down Expand Up @@ -149,6 +150,7 @@ def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr =
if RUBYLIB and lib = child_env["RUBYLIB"]
child_env["RUBYLIB"] = [lib, RUBYLIB].join(File::PATH_SEPARATOR)
end
child_env['ASAN_OPTIONS'] = ENV['ASAN_OPTIONS'] if ENV['ASAN_OPTIONS']
args = [args] if args.kind_of?(String)
pid = spawn(child_env, *precommand, rubybin, *args, **opt)
in_c.close
Expand Down Expand Up @@ -209,6 +211,7 @@ def flush; end
ensure
stderr, $stderr = $stderr, stderr
$VERBOSE = EnvUtil.original_verbose
EnvUtil.original_warning.each {|i, v| Warning[i] = v}
end
module_function :verbose_warning

Expand Down
4 changes: 4 additions & 0 deletions test/lib/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require "test/unit"
require_relative "core_assertions"

class Test::Unit::TestCase
alias skip pend
end

Test::Unit::TestCase.include Test::Unit::CoreAssertions