minitest 4.7.5 → 5.0.7

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.
@@ -4,7 +4,7 @@
4
4
  # so all the goodies come along (tho not all are wrapped yet to
5
5
  # return another ParallelEach instance).
6
6
 
7
- class ParallelEach
7
+ class Minitest::ParallelEach
8
8
  require 'thread'
9
9
  include Enumerable
10
10
 
@@ -23,10 +23,6 @@ class ParallelEach
23
23
  N.times { @queue << nil }
24
24
  end
25
25
 
26
- def grep pattern # :nodoc:
27
- self.class.new super
28
- end
29
-
30
26
  def select(&block) # :nodoc:
31
27
  self.class.new super
32
28
  end
@@ -49,25 +45,76 @@ class ParallelEach
49
45
  threads.map(&:join)
50
46
  end
51
47
 
52
- def count
48
+ def count # :nodoc:
53
49
  [@queue.size - N, 0].max
54
50
  end
55
51
 
56
- alias_method :size, :count
52
+ alias_method :size, :count # :nodoc:
57
53
  end
58
54
 
59
- class MiniTest::Unit
60
- alias _old_run_suites _run_suites
55
+ module Minitest
56
+ class << self
57
+ remove_method :__run
58
+ end
59
+
60
+ class Test
61
+ @mutex = Mutex.new
62
+
63
+ def self.synchronize # :nodoc:
64
+ if @mutex then # see parallel_each.rb
65
+ @mutex.synchronize { yield }
66
+ else
67
+ yield
68
+ end
69
+ end
70
+
71
+ alias :simple_capture_io :capture_io
72
+
73
+ def capture_io(&b)
74
+ Test.synchronize do
75
+ simple_capture_io(&b)
76
+ end
77
+ end
78
+
79
+ alias :simple_capture_subprocess_io :capture_subprocess_io
80
+
81
+ def capture_subprocess_io(&b)
82
+ Test.synchronize do
83
+ simple_capture_subprocess_io(&b)
84
+ end
85
+ end
86
+ end
87
+
88
+ class Reporter
89
+ @mutex = Mutex.new
90
+
91
+ def self.synchronize # :nodoc:
92
+ if @mutex then # see parallel_each.rb
93
+ @mutex.synchronize { yield }
94
+ else
95
+ yield
96
+ end
97
+ end
98
+
99
+ alias :simple_record :record
100
+
101
+ def record result
102
+ Reporter.synchronize do
103
+ simple_record result
104
+ end
105
+ end
106
+ end
61
107
 
62
108
  ##
63
109
  # Runs all the +suites+ for a given +type+. Runs suites declaring
64
110
  # a test_order of +:parallel+ in parallel, and everything else
65
111
  # serial.
66
112
 
67
- def _run_suites suites, type
113
+ def self.__run reporter, options
114
+ suites = Runnable.runnables
68
115
  parallel, serial = suites.partition { |s| s.test_order == :parallel }
69
116
 
70
- ParallelEach.new(parallel).map { |suite| _run_suite suite, type } +
71
- serial.map { |suite| _run_suite suite, type }
117
+ ParallelEach.new(parallel).map { |suite| suite.run reporter, options } +
118
+ serial.map { |suite| suite.run reporter, options }
72
119
  end
73
120
  end
@@ -1,112 +1,4 @@
1
- require "minitest/unit"
1
+ require "minitest"
2
2
 
3
- ##
4
- # Show your testing pride!
5
-
6
- class PrideIO
7
-
8
- # Start an escape sequence
9
- ESC = "\e["
10
-
11
- # End the escape sequence
12
- NND = "#{ESC}0m"
13
-
14
- # The IO we're going to pipe through.
15
- attr_reader :io
16
-
17
- def initialize io # :nodoc:
18
- @io = io
19
- # stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
20
- # also reference http://en.wikipedia.org/wiki/ANSI_escape_code
21
- @colors ||= (31..36).to_a
22
- @size = @colors.size
23
- @index = 0
24
- # io.sync = true
25
- end
26
-
27
- ##
28
- # Wrap print to colorize the output.
29
-
30
- def print o
31
- case o
32
- when "." then
33
- io.print pride o
34
- when "E", "F" then
35
- io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
36
- else
37
- io.print o
38
- end
39
- end
40
-
41
- def puts(*o) # :nodoc:
42
- o.map! { |s|
43
- s.to_s.sub(/Finished tests/) {
44
- @index = 0
45
- 'Fabulous tests'.split(//).map { |c|
46
- pride(c)
47
- }.join
48
- }
49
- }
50
-
51
- super
52
- end
53
-
54
- ##
55
- # Color a string.
56
-
57
- def pride string
58
- string = "*" if string == "."
59
- c = @colors[@index % @size]
60
- @index += 1
61
- "#{ESC}#{c}m#{string}#{NND}"
62
- end
63
-
64
- def method_missing msg, *args # :nodoc:
65
- io.send(msg, *args)
66
- end
67
- end
68
-
69
- ##
70
- # If you thought the PrideIO was colorful...
71
- #
72
- # (Inspired by lolcat, but with clean math)
73
-
74
- class PrideLOL < PrideIO
75
- PI_3 = Math::PI / 3 # :nodoc:
76
-
77
- def initialize io # :nodoc:
78
- # walk red, green, and blue around a circle separated by equal thirds.
79
- #
80
- # To visualize, type this into wolfram-alpha:
81
- #
82
- # plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
83
-
84
- # 6 has wide pretty gradients. 3 == lolcat, about half the width
85
- @colors = (0...(6 * 7)).map { |n|
86
- n *= 1.0 / 6
87
- r = (3 * Math.sin(n ) + 3).to_i
88
- g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
89
- b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
90
-
91
- # Then we take rgb and encode them in a single number using base 6.
92
- # For some mysterious reason, we add 16... to clear the bottom 4 bits?
93
- # Yes... they're ugly.
94
-
95
- 36 * r + 6 * g + b + 16
96
- }
97
-
98
- super
99
- end
100
-
101
- ##
102
- # Make the string even more colorful. Damnit.
103
-
104
- def pride string
105
- c = @colors[@index % @size]
106
- @index += 1
107
- "#{ESC}38;5;#{c}m#{string}#{NND}"
108
- end
109
- end
110
-
111
- klass = ENV['TERM'] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
112
- MiniTest::Unit.output = klass.new(MiniTest::Unit.output)
3
+ Minitest.load_plugins
4
+ Minitest::PrideIO.pride!
@@ -0,0 +1,143 @@
1
+ require "minitest"
2
+
3
+ module Minitest
4
+ def self.plugin_pride_options opts, options # :nodoc:
5
+ opts.on "-p", "--pride", "Pride. Show your testing pride!" do
6
+ PrideIO.pride!
7
+ end
8
+ end
9
+
10
+ def self.plugin_pride_init options # :nodoc:
11
+ if PrideIO.pride? then
12
+ klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
13
+ io = klass.new options[:io]
14
+
15
+ self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
16
+ rep.io = io
17
+ end
18
+ end
19
+ end
20
+
21
+ ##
22
+ # Show your testing pride!
23
+
24
+ class PrideIO
25
+ ##
26
+ # Activate the pride plugin. Called from both -p option and minitest/pride
27
+
28
+ def self.pride!
29
+ @pride = true
30
+ end
31
+
32
+ ##
33
+ # Are we showing our testing pride?
34
+
35
+ def self.pride?
36
+ @pride ||= false
37
+ end
38
+
39
+ # Start an escape sequence
40
+ ESC = "\e["
41
+
42
+ # End the escape sequence
43
+ NND = "#{ESC}0m"
44
+
45
+ # The IO we're going to pipe through.
46
+ attr_reader :io
47
+
48
+ def initialize io # :nodoc:
49
+ @io = io
50
+ # stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
51
+ # also reference http://en.wikipedia.org/wiki/ANSI_escape_code
52
+ @colors ||= (31..36).to_a
53
+ @size = @colors.size
54
+ @index = 0
55
+ # io.sync = true
56
+ end
57
+
58
+ ##
59
+ # Wrap print to colorize the output.
60
+
61
+ def print o
62
+ case o
63
+ when "." then
64
+ io.print pride o
65
+ when "E", "F" then
66
+ io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
67
+ when "S" then
68
+ io.print pride o
69
+ else
70
+ io.print o
71
+ end
72
+ end
73
+
74
+ def puts(*o) # :nodoc:
75
+ o.map! { |s|
76
+ s.to_s.sub(/Finished/) {
77
+ @index = 0
78
+ 'Fabulous run'.split(//).map { |c|
79
+ pride(c)
80
+ }.join
81
+ }
82
+ }
83
+
84
+ io.puts(*o)
85
+ end
86
+
87
+ ##
88
+ # Color a string.
89
+
90
+ def pride string
91
+ string = "*" if string == "."
92
+ c = @colors[@index % @size]
93
+ @index += 1
94
+ "#{ESC}#{c}m#{string}#{NND}"
95
+ end
96
+
97
+ def method_missing msg, *args # :nodoc:
98
+ io.send(msg, *args)
99
+ end
100
+ end
101
+
102
+ ##
103
+ # If you thought the PrideIO was colorful...
104
+ #
105
+ # (Inspired by lolcat, but with clean math)
106
+
107
+ class PrideLOL < PrideIO
108
+ PI_3 = Math::PI / 3 # :nodoc:
109
+
110
+ def initialize io # :nodoc:
111
+ # walk red, green, and blue around a circle separated by equal thirds.
112
+ #
113
+ # To visualize, type this into wolfram-alpha:
114
+ #
115
+ # plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
116
+
117
+ # 6 has wide pretty gradients. 3 == lolcat, about half the width
118
+ @colors = (0...(6 * 7)).map { |n|
119
+ n *= 1.0 / 6
120
+ r = (3 * Math.sin(n ) + 3).to_i
121
+ g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
122
+ b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
123
+
124
+ # Then we take rgb and encode them in a single number using base 6.
125
+ # For some mysterious reason, we add 16... to clear the bottom 4 bits?
126
+ # Yes... they're ugly.
127
+
128
+ 36 * r + 6 * g + b + 16
129
+ }
130
+
131
+ super
132
+ end
133
+
134
+ ##
135
+ # Make the string even more colorful. Damnit.
136
+
137
+ def pride string
138
+ c = @colors[@index % @size]
139
+ @index += 1
140
+ "#{ESC}38;5;#{c}m#{string}#{NND}"
141
+ end
142
+ end
143
+ end