Skip to content
Browse files

Move to using #exit only and force M::Runner.run to exit instead of b…

…urying that throughout the lib so M can be used from another library
  • Loading branch information...
1 parent 5328939 commit 3ef98738f3d005436afa81de0f232ca40f9100a0 @qrush committed
Showing with 22 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +16 −12 lib/m.rb
  3. +5 −0 test/everything_test.rb
View
1 .gitignore
@@ -15,3 +15,4 @@ test/tmp
test/version_tmp
tmp
/docs
+_site
View
28 lib/m.rb
@@ -15,14 +15,14 @@
#If you're using Bundler, you'll need to include it in your Gemfile. Toss it into the `test` group:
#
# group :test do
-# gem 'm', '~> 1.2.1'
+# gem 'm', '~> 1.3.0'
# end
#
#Developing a RubyGem? Add `m` as a development dependency.
#
# Gem::Specification.new do |gem|
# # ...
-# gem.add_development_dependency "m", "~> 1.2.1"
+# gem.add_development_dependency "m", "~> 1.3.0"
# end
#
#`m` is Ruby 1.9+ only. Sorry, but `method_source`, `sourcify`, and `ruby_parser`
@@ -98,11 +98,11 @@
### M, your metal test runner
# Maybe this gem should have a longer name? Metal?
module M
- VERSION = "1.2.1" unless defined?(VERSION)
+ VERSION = "1.3.0" unless defined?(VERSION)
- # Accept arguments coming from bin/m and run tests.
+ # Accept arguments coming from bin/m and run tests, then bail out immediately.
def self.run(argv)
- Runner.new(argv).run
+ exit Runner.new(argv).run
end
### Runner is in charge of running your tests.
@@ -188,13 +188,13 @@ def execute
# directly run the tests from here and exit with the status of the tests passing or failing
if defined?(MiniTest)
- exit MiniTest::Unit.runner.run test_arguments
+ MiniTest::Unit.runner.run test_arguments
elsif defined?(Test)
- exit Test::Unit::AutoRunner.run(false, nil, test_arguments)
+ Test::Unit::AutoRunner.run(false, nil, test_arguments)
else
not_supported
end
- else
+ elsif tests.size > 0
# Otherwise we found no tests on this line, so you need to pick one.
message = "No tests found on line #{@line}. Valid tests to run:\n\n"
@@ -204,8 +204,9 @@ def execute
message << "#{sprintf("%0#{tests.column_size}s", test.name)}: m #{@file}:#{test.start_line}\n"
end
- # fail like a good unix process should.
- abort message
+ # Spit out helpful message and bail
+ STDERR.puts message
+ false
end
end
@@ -219,7 +220,8 @@ def suites
load @file
rescue LoadError => e
# Fail with a happier error message instead of spitting out a backtrace from this gem
- abort "Failed loading test file:\n#{e.message}"
+ STDERR.puts "Failed loading test file:\n#{e.message}"
+ return []
end
# Figure out what test framework we're using
@@ -228,6 +230,7 @@ def suites
elsif defined?(Test)
suites = Test::Unit::TestCase.test_suites
else
+ suites = []
not_supported
end
@@ -259,7 +262,8 @@ def tests
# Fail loudly if this isn't supported
def not_supported
- abort "This test framework is not supported! Please open up an issue at https://github.com/qrush/m !"
+ STDERR.puts "This test framework is not supported! Please open up an issue at https://github.com/qrush/m !"
+ false
end
end
end
View
5 test/everything_test.rb
@@ -20,4 +20,9 @@ def test_running_tests_within_a_subdirectory
output = m('examples')
assert_output /12 tests/, output
end
+
+ def test_blank_file_is_quieter
+ output = m('bananas')
+ assert_no_match /Valid tests to run/, output
+ end
end

0 comments on commit 3ef9873

Please sign in to comment.
Something went wrong with that request. Please try again.