m 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +8 -4
  4. data/Gemfile +1 -0
  5. data/README.md +11 -6
  6. data/Rakefile +10 -1
  7. data/benchmarks/20150430-benchmark.log +26 -0
  8. data/gemfiles/minitest4.gemfile +1 -1
  9. data/gemfiles/minitest4.gemfile.lock +30 -18
  10. data/gemfiles/minitest5.gemfile +1 -1
  11. data/gemfiles/minitest5.gemfile.lock +29 -17
  12. data/lib/m.rb +1 -271
  13. data/lib/m/executor.rb +101 -0
  14. data/lib/m/frameworks.rb +34 -0
  15. data/lib/m/parser.rb +74 -0
  16. data/lib/m/runner.rb +20 -0
  17. data/lib/m/runners/base.rb +17 -0
  18. data/lib/m/runners/minitest_4.rb +13 -0
  19. data/lib/m/runners/minitest_5.rb +17 -0
  20. data/lib/m/runners/test_unit.rb +13 -0
  21. data/lib/m/runners/unsupported_framework.rb +21 -0
  22. data/lib/m/testable.rb +15 -0
  23. data/lib/version.rb +1 -1
  24. data/m.gemspec +1 -1
  25. data/test/active_support_test.rb +17 -17
  26. data/test/bench.rb +25 -8
  27. data/test/empty_test.rb +1 -1
  28. data/test/everything_test.rb +11 -6
  29. data/test/examples/active_support_example_test.rb +0 -1
  30. data/test/examples/active_support_unescaped_example_test.rb +0 -1
  31. data/test/examples/empty_example_test.rb +2 -2
  32. data/test/examples/minitest_4_example_test.rb +4 -6
  33. data/test/examples/minitest_5_example_test.rb +4 -5
  34. data/test/examples/multiple_example_test.rb +0 -1
  35. data/test/examples/subdir/a_test.rb +2 -2
  36. data/test/examples/subdir/b_test.rb +2 -2
  37. data/test/examples/subdir/c_test.rb +2 -2
  38. data/test/examples/subdir_with_failures/a_test.rb +7 -0
  39. data/test/examples/test_unit_example_test.rb +12 -12
  40. data/test/minitest_4_test.rb +13 -13
  41. data/test/minitest_5_test.rb +6 -6
  42. data/test/multiple_test.rb +3 -3
  43. data/test/options_test.rb +6 -6
  44. data/test/test_helper.rb +13 -12
  45. data/test/test_unit_test.rb +29 -27
  46. metadata +13 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbd933c0fe3a41a288037d2a8b1a6c3bec5f60b7
4
- data.tar.gz: d9bfa2b3ba294b898407a2a053556dd8b18d3855
3
+ metadata.gz: bd1ad8313ab5bd9e236d70fe871ba3e29d871221
4
+ data.tar.gz: 0e6b5521243cf531c2c45509aaf9d27c438696d5
5
5
  SHA512:
6
- metadata.gz: db5ce32d613f9edaf57001b2dcec827fd8465d5c89fc55f551f7e211cf43bd7eea38a321b53d5b1d7556dace9ef62675f69cfb03c5fb68d90699b427256de742
7
- data.tar.gz: e1d13b7da917f7fcbf7df78ec20a11b10af5cd7131c4f5cb44c8b9b0c6aa0a3ba93e13ac2b236fcfd2f304dd2684e75594de8b08cc5efe9357cb2740e5d5841d
6
+ metadata.gz: 33c1b791fe1b6c24152547b4629a9b48a7be747b80d946d7180083835265cf5c98d46d5cdeacb6c1382722871c37dc04a37c55851ecd76841277b4a1a67513f3
7
+ data.tar.gz: 79c1d8f2ab1417c58807cd69275de576fd94ca746dc5d48dc043d2372bc8a5b55eaddd26d4e662a49583f884e3c1373f36f3417888702d17f09f9988bbbf5324
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/version_tmp
16
16
  tmp
17
17
  /docs
18
18
  _site
19
+ .ruby-version
@@ -1,6 +1,10 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.0.0
4
- branches:
5
- only:
6
- - master
3
+ - 2.1.0
4
+ - 2.2.0
5
+ install:
6
+ - bundle install
7
+ - bundle --gemfile=gemfiles/minitest5.gemfile
8
+ - bundle --gemfile=gemfiles/minitest4.gemfile
9
+ script:
10
+ - bundle exec rake tests
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'coveralls', require: false
4
+ gem 'benchmark-ips'
4
5
 
5
6
  gemspec
data/README.md CHANGED
@@ -50,7 +50,7 @@ Gem::Specification.new do |gem|
50
50
  end
51
51
  ```
52
52
 
53
- m works on Ruby 1.9+ only.
53
+ m works on Ruby 2.0+ only.
54
54
 
55
55
 
56
56
  USAGE
@@ -128,16 +128,21 @@ SUPPORT
128
128
  CONTRIBUTING
129
129
  ============
130
130
 
131
- You can run the tests for minitest 4 with:
131
+ You can run all the tests with:
132
132
 
133
- rake appraisal:minitest4 test
133
+ bundle exec rake tests
134
+
135
+ You can also run tests selectively. For minitest 4 run:
136
+
137
+ appraisal minitest4 rake test
134
138
 
135
139
  and the ones for minitest 5 with:
136
140
 
137
- rake appraisal:minitest5 test TEST=test/minitest_5_test.rb
141
+ appraisal minitest5 rake test TEST=test/minitest_5_test.rb
138
142
 
139
- In the case of minitest 5 the whole suite will fail due to incompatibilities
140
- with ruby (at least until 2.1.1).
143
+ In the case of minitest 5, we have to specify the test to run, because running
144
+ the whole suite will fail due to incompatibilities with ruby (at least until
145
+ 2.1.1).
141
146
 
142
147
 
143
148
  LICENSE
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'rubygems'
3
3
  require 'bundler/setup'
4
4
  require 'appraisal'
5
+ require 'coveralls'
5
6
  require "bundler/gem_tasks"
6
7
  require 'rake/clean'
7
8
  require "rake/testtask"
@@ -10,12 +11,20 @@ task :default => [:test]
10
11
 
11
12
  Rake::TestTask.new do |t|
12
13
  t.libs << 'test'
14
+ t.libs << 'lib'
13
15
  t.pattern = 'test/*_test.rb'
14
16
  end
15
17
 
18
+ desc 'Run all tests and get merged test coverage'
19
+ task :tests do
20
+ system "appraisal minitest4 rake test"
21
+ system "appraisal minitest5 rake test TEST=test/minitest_5_test.rb"
22
+ Coveralls.push!
23
+ end
24
+
16
25
  desc 'Run simple benchmarks'
17
26
  task :bench do
18
- exec "ruby test/bench.rb"
27
+ exec "ruby test/bench.rb > benchmarks/#{Time.now.strftime('%Y%m%d')}-benchmark.log"
19
28
  end
20
29
 
21
30
  # ROCCO ===============================================================
@@ -0,0 +1,26 @@
1
+ Calculating -------------------------------------
2
+ running m on a file that doesn't exist
3
+ 1.000 i/100ms
4
+ running m on an empty file
5
+ 1.000 i/100ms
6
+ running m on an entire file with minitest5
7
+ 1.000 i/100ms
8
+ running m on an entire file with minitest4
9
+ 1.000 i/100ms
10
+ running m on a specific test with minitest4
11
+ 1.000 i/100ms
12
+ running m on a specific test with minitest5
13
+ 1.000 i/100ms
14
+ -------------------------------------------------
15
+ running m on a file that doesn't exist
16
+ 3.097 (± 0.0%) i/s - 16.000
17
+ running m on an empty file
18
+ 1.821 (± 0.0%) i/s - 10.000 in 5.496098s
19
+ running m on an entire file with minitest5
20
+ 0.711 (± 0.0%) i/s - 4.000 in 5.630911s
21
+ running m on an entire file with minitest4
22
+ 0.746 (± 0.0%) i/s - 4.000 in 5.362587s
23
+ running m on a specific test with minitest4
24
+ 0.748 (± 0.0%) i/s - 4.000 in 5.345471s
25
+ running m on a specific test with minitest5
26
+ 0.746 (± 0.0%) i/s - 4.000 in 5.363017s
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "coveralls", :require=>false
6
6
  gem "minitest", "4.7.5"
7
7
 
8
- gemspec :path=>"../"
8
+ gemspec :path=>"../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- m (1.3.2)
4
+ m (1.3.3)
5
5
  method_source (>= 0.6.7)
6
6
  rake (>= 0.9.2.2)
7
7
 
@@ -18,38 +18,50 @@ GEM
18
18
  bundler
19
19
  rake
20
20
  atomic (1.1.14)
21
- colorize (0.6.0)
22
- coveralls (0.5.8)
23
- colorize
24
- json
25
- rest-client
26
- simplecov (>= 0.7)
27
- thor
28
- docile (1.1.1)
21
+ coveralls (0.8.1)
22
+ json (~> 1.8)
23
+ rest-client (>= 1.6.8, < 2)
24
+ simplecov (~> 0.10.0)
25
+ term-ansicolor (~> 1.3)
26
+ thor (~> 0.19.1)
27
+ docile (1.1.5)
28
+ domain_name (0.5.24)
29
+ unf (>= 0.0.5, < 1.0.0)
30
+ http-cookie (1.0.2)
31
+ domain_name (~> 0.5)
29
32
  i18n (0.6.9)
30
- json (1.8.1)
33
+ json (1.8.2)
31
34
  method_source (0.8.2)
32
- mime-types (2.0)
35
+ mime-types (2.5)
33
36
  minitest (4.7.5)
34
37
  multi_json (1.8.4)
35
38
  mustache (0.99.4)
39
+ netrc (0.10.3)
36
40
  rake (10.1.1)
37
41
  rdiscount (1.6.8)
38
42
  redcarpet (3.0.0)
39
- rest-client (1.6.7)
40
- mime-types (>= 1.16)
43
+ rest-client (1.8.0)
44
+ http-cookie (>= 1.0.2, < 2.0)
45
+ mime-types (>= 1.16, < 3.0)
46
+ netrc (~> 0.7)
41
47
  rocco (0.8.2)
42
48
  mustache
43
49
  redcarpet
44
- simplecov (0.8.2)
50
+ simplecov (0.10.0)
45
51
  docile (~> 1.1.0)
46
- multi_json
47
- simplecov-html (~> 0.8.0)
48
- simplecov-html (0.8.0)
49
- thor (0.18.1)
52
+ json (~> 1.8)
53
+ simplecov-html (~> 0.10.0)
54
+ simplecov-html (0.10.0)
55
+ term-ansicolor (1.3.0)
56
+ tins (~> 1.0)
57
+ thor (0.19.1)
50
58
  thread_safe (0.1.3)
51
59
  atomic
60
+ tins (1.5.1)
52
61
  tzinfo (0.3.38)
62
+ unf (0.1.4)
63
+ unf_ext
64
+ unf_ext (0.0.7.1)
53
65
 
54
66
  PLATFORMS
55
67
  ruby
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "coveralls", :require=>false
6
6
  gem "minitest"
7
7
 
8
- gemspec :path=>"../"
8
+ gemspec :path=>"../"
@@ -14,35 +14,47 @@ GEM
14
14
  appraisal (0.5.2)
15
15
  bundler
16
16
  rake
17
- colorize (0.6.0)
18
- coveralls (0.5.8)
19
- colorize
20
- json
21
- rest-client
22
- simplecov (>= 0.7)
23
- thor
24
- docile (1.1.1)
17
+ coveralls (0.8.1)
18
+ json (~> 1.8)
19
+ rest-client (>= 1.6.8, < 2)
20
+ simplecov (~> 0.10.0)
21
+ term-ansicolor (~> 1.3)
22
+ thor (~> 0.19.1)
23
+ docile (1.1.5)
24
+ domain_name (0.5.24)
25
+ unf (>= 0.0.5, < 1.0.0)
26
+ http-cookie (1.0.2)
27
+ domain_name (~> 0.5)
25
28
  i18n (0.6.9)
26
- json (1.8.1)
29
+ json (1.8.2)
27
30
  method_source (0.8.2)
28
- mime-types (2.0)
31
+ mime-types (2.5)
29
32
  minitest (5.3.1)
30
33
  multi_json (1.8.4)
31
34
  mustache (0.99.4)
35
+ netrc (0.10.3)
32
36
  rake (10.1.1)
33
37
  rdiscount (1.6.8)
34
38
  redcarpet (3.0.0)
35
- rest-client (1.6.7)
36
- mime-types (>= 1.16)
39
+ rest-client (1.8.0)
40
+ http-cookie (>= 1.0.2, < 2.0)
41
+ mime-types (>= 1.16, < 3.0)
42
+ netrc (~> 0.7)
37
43
  rocco (0.8.2)
38
44
  mustache
39
45
  redcarpet
40
- simplecov (0.8.2)
46
+ simplecov (0.10.0)
41
47
  docile (~> 1.1.0)
42
- multi_json
43
- simplecov-html (~> 0.8.0)
44
- simplecov-html (0.8.0)
45
- thor (0.18.1)
48
+ json (~> 1.8)
49
+ simplecov-html (~> 0.10.0)
50
+ simplecov-html (0.10.0)
51
+ term-ansicolor (1.3.0)
52
+ tins (~> 1.0)
53
+ thor (0.19.1)
54
+ tins (1.5.1)
55
+ unf (0.1.4)
56
+ unf_ext
57
+ unf_ext (0.0.7.1)
46
58
 
47
59
  PLATFORMS
48
60
  ruby
data/lib/m.rb CHANGED
@@ -1,102 +1,8 @@
1
- #`m` stands for metal, which is a better test/unit test runner that can run
2
- #tests by line number.
3
- #
4
- #[![m ci](https://secure.travis-ci.org/qrush/m.png)](http://travis-ci.org/qrush/m)
5
- #
6
- #![Rush is a heavy metal band. Look it up on Wikipedia.](https://raw.github.com/qrush/m/master/rush.jpg)
7
- #
8
- #<sub>[Rush at the Bristol Colston Hall May 1979](http://www.flickr.com/photos/8507625@N02/3468299995/)</sub>
9
- ### Install
10
- #
11
- #Install via:
12
- #
13
- # gem install m
14
- #
15
- #If you're using Bundler, you'll need to include it in your Gemfile. Toss it into the `test` group:
16
- #
17
- # group :test do
18
- # gem 'm', '~> 1.3.1'
19
- # end
20
- #
21
- #Developing a RubyGem? Add `m` as a development dependency.
22
- #
23
- # Gem::Specification.new do |gem|
24
- # # ...
25
- # gem.add_development_dependency "m", "~> 1.3.1"
26
- # end
27
- #
28
- #`m` works on Ruby 1.9+ only.
29
- #
30
- ### Usage
31
- #
32
- #Basically, I was sick of using the `-n` flag to grab one test to run. Instead, I
33
- #prefer how RSpec's test runner allows tests to be run by line number.
34
- #
35
- #Given this file:
36
- #
37
- # $ cat -n test/example_test.rb
38
- # 1 require 'test/unit'
39
- # 2
40
- # 3 class ExampleTest < Test::Unit::TestCase
41
- # 4 def test_apple
42
- # 5 assert_equal 1, 1
43
- # 6 end
44
- # 7
45
- # 8 def test_banana
46
- # 9 assert_equal 1, 1
47
- # 10 end
48
- # 11 end
49
- #
50
- #You can run a test by line number, using format `m TEST_FILE:LINE_NUMBER_OF_TEST`:
51
- #
52
- # $ m test/example_test.rb:4
53
- # Run options: -n /test_apple/
54
- #
55
- # # Running tests:
56
- #
57
- # .
58
- #
59
- # Finished tests in 0.000525s, 1904.7619 tests/s, 1904.7619 assertions/s.
60
- #
61
- # 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
62
- #
63
- #Hit the wrong line number? No problem, `m` helps you out:
64
- #
65
- # $ m test/example_test.rb:2
66
- # No tests found on line 2. Valid tests to run:
67
- #
68
- # test_apple: m test/examples/test_unit_example_test.rb:4
69
- # test_banana: m test/examples/test_unit_example_test.rb:8
70
- #
71
- #Want to run the whole test? Just leave off the line number.
72
- #
73
- # $ m test/example_test.rb
74
- # Run options:
75
- #
76
- # # Running tests:
77
- #
78
- # ..
79
- #
80
- # Finished tests in 0.001293s, 1546.7904 tests/s, 3093.5808 assertions/s.
81
- #
82
- # 1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
83
- #
84
- #### Supports
85
- #
86
- #`m` works with a few Ruby test frameworks:
87
- #
88
- #* `Test::Unit`
89
- #* `ActiveSupport::TestCase`
90
- #* `MiniTest::Unit::TestCase`
91
- #
92
- ### License
93
- #
94
- #This gem is MIT licensed, please see `LICENSE` for more information.
95
-
96
1
  ### M, your metal test runner
97
2
  # Maybe this gem should have a longer name? Metal?
98
3
  require_relative 'version'
99
4
  require_relative 'm/frameworks'
5
+ require_relative 'm/runner'
100
6
 
101
7
  module M
102
8
  # Accept arguments coming from bin/m and run tests, then bail out immediately.
@@ -106,180 +12,4 @@ module M
106
12
  $stderr.sync = true
107
13
  exit! Runner.new(argv).run
108
14
  end
109
-
110
- ### Runner is in charge of running your tests.
111
- # Instead of slamming all of this junk in an `M` class, it's here instead.
112
- class Runner
113
- def initialize(argv)
114
- @argv = argv
115
- end
116
-
117
- # There's two steps to running our tests:
118
- # 1. Parsing the given input for the tests we need to find (or groups of tests)
119
- # 2. Run those tests we found that match what you wanted
120
- def run
121
- parse
122
- execute
123
- end
124
-
125
- private
126
-
127
- def parse
128
- # With no arguments,
129
- if @argv.empty?
130
- # Just shell out to `rake test`.
131
- exec "rake test"
132
- else
133
- parse_options! @argv
134
-
135
- # Parse out ARGV, it should be coming in in a format like `test/test_file.rb:9`
136
- @file, line = @argv.first.split(':')
137
- @line ||= line.to_i
138
-
139
- # If this file is a directory, not a file, run the tests inside of this directory
140
- if Dir.exist?(@file)
141
- # Make a new rake test task with a hopefully unique name, and run every test looking file in it
142
- require "rake/testtask"
143
- Rake::TestTask.new(:m_custom) do |t|
144
- t.libs << 'test'
145
- t.libs << 'spec'
146
- t.test_files = FileList["#{@file}/*test*.rb", "#{@file}/*spec*.rb"]
147
- end
148
- # Invoke the rake task and exit, hopefully it'll work!
149
- Rake::Task['m_custom'].invoke
150
- exit
151
- end
152
- end
153
- end
154
-
155
- def parse_options!(argv)
156
- require 'optparse'
157
-
158
- OptionParser.new do |opts|
159
- opts.banner = 'Options:'
160
- opts.version = M::VERSION
161
-
162
- opts.on '-h', '--help', 'Display this help.' do
163
- puts "Usage: m [OPTIONS] [FILES]\n\n", opts
164
- exit
165
- end
166
-
167
- opts.on '--version', 'Display the version.' do
168
- puts "m #{M::VERSION}"
169
- exit
170
- end
171
-
172
- opts.on '-l', '--line LINE', Integer, 'Line number for file.' do |line|
173
- @line = line
174
- end
175
-
176
- opts.parse! argv
177
- end
178
- end
179
-
180
- def execute
181
- # Locate tests to run that may be inside of this line. There could be more than one!
182
- tests_to_run = tests.within(@line)
183
-
184
- # If we found any tests,
185
- if tests_to_run.size > 0
186
- # assemble the regexp to run these tests,
187
- test_names = tests_to_run.map { |test| Regexp.escape(test.name) }.join('|')
188
-
189
- # set up the args needed for the runner
190
- test_arguments = ["-n", "/^(#{test_names})$/"]
191
-
192
- # directly run the tests from here and exit with the status of the tests passing or failing
193
- if Frameworks.minitest5?
194
- Minitest.run test_arguments
195
- elsif Frameworks.minitest4?
196
- MiniTest::Unit.runner.run test_arguments
197
- elsif defined?(Test)
198
- Test::Unit::AutoRunner.run(false, nil, test_arguments)
199
- else
200
- not_supported
201
- end
202
- elsif tests.size > 0
203
- # Otherwise we found no tests on this line, so you need to pick one.
204
- message = "No tests found on line #{@line}. Valid tests to run:\n\n"
205
-
206
- # For every test ordered by line number,
207
- # spit out the test name and line number where it starts,
208
- tests.by_line_number do |test|
209
- message << "#{sprintf("%0#{tests.column_size}s", test.name)}: m #{@file}:#{test.start_line}\n"
210
- end
211
-
212
- # Spit out helpful message and bail
213
- STDERR.puts message
214
- false
215
- else
216
- # There were no tests at all
217
- message = "There were no tests found.\n\n"
218
- STDERR.puts message
219
- false
220
- end
221
- end
222
-
223
- # Finds all test suites in this test file, with test methods included.
224
- def suites
225
- # Since we're not using `ruby -Itest -Ilib` to run the tests, we need to add this directory to the `LOAD_PATH`
226
- $:.unshift "./test", "./spec", "./lib"
227
-
228
- begin
229
- # Fire up this Ruby file. Let's hope it actually has tests.
230
- load @file
231
- rescue LoadError => e
232
- # Fail with a happier error message instead of spitting out a backtrace from this gem
233
- STDERR.puts "Failed loading test file:\n#{e.message}"
234
- return []
235
- end
236
-
237
- # Figure out what test framework we're using
238
- if Frameworks.minitest5?
239
- suites = Minitest::Runnable.runnables
240
- elsif Frameworks.minitest4?
241
- suites = MiniTest::Unit::TestCase.test_suites
242
- elsif defined?(Test)
243
- suites = Test::Unit::TestCase.test_suites
244
- else
245
- suites = []
246
- not_supported
247
- end
248
-
249
- # Use some janky internal APIs to group test methods by test suite.
250
- suites.inject({}) do |suites, suite_class|
251
- # End up with a hash of suite class name to an array of test methods, so we can later find them and ignore empty test suites
252
- if Frameworks.minitest5?
253
- suites[suite_class] = suite_class.runnable_methods if suite_class.runnable_methods.size > 0
254
- else
255
- suites[suite_class] = suite_class.test_methods if suite_class.test_methods.size > 0
256
- end
257
- suites
258
- end
259
- end
260
-
261
- # Shoves tests together in our custom container and collection classes.
262
- # Memoize it since it's unnecessary to do this more than one for a given file.
263
- def tests
264
- @tests ||= begin
265
- require "m/test_collection"
266
- require "m/test_method"
267
- # With each suite and array of tests,
268
- # and with each test method present in this test file,
269
- # shove a new test method into this collection.
270
- suites.inject(TestCollection.new) do |collection, (suite_class, test_methods)|
271
- test_methods.each do |test_method|
272
- collection << TestMethod.create(suite_class, test_method)
273
- end
274
- collection
275
- end
276
- end
277
- end
278
-
279
- # Fail loudly if this isn't supported
280
- def not_supported
281
- STDERR.puts "This test framework is not supported! Please open up an issue at https://github.com/qrush/m !"
282
- false
283
- end
284
- end
285
15
  end