Skip to content
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
11 changes: 2 additions & 9 deletions .github/workflows/ruby-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
matrix:
os:
- ubuntu-latest
gemfile:
- minitest5
- test_unit_gem
ruby:
- ruby-2.7
- ruby-3.0
Expand All @@ -29,13 +26,9 @@ jobs:
- jruby
- truffleruby
include:
- { os: ubuntu-latest, gemfile: minitest4, ruby: ruby-2.7 }
- { os: ubuntu-latest, gemfile: minitest4, ruby: ruby-4.0 }
- { os: macos-latest, gemfile: minitest5, ruby: ruby-2.7 }
- { os: macos-latest, gemfile: minitest5, ruby: ruby-4.0 }
- { os: macos-latest, ruby: ruby-2.7 }
- { os: macos-latest, ruby: ruby-4.0 }
runs-on: ${{ matrix.os }}
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
steps:
- name: Checkout
uses: actions/checkout@v6
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source "https://rubygems.org"

gem "benchmark-ips"
gem "coveralls", require: false
gem "minitest", ">= 5"
gem "test-unit"

gem "allocation_stats" unless defined?(JRUBY_VERSION)

Expand Down
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,7 @@ CONTRIBUTING

You can run all the tests with:

bundle exec rake tests

You can also run tests selectively. For minitest 4 run:

bundle exec rake test:minitest4

and the ones for minitest 5 with:

bundle exec rake test:minitest5

bundle exec rake test

LICENSE
=======
Expand Down
30 changes: 2 additions & 28 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,17 @@ require "bundler/gem_tasks"
require "rake/clean"
require "rake/testtask"
require "standard/rake"
require "rbconfig"

task default: [:test, "standard:fix"]

Rake::TestTask.new do |t|
t.libs << "test"
t.libs << "lib"
t.pattern = "test/*_test.rb"
end

desc "Run all tests and get merged test coverage"
namespace :test do
Dir.glob("gemfiles/*.gemfile").each do |gemfile_path|
name = /gemfiles\/(.*).gemfile/.match(gemfile_path)[1]
desc "Run #{name} tests"
task name do |rake_task|
gemfile_name = rake_task.name.split(":").last
gemfile_path = "gemfiles/#{gemfile_name}.gemfile"
Bundler.with_original_env do
sh "BUNDLE_GEMFILE=#{gemfile_path} bundle exec rake"
end
end
end
end

desc "Run all tests and get merged test coverage"
task :tests do
Dir.glob("gemfiles/*.gemfile").each do |gemfile_path|
Bundler.with_original_env do
sh "BUNDLE_GEMFILE=#{gemfile_path} bundle exec rake"
end
end
Coveralls.push!
end

desc "Run simple benchmarks"
task :bench do
current_commit = `git rev-parse HEAD`
file_name = "benchmarks/#{Time.now.strftime "%Y%m%d"}-benchmark.log"
exec "echo -e 'Data for commit: #{current_commit}' > #{file_name} && ruby test/bench.rb >> #{file_name}"
exec "echo -e 'Data for commit: #{current_commit}' > #{file_name} && #{RbConfig.ruby} test/bench.rb >> #{file_name}"
end
10 changes: 0 additions & 10 deletions gemfiles/minitest4.gemfile

This file was deleted.

10 changes: 0 additions & 10 deletions gemfiles/minitest5.gemfile

This file was deleted.

10 changes: 0 additions & 10 deletions gemfiles/test_unit_gem.gemfile

This file was deleted.

1 change: 1 addition & 0 deletions lib/m/executor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative "runners/base"
require_relative "runners/minitest_6"
require_relative "runners/minitest_5"
require_relative "runners/minitest_4"
require_relative "runners/test_unit"
Expand Down
22 changes: 11 additions & 11 deletions lib/m/frameworks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def self.minitest_version_major
end
end

def self.minitest5?
minitest_version_major == "5"
def self.minitest6?
minitest_version_major == "6"
end

def self.minitest4?
minitest_version_major == "4"
def self.minitest5?
minitest_version_major == "5"
end

def self.test_unit?
Expand All @@ -25,10 +25,10 @@ def self.framework_runner
end

def framework_runner
if minitest5?
if minitest6?
Runners::Minitest6.new
elsif minitest5?
Runners::Minitest5.new
elsif minitest4?
Runners::Minitest4.new
elsif test_unit?
Runners::TestUnit.new
else
Expand All @@ -38,12 +38,12 @@ def framework_runner

private

def minitest5?
self.class.minitest5?
def minitest6?
self.class.minitest6?
end

def minitest4?
self.class.minitest4?
def minitest5?
self.class.minitest5?
end

def test_unit?
Expand Down
5 changes: 3 additions & 2 deletions lib/m/parser.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative "testable"
require "rbconfig"

module M
class Parser
Expand All @@ -11,12 +12,12 @@ def parse
# With no arguments,
if argv.empty?
# Just shell out to `rake test`.
exec "rake test"
exec "#{RbConfig.ruby} -S rake test"
else
parse_options! argv

if argv.first.start_with? "--"
exec "rake test #{argv.join}"
exec "#{RbConfig.ruby} -S rake test #{argv.join}"
exit 0
else
# Parse out ARGV, it should be coming in in a format like `test/test_file.rb:9:19`
Expand Down
3 changes: 3 additions & 0 deletions lib/m/runners/minitest_6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative "minitest_5"

M::Runners::Minitest6 = M::Runners::Minitest5
12 changes: 7 additions & 5 deletions lib/m/test_method.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "finish_line" if RUBY_VERSION < "4"
require_relative "finish_line" # if RUBY_VERSION < "4.1"

module M
### Simple data structure for what a test method contains.
Expand All @@ -13,12 +13,14 @@ def self.create suite_class, test_method
method = suite_class.instance_method test_method

# Ruby can find the starting line for us, so pull that out of the array.
# Ruby 4.0+ can also provide the ending line.
start_line, end_line = method.source_location.values_at(1, 3)
# Ruby 4.1+ can also provide the ending line.
#start_line, end_line = method.source_location.values_at(1, 3)
start_line = method.source_location[1]

# Ruby < 4.0 can't find the end line. Use a Ripper-derived parser to
# Ruby < 4.1 can't find the end line. Use a Ripper-derived parser to
# determine the ending line.
end_line ||= FinishLine.ending_line_for method
#end_line ||= FinishLine.ending_line_for method
end_line = FinishLine.ending_line_for method

# Shove the given attributes into a new databag
new test_method, start_line, end_line
Expand Down
2 changes: 1 addition & 1 deletion test/active_support_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require_relative "test_helper"

class ActiveSupportTest < MTest
def test_run_simple_test_by_line_number_with_absolute_path
Expand Down
5 changes: 2 additions & 3 deletions test/allocations.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$LOAD_PATH.unshift "lib"
require "m"
require_relative "../lib/m"
require "allocation_stats"

def benchmark_allocations burn: 1, &block
Expand All @@ -16,6 +15,6 @@ def benchmark_allocations burn: 1, &block

benchmark_allocations do
10.times do
M::Runner.new(["test/examples/minitest_5_example_test.rb:19"]).run
M::Runner.new(["test/examples/minitest_5_or_6_example_test.rb:19"]).run
end
end
25 changes: 9 additions & 16 deletions test/bench.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
require "benchmark/ips"
require "rbconfig"

Benchmark.ips do |bench|
bench.report("running m on a file that doesn't exist") do
`bundle exec ruby -Ilib ./bin/m failwhale 2>/dev/null`
`bundle exec #{RbConfig.ruby} -Ilib ./bin/m failwhale 2>/dev/null`
end

bench.report("running m on an empty file") do
`bundle exec ruby -Ilib ./bin/m test/examples/empty_example_test.rb 2>/dev/null`
`bundle exec #{RbConfig.ruby} -Ilib ./bin/m test/examples/empty_example_test.rb 2>/dev/null`
end

bench.report("running m on an entire file with minitest4") do
`BUNDLE_GEMFILE=gemfiles/minitest4.gemfile bundle exec ruby -Ilib ./bin/m test/examples/minitest_4_example_test.rb 2>/dev/null`
end

bench.report("running m on an entire file with minitest5") do
`BUNDLE_GEMFILE=gemfiles/minitest5.gemfile bundle exec ruby -Ilib ./bin/m test/examples/minitest_5_example_test.rb 2>/dev/null`
bench.report("running m on an entire file with minitest") do
`bundle exec #{RbConfig.ruby} -Ilib ./bin/m test/examples/minitest_5_or_6_example_test.rb 2>/dev/null`
end

bench.report("running m on an entire file with test-unit gem") do
`BUNDLE_GEMFILE=gemfiles/test_unit_gem.gemfile bundle exec ruby -Ilib ./bin/m test/examples/test_unit_example_test.rb 2>/dev/null`
end

bench.report("running m on a specific test with minitest4") do
`BUNDLE_GEMFILE=gemfiles/minitest4.gemfile bundle exec ruby -Ilib ./bin/m test/examples/minitest_4_example_test.rb:19 2>/dev/null`
`bundle exec #{RbConfig.ruby} -Ilib ./bin/m test/examples/test_unit_example_test.rb 2>/dev/null`
end

bench.report("running m on a specific test with minitest5") do
`BUNDLE_GEMFILE=gemfiles/minitest5.gemfile bundle exec ruby -Ilib ./bin/m test/examples/minitest_5_example_test.rb:19 2>/dev/null`
bench.report("running m on a specific test with minitest") do
`bundle exec #{RbConfig.ruby} -Ilib ./bin/m test/examples/minitest_5_or_6_example_test.rb:19 2>/dev/null`
end

bench.report("running m on a specific test with test-unit gem") do
`BUNDLE_GEMFILE=gemfiles/test_unit_gem.gemfile bundle exec ruby -Ilib ./bin/m test/examples/test_unit_example_test.rb:15 2>/dev/null`
`bundle exec #{RbConfig.ruby} -Ilib ./bin/m test/examples/test_unit_example_test.rb:15 2>/dev/null`
end
end
2 changes: 1 addition & 1 deletion test/empty_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require_relative "test_helper"

class EmptyTest < MTest
def test_run_simple_test_by_line_number
Expand Down
2 changes: 1 addition & 1 deletion test/everything_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require_relative "test_helper"

class EverythingTest < MTest
def test_runs_entire_test_suite_with_no_arguments
Expand Down
34 changes: 0 additions & 34 deletions test/examples/minitest_4_example_test.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "minitest/autorun"

if M::Frameworks.minitest5?
if M::Frameworks.minitest5? || M::Frameworks.minitest6?
class Meme
def i_can_has_cheezburger?
"OHAI!"
Expand Down
6 changes: 2 additions & 4 deletions test/examples/minitest_example_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "minitest/unit"
require "minitest"

class Meme
def i_can_has_cheezburger?
Expand All @@ -10,9 +10,7 @@ def will_it_blend?
end
end

Test = M::Frameworks.minitest4? ? MiniTest::Unit::TestCase : Minitest::Test

class TestMeme < Test
class TestMeme < Minitest::Test
def setup
@meme = Meme.new
end
Expand Down
2 changes: 1 addition & 1 deletion test/exit_codes_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require_relative "test_helper"

class ExitCodesTest < MTest
def test_failing_test_returns_1
Expand Down
Loading