minitest-sprint 1.2.2 → 1.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b41b1bfaf2a97919bf828fc3c2f16ccec95586fb8c235b27b3f3fad24f7167ab
4
- data.tar.gz: e84c24a78164f343fafecd2c7a3163640d809766a65d670ae745667817a3d8a6
3
+ metadata.gz: 15862af6101198e626598b28e42340d09444d9d6e6db2b7a87e8ec8cf04cec21
4
+ data.tar.gz: d9560abffb24db61b91063df3c0864f2381895a6efc27474ca844deb5141edb4
5
5
  SHA512:
6
- metadata.gz: 3a8787ebc703cf777efc0d9813729cfe3fe633258b3adc9852ae3a5edd67588760f84b6e781b59b7d97d2400774609a84f8cbb975cc4245ce18de307fdad1ce0
7
- data.tar.gz: 2fa35f00ce315c2018271cd262bd01c3e5104600a21c3b4d1727c6d4aeff361d42a8a3e4e3b6317cd6c702f1079ce6bb55f4fad1821e051c6e9626ab0f6f23be
6
+ metadata.gz: b50824def71637787d6210669a0e9301f6f7e511bbf46632430adf4e9767b10023fa17bdd1e096703368f3d7c19610884d652de015c083bd7e55ced49b6d6af4
7
+ data.tar.gz: e2a1fd53a85f454d919abced1ecdc2a082f02309bd3c3ce2e029cdec38f2afb5a6556f2eaed75f0be85bcc3491464f20f32414beabb90734ac497c41ddae63d3
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,25 @@
1
+ === 1.4.0 / 2025-11-17
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Added multiple line number support: eg test.rb:42,50-100 (multiple files too)
6
+
7
+ * 3 bug fixes:
8
+
9
+ * Fixed exception raised when requiring default test that wasn't actually there
10
+ * Fixed shebang on bin/minitest for linux
11
+ * Set minimum ruby version to 3.1.
12
+
13
+ === 1.3.0 / 2024-07-23
14
+
15
+ * 1 minor enhancement:
16
+
17
+ * Allow rake task name to be passed as an argument and repeated back in failure list. (adam12)
18
+
19
+ * 1 bug fix:
20
+
21
+ * Fixed wonky shebang in bin/minitest.
22
+
1
23
  === 1.2.2 / 2022-06-20
2
24
 
3
25
  * 1 bug fix:
data/README.rdoc CHANGED
@@ -8,14 +8,22 @@ rdoc :: http://docs.seattlerb.org/minitest-sprint
8
8
  Runs (Get it? It's fast!) your tests and makes it easier to rerun individual
9
9
  failures.
10
10
 
11
- === Tab Completion
12
-
13
- Add this to your .bashrc (or .zshrc?--someone please confirm with a PR):
11
+ == FEATURES/PROBLEMS:
14
12
 
15
- $ complete -o bashdefault -f -C 'ruby --disable-gems $(gem which minitest/complete)' minitest
13
+ * Run tests by line number <path>:<line-specifiers>:
14
+ * test.rb:42
15
+ * test.rb:50-100
16
+ * test1.rb:42,50-100,150 test2.rb:13
17
+ * Uses path_expander, so you can use:
18
+ * dir_arg -- expand a directory automatically
19
+ * @file_of_args -- persist arguments in a file
20
+ * -path_to_subtract -- ignore intersecting subsets of files/directories
21
+ * Includes a script for commandline autocompletion of test names.
22
+ * Includes extra plugins to print out failure re-run commands.
23
+ * One for the minitest commandline runner. (--binstub)
24
+ * One for rake test runners. (--rake)
16
25
 
17
- Running individual minitest tests will now have tab completion for the
18
- method names. When running tests, just hit tab after -n. For example:
26
+ == SYNOPSIS:
19
27
 
20
28
  $ minitest test/test_whatever.rb -n test_thingy<TAB><TAB>
21
29
  test_thingy_error
@@ -24,19 +32,19 @@ method names. When running tests, just hit tab after -n. For example:
24
32
  test_thingy_failing_filtered
25
33
  ... etc ...
26
34
 
27
- == FEATURES/PROBLEMS:
35
+ # Rakefile
36
+ Minitest::TestTask.create do |t|
37
+ t.extra_args = ["--rake"] # Or --binstub
38
+ end
28
39
 
29
- * TEENY implementation.
30
- * Includes a script for commandline autocompletion of test names.
31
- * Includes extra plugins to print out failure re-run commands.
32
- * One for the minitest commandline runner. (--binstub)
33
- * One for rake test runners. (--rake)
34
- * Uses path_expander, so you can use:
35
- * dir_arg -- expand a directory automatically
36
- * @file_of_args -- persist arguments in a file
37
- * -path_to_subtract -- ignore intersecting subsets of files/directories
40
+ === Tab Completion
38
41
 
39
- == SYNOPSIS:
42
+ Add this to your .bashrc (or .zshrc?--someone please confirm with a PR):
43
+
44
+ $ complete -o bashdefault -f -C 'ruby --disable-gems $(gem which minitest/complete)' minitest
45
+
46
+ Running individual minitest tests will now have tab completion for the
47
+ method names. When running tests, just hit tab after -n. For example:
40
48
 
41
49
  $ minitest test/test_whatever.rb -n test_thingy<TAB><TAB>
42
50
  test_thingy_error
@@ -51,7 +59,7 @@ method names. When running tests, just hit tab after -n. For example:
51
59
 
52
60
  == INSTALL:
53
61
 
54
- * sudo gem install minitest-sprint
62
+ * gem install minitest-sprint
55
63
 
56
64
  == LICENSE:
57
65
 
data/Rakefile CHANGED
@@ -11,7 +11,10 @@ Hoe.spec "minitest-sprint" do
11
11
  developer "Ryan Davis", "ryand-ruby@zenspider.com"
12
12
  license "MIT"
13
13
 
14
+ require_ruby_version ">= 3.1"
15
+
14
16
  dependency "path_expander", "~> 1.1"
17
+ dependency "prism", "~> 1.5"
15
18
  end
16
19
 
17
20
  # vim: syntax=ruby
data/bin/minitest CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env -S ruby
2
2
 
3
3
  require "minitest/sprint"
4
4
 
@@ -1,4 +1,5 @@
1
1
  require "path_expander"
2
+ require "prism"
2
3
 
3
4
  module Minitest; end # :nodoc:
4
5
 
@@ -6,10 +7,45 @@ module Minitest; end # :nodoc:
6
7
  # Minitest's PathExpander to find and filter tests.
7
8
 
8
9
  class Minitest::PathExpander < PathExpander
10
+ attr_accessor :by_line
11
+
9
12
  TEST_GLOB = "**/{test_*,*_test,spec_*,*_spec}.rb" # :nodoc:
10
13
 
11
14
  def initialize args = ARGV # :nodoc:
12
15
  super args, TEST_GLOB, "test"
16
+ self.by_line = {}
17
+ end
18
+
19
+ def process(&b) # :nodoc: TODO: push up!
20
+ super.each(&b)
21
+ post_process
22
+ self
23
+ end
24
+
25
+ def process_args # :nodoc:
26
+ args.reject! { |arg| # this is a good use of overriding
27
+ case arg
28
+ when /^(.*):([\d,-]+)$/ then
29
+ f, ls = $1, $2
30
+ ls = ls
31
+ .split(/,/)
32
+ .map { |l|
33
+ case l
34
+ when /^\d+$/ then
35
+ l.to_i
36
+ when /^(\d+)-(\d+)$/ then
37
+ $1.to_i..$2.to_i
38
+ else
39
+ raise "unhandled argument format: %p" % [l]
40
+ end
41
+ }
42
+ next unless File.exist? f
43
+ args << f # push path on lest it run whole dir
44
+ by_line[f] = ls
45
+ end
46
+ }
47
+
48
+ super
13
49
  end
14
50
 
15
51
  ##
@@ -31,4 +67,131 @@ class Minitest::PathExpander < PathExpander
31
67
  end
32
68
  }
33
69
  end
70
+
71
+ ##
72
+ # Add additional arguments to args to handle path:line argument filtering
73
+
74
+ def post_process
75
+ return if by_line.empty?
76
+
77
+ tests = tests_by_class
78
+
79
+ exit! if handle_missing_tests? tests
80
+
81
+ test_res = tests_to_regexp tests
82
+ self.args << "-n" << "/#{test_res.join "|"}/"
83
+ end
84
+
85
+ def all_tests
86
+ Minitest.seed = 42 # minor hack to deal with runnable_methods shuffling
87
+ Minitest::Runnable.runnables
88
+ .to_h { |k|
89
+ ms = k.runnable_methods
90
+ .sort
91
+ .map { |m| TM.new k, m.to_sym }
92
+ .sort_by { |t| [t.path, t.line_s] }
93
+ [k, ms]
94
+ }
95
+ .reject { |k, v| v.empty? }
96
+ end
97
+
98
+ ##
99
+ # Returns a hash mapping Minitest runnable classes to TMs
100
+
101
+ def tests_by_class
102
+ all_tests
103
+ .transform_values { |ms|
104
+ ms.select { |m| bl=by_line[m.path]; not bl or bl.any? { |l| m.include? l } }
105
+ }
106
+ .reject { |k, v| v.empty? }
107
+ end
108
+
109
+ ##
110
+ # Converts +tests+ to an array of "klass#(methods+)" regexps to be
111
+ # used for test selection.
112
+
113
+ def tests_to_regexp tests
114
+ tests # { k1 => [Test(a), ...}
115
+ .transform_values { |tms| tms.map(&:name) } # { k1 => %w[a, b], ...}
116
+ .map { |k, ns| # [ "k1#(?:a|b)", "k2#c", ...]
117
+ if ns.size > 1 then
118
+ ns.map! { |n| Regexp.escape n }
119
+ "%s#\(%s\)" % [Regexp.escape(k.name), ns.join("|")]
120
+ else
121
+ "%s#%s" % [Regexp.escape(k.name), ns.first]
122
+ end
123
+ }
124
+ end
125
+
126
+ ##
127
+ # Handle the case where a line number doesn't match any known tests.
128
+ # Returns true to signal that running should stop.
129
+
130
+ def handle_missing_tests? tests
131
+ _tests = tests.values.flatten
132
+ not_found = by_line
133
+ .flat_map { |f, ls| ls.map { |l| [f, l] } }
134
+ .reject { |f, l|
135
+ _tests.any? { |t| t.path == f and t.include? l }
136
+ }
137
+
138
+ unless not_found.empty? then
139
+ by_path = all_tests.values.flatten.group_by(&:path)
140
+
141
+ puts
142
+ puts "ERROR: test(s) not found at:"
143
+ not_found.each do |f, l|
144
+ puts " %s:%s" % [f, l]
145
+ puts
146
+ puts "Did you mean?"
147
+ puts
148
+ l = l.begin if l.is_a? Range
149
+ by_path[f]
150
+ .sort_by { |m| (m.line_s - l).abs }
151
+ .first(2)
152
+ .each do |m|
153
+ puts " %-30s (dist=%+d) (%s)" % [m, m.line_s - l, m.name]
154
+ end
155
+ puts
156
+ end
157
+ true
158
+ end
159
+ end
160
+
161
+ TM = Data.define :klass, :name, :path, :lines do
162
+ def initialize klass:, name:
163
+ method = klass.instance_method name
164
+ path, line_s = method.source_location
165
+
166
+ path = path.delete_prefix "#{Dir.pwd}/"
167
+
168
+ line_e = line_s + TM.source_for(method).lines.size - 1
169
+
170
+ lines = line_s..line_e
171
+
172
+ super klass:, name:, path:, lines:
173
+ end
174
+
175
+ def self.source_for method
176
+ path, line = method.source_location
177
+ file = cache[path] ||= File.readlines(path)
178
+
179
+ ruby = +""
180
+
181
+ file[line-1..].each do |l|
182
+ ruby << l
183
+ return ruby if Prism.parse_success? ruby
184
+ end
185
+
186
+ nil
187
+ end
188
+
189
+ def self.cache = @cache ||= {}
190
+
191
+ def include?(o) = o.is_a?(Integer) ? lines.include?(o) : lines.overlap?(o)
192
+
193
+ def to_s = "%s:%d-%d" % [path, lines.begin, lines.end]
194
+
195
+ def line_s = lines.begin
196
+ end
34
197
  end
@@ -2,9 +2,16 @@ require "minitest/sprint_reporter"
2
2
 
3
3
  module Minitest
4
4
  class RakeReporter < SprintReporter
5
+ attr_accessor :name
6
+
7
+ def initialize name = nil
8
+ self.results = []
9
+ self.name = name
10
+ end
11
+
5
12
  def print_list
6
13
  results.each do |result|
7
- puts " rake N=#{result.class_name}##{result.name}"
14
+ puts [" rake", name, "N=#{result.class_name}##{result.name}"].compact.join(" ")
8
15
  end
9
16
  end
10
17
  end
@@ -5,11 +5,10 @@ $LOAD_PATH.unshift "test"
5
5
  $LOAD_PATH.unshift "lib"
6
6
 
7
7
  class Minitest::Sprint
8
- VERSION = "1.2.2"
8
+ VERSION = "1.4.0"
9
9
 
10
10
  def self.run args = ARGV
11
- Minitest::PathExpander.new(args).process.each do |f|
12
- require "./#{f}"
13
- end
11
+ Minitest::PathExpander.new(args)
12
+ .process { |f| require "./#{f}" if File.file? f }
14
13
  end
15
14
  end
@@ -2,8 +2,9 @@ require "minitest"
2
2
 
3
3
  module Minitest
4
4
  def self.plugin_sprint_options opts, options # :nodoc:
5
- opts.on "--rake", "Report how to re-run failures with rake." do
5
+ opts.on "--rake [TASK]", "Report how to re-run failures with rake." do |task|
6
6
  options[:sprint] = :rake
7
+ options[:rake_task] = task
7
8
  end
8
9
 
9
10
  opts.on "--binstub", "Report how to re-run failures with minitest." do
@@ -15,7 +16,7 @@ module Minitest
15
16
  case options[:sprint]
16
17
  when :rake then
17
18
  require "minitest/rake_reporter"
18
- self.reporter << Minitest::RakeReporter.new
19
+ self.reporter << Minitest::RakeReporter.new(options[:rake_task])
19
20
  when :binstub then
20
21
  require "minitest/binstub_reporter"
21
22
  self.reporter << Minitest::BinstubReporter.new
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-sprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
12
11
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBBjANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
12
+ MIIDPjCCAiagAwIBAgIBCTANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
13
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTIxMTIyMzIzMTkwNFoXDTIyMTIyMzIzMTkwNFowRTETMBEGA1UE
14
+ GRYDY29tMB4XDTI1MDEwNjIzMjcwMVoXDTI2MDEwNjIzMjcwMVowRTETMBEGA1UE
16
15
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
16
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
17
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -22,14 +21,14 @@ cert_chain:
22
21
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
23
22
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
24
23
  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB
25
- AQCKB5jfsuSnKb+t/Wrh3UpdkmX7TrEsjVmERC0pPqzQ5GQJgmEXDD7oMgaKXaAq
26
- x2m+KSZDrqk7c8uho5OX6YMqg4KdxehfSLqqTZGoeV78qwf/jpPQZKTf+W9gUSJh
27
- zsWpo4K50MP+QtdSbKXZwjAafpQ8hK0MnnZ/aeCsW9ov5vdXpYbf3dpg6ADXRGE7
28
- lQY2y1tJ5/chqu6h7dQmnm2ABUqx9O+JcN9hbCYoA5i/EeubUEtFIh2w3SpO6YfB
29
- JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
- YsuyUzsMz6GQA4khyaMgKNSD
24
+ AQAC0WQJcPOWPFwkojhzweilRVjTJ19UiLhiBTw3C1wJO3LVdBkWDmnnhAmKuX4D
25
+ r7vjQvESlABGIPdutI1Yl7mrHQzTkfLfXvNN6MT0nLChPyIYauT6SZZxubwJrUfA
26
+ 7R0c2CJTIboZ0XaGpLsXqHEF1c29H7TV1QvVuqKAN2mCjh4N82QVn+ZKtys28AwT
27
+ 6GfQX2fqLoi4KSc7xIzHKaNzqxeOICmJofk9w5VZ2rRN6yes8jvFYwz9HR41wdj8
28
+ bwfinv7Yp5fA6AysuZLhCykyfDuZVRrUp0Vb68YCKsLjJly/Theak+euNTxvHsB+
29
+ al9oSgPPHICMEX65qvLywitx
31
30
  -----END CERTIFICATE-----
32
- date: 2022-06-20 00:00:00.000000000 Z
31
+ date: 1980-01-02 00:00:00.000000000 Z
33
32
  dependencies:
34
33
  - !ruby/object:Gem::Dependency
35
34
  name: path_expander
@@ -45,6 +44,20 @@ dependencies:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
46
  version: '1.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: prism
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.5'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.5'
48
61
  - !ruby/object:Gem::Dependency
49
62
  name: rdoc
50
63
  requirement: !ruby/object:Gem::Requirement
@@ -71,14 +84,14 @@ dependencies:
71
84
  requirements:
72
85
  - - "~>"
73
86
  - !ruby/object:Gem::Version
74
- version: '3.23'
87
+ version: '4.3'
75
88
  type: :development
76
89
  prerelease: false
77
90
  version_requirements: !ruby/object:Gem::Requirement
78
91
  requirements:
79
92
  - - "~>"
80
93
  - !ruby/object:Gem::Version
81
- version: '3.23'
94
+ version: '4.3'
82
95
  description: |-
83
96
  Runs (Get it? It's fast!) your tests and makes it easier to rerun individual
84
97
  failures.
@@ -111,7 +124,6 @@ licenses:
111
124
  - MIT
112
125
  metadata:
113
126
  homepage_uri: https://github.com/seattlerb/minitest-sprint
114
- post_install_message:
115
127
  rdoc_options:
116
128
  - "--main"
117
129
  - README.rdoc
@@ -121,15 +133,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
133
  requirements:
122
134
  - - ">="
123
135
  - !ruby/object:Gem::Version
124
- version: '0'
136
+ version: '3.1'
125
137
  required_rubygems_version: !ruby/object:Gem::Requirement
126
138
  requirements:
127
139
  - - ">="
128
140
  - !ruby/object:Gem::Version
129
141
  version: '0'
130
142
  requirements: []
131
- rubygems_version: 3.3.12
132
- signing_key:
143
+ rubygems_version: 3.7.2
133
144
  specification_version: 4
134
145
  summary: Runs (Get it? It's fast!) your tests and makes it easier to rerun individual
135
146
  failures.
metadata.gz.sig CHANGED
Binary file