forking_test_runner 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 526b183c2e01a812e6598740d3793c7f066b7388
4
- data.tar.gz: 0773d4da8e38e74bf76b612064d9cef46af361d0
3
+ metadata.gz: de99eb6c9f92a0d16b7b0e85053449bce2418a30
4
+ data.tar.gz: bca4f9f34d9fff0a2bc665e680934403edfe71fa
5
5
  SHA512:
6
- metadata.gz: 30723e795b02d4c3fbdb3d61790206dc965a9d7a11bebe92589589b43a4e0d31dea2f052f81d0b3ae09e265401b272726395966929692f0f83838c95c93f0936
7
- data.tar.gz: 5e0cd98d64fcf90c578a2af9a584666a17a2561878840cfa8390931c753d3c901fdf2a58f83cdb69c6c8077d7d0e6495419010eb60a8a3f08e1c3e5d8d248810
6
+ metadata.gz: 447e4dd3336ee76632a7f5c20ce3e7a92509c37ddd3e4123557e9ec74f0dd6c653116cde1e87e557ad8a8013c332b15a29c2e2e4e35b22f7976f62baedf76fff
7
+ data.tar.gz: 342d7b3bbafbddf334c778b27ed7fa3ab71b2a45a3cfc879fd994fc157a024f33994087bff40102b874c2cbf72b7842ba964907fae39ef2876e3abd1bf03854a
@@ -8,7 +8,10 @@ module ForkingTestRunner
8
8
  @rspec = delete_argv("--rspec", argv, arg: false)
9
9
  @no_fixtures = delete_argv("--no-fixtures", argv, arg: false)
10
10
 
11
+ @quiet = delete_argv("--quiet", argv, arg: false)
12
+
11
13
  disable_test_autorun
14
+
12
15
  load_test_env(delete_argv("--helper", argv))
13
16
 
14
17
  # figure out what we need to run
@@ -16,26 +19,43 @@ module ForkingTestRunner
16
19
  runtime_log = delete_argv("--runtime-log", argv)
17
20
  group, group_count, tests = extract_group_args(argv)
18
21
  tests = find_tests_for_group(group, group_count, tests, runtime_log)
19
- puts "Running tests #{tests.map(&:first).join(" ")}"
22
+
23
+ if @quiet
24
+ puts "Running #{tests.size} test files"
25
+ else
26
+ puts "Running tests #{tests.map(&:first).join(" ")}"
27
+ end
20
28
 
21
29
  # run all the tests
22
30
  results = tests.map do |file, expected|
23
- puts "#{CLEAR} >>> #{file}"
24
- time, success = benchmark { run_test(file) }
25
- puts "Time: expected #{expected.round(2)}, actual #{time.round(2)}" if runtime_log
26
- puts "#{CLEAR} <<< #{file} ---- #{success ? "OK" : "Failed"}"
27
- [file, time, expected, success]
31
+ puts "#{CLEAR} >>> #{file} "
32
+ time, success, output = benchmark { run_test(file) }
33
+
34
+ puts output if !success && @quiet
35
+
36
+ unless @quiet
37
+ puts "Time: expected #{expected.round(2)}, actual #{time.round(2)}" if runtime_log
38
+ puts "#{CLEAR} <<< #{file} ---- #{success ? "OK" : "Failed"}"
39
+ end
40
+ [file, time, expected, output, success]
28
41
  end
29
42
 
30
- # pretty print the results
31
- puts "\nResults:"
32
- puts results.
33
- sort_by { |_,_,_,r| r ? 0 : 1 }. # failures should be last so they are easy to find
34
- map { |f,_,_,r| "#{f}: #{r ? "OK" : "Fail"}"}
43
+ unless @quiet
44
+ # pretty print the results
45
+ puts "\nResults:"
46
+ puts results.
47
+ sort_by { |_,_,_,_,r| r ? 0 : 1 }. # failures should be last so they are easy to find
48
+ map { |f,_,_,_,r| "#{f}: #{r ? "OK" : "Fail"}"}
49
+ puts
50
+ end
51
+
52
+ success = results.map(&:last).all?
53
+
54
+ puts colorize(success, summarize_results(results.map { |r| r[3] }))
35
55
 
36
56
  if runtime_log
37
57
  # show how long they ran vs expected
38
- diff = results.map { |_,time,expected,_| time - expected }.inject(:+).to_f
58
+ diff = results.map { |_,time,expected| time - expected }.inject(:+).to_f
39
59
  puts "Time: #{diff.round(2)} diff to expected"
40
60
  end
41
61
 
@@ -46,17 +66,37 @@ module ForkingTestRunner
46
66
  end
47
67
 
48
68
  # exit with success or failure
49
- results.map(&:last).all? ? 0 : 1
69
+ success ? 0 : 1
50
70
  end
51
71
 
52
72
  private
53
73
 
74
+ def colorize(green, string)
75
+ if $stdout.tty?
76
+ "\e[#{green ? 32 : 31}m#{string}\e[0m"
77
+ else
78
+ string
79
+ end
80
+ end
81
+
82
+ def summarize_results(results)
83
+ runner = if @rspec
84
+ require 'parallel_tests/test/runner'
85
+ ParallelTests::Test::Runner
86
+ else
87
+ require 'parallel_tests/rspec/runner'
88
+ ParallelTests::RSpec::Runner
89
+ end
90
+
91
+ runner.summarize_results(results.map { |r| runner.find_results(r) })
92
+ end
93
+
54
94
  def benchmark
55
95
  result = false
56
96
  time = Benchmark.realtime do
57
97
  result = yield
58
98
  end
59
- return time, result
99
+ return [time, result].flatten
60
100
  end
61
101
 
62
102
  # log runtime via dumping or curling it into the runtime log location
@@ -141,13 +181,37 @@ module ForkingTestRunner
141
181
  toggle_test_autorun true, file
142
182
  end
143
183
 
184
+ def fork_with_captured_output(tee_to_stdout)
185
+ rpipe, wpipe = IO.pipe
186
+
187
+ child = fork do
188
+ rpipe.close
189
+ $stdout.reopen(wpipe)
190
+
191
+ yield
192
+ end
193
+
194
+ wpipe.close
195
+
196
+ buffer = ""
197
+
198
+ while ch = rpipe.read(1)
199
+ buffer << ch
200
+ $stdout.write(ch) if tee_to_stdout
201
+ end
202
+
203
+ Process.wait(child)
204
+ buffer
205
+ end
206
+
144
207
  def run_test(file)
145
208
  if ar?
146
209
  preload_fixtures
147
210
  ActiveRecord::Base.connection.disconnect!
148
211
  end
149
- change_program_name_to file do
150
- child = fork do
212
+
213
+ output = change_program_name_to file do
214
+ fork_with_captured_output(!@quiet) do
151
215
  SimpleCov.pid = Process.pid if defined?(SimpleCov) && SimpleCov.respond_to?(:pid=) # trick simplecov into reporting in this fork
152
216
  if ar?
153
217
  key = (ActiveRecord::VERSION::STRING >= "4.1.0" ? :test : "test")
@@ -155,9 +219,9 @@ module ForkingTestRunner
155
219
  end
156
220
  enable_test_autorun(file)
157
221
  end
158
- Process.wait(child)
159
222
  end
160
- $?.success?
223
+
224
+ [$?.success?, output]
161
225
  end
162
226
 
163
227
  def change_program_name_to(name)
@@ -199,6 +263,20 @@ module ForkingTestRunner
199
263
  defined?(ActiveRecord::Base)
200
264
  end
201
265
 
266
+ def minitest_class
267
+ @minitest_class ||= begin
268
+ require 'bundler/setup'
269
+ gem 'minitest'
270
+ if Gem.loaded_specs["minitest"].version.segments.first == 4 # 4.x
271
+ require 'minitest/unit'
272
+ MiniTest::Unit
273
+ else
274
+ require 'minitest'
275
+ Minitest
276
+ end
277
+ end
278
+ end
279
+
202
280
  def toggle_test_autorun(value, file=nil)
203
281
  if @rspec
204
282
  if value
@@ -211,22 +289,10 @@ module ForkingTestRunner
211
289
  $LOAD_PATH.unshift "./spec"
212
290
  end
213
291
  else
214
- @minitest_class ||= begin
215
- require 'bundler/setup'
216
- gem 'minitest'
217
- if Gem.loaded_specs["minitest"].version.segments.first == 4 # 4.x
218
- require 'minitest/unit'
219
- MiniTest::Unit
220
- else
221
- require 'minitest'
222
- Minitest
223
- end
224
- end
225
-
226
- @minitest_class.class_variable_set("@@installed_at_exit", !value)
292
+ minitest_class.class_variable_set("@@installed_at_exit", !value)
227
293
 
228
294
  if value
229
- @minitest_class.autorun
295
+ minitest_class.autorun
230
296
  require "./#{file}"
231
297
  end
232
298
  end
@@ -1,3 +1,3 @@
1
1
  module ForkingTestRunner
2
- VERSION = "0.4.6"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forking_test_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.2.2
156
+ rubygems_version: 2.2.3
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Run every test in a fork to avoid pollution and get clean output per test