micron 0.5.0 → 0.5.1

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: 29d7b92b84fd3c8da1f0d4c41f008153d8074f69
4
- data.tar.gz: f76f16a5f3b5e8dbee5ee3b00a7624b72b8fb199
3
+ metadata.gz: 01a37fda7663cd88bfdd2bf65785187f7abd0e33
4
+ data.tar.gz: 64658365410209329b6ee913f1ea349bec00d8b7
5
5
  SHA512:
6
- metadata.gz: e10e61aee8e0677d2b4bcecc29c4714b909164821ac630d9e54cc80041c49e87dc78332f39b48b6d77a0dcf9579f80bd081061dc0276d8f9022dd21ba27af5de
7
- data.tar.gz: 4bc4917b3ddb759ccb2f5dde09b7898ac5bf788c310554a3e0335eba6e237c6c4fd986876baada9d0e5295e78bc9c762f4832069fa16033fdb5bbb20469310dd
6
+ metadata.gz: 177ec22157dbba989446dec42a9986e31aa5711be9c18ba34b6253b28bd48eda0d190c64c7ef4ff5eb13f697b9b86a225ae873aee9292b05c9e485d712d9f65f
7
+ data.tar.gz: 196ba6ed92b95e032013ed28d6dca7fe9bdaf71f0f50c135b4668db0afcba8306d5d633a1d5d0fcdd2f36db359fbe0a23193858b1a8ede7e84317d2a0ae60dec
data/Gemfile CHANGED
@@ -7,13 +7,11 @@ end
7
7
  gem "easycov", :github => "chetan/easycov"
8
8
 
9
9
  gem "hitimes"
10
- gem "colorize"
10
+ gem "ansi"
11
11
 
12
12
  group :development do
13
13
  gem "yard", "~> 0.8"
14
14
  gem "bundler", "~> 1.1"
15
- gem "jeweler", :git => "https://github.com/chetan/jeweler.git", :branch => "bixby"
16
-
17
- gem "minitest", "~> 4.0", :platforms => [:mri_19, :mri_20, :rbx]
15
+ gem "jeweler", :github => "chetan/jeweler", :branch => "bixby"
18
16
  end
19
17
 
@@ -1,88 +1,100 @@
1
1
  GIT
2
2
  remote: git://github.com/chetan/easycov.git
3
- revision: 58be40eddda14fb8db4f1b72427922e8054bae7a
3
+ revision: 6e89ff38c36a605c4de8a34893726c73bd93f3b4
4
4
  specs:
5
- easycov (0.1.1)
5
+ easycov (0.4.0)
6
6
  multi_json
7
7
  simplecov
8
+ simplecov-console
9
+ simplecov-html
8
10
 
9
11
  GIT
10
- remote: https://github.com/chetan/jeweler.git
11
- revision: c83ba18b074e82415052e80499a770bff87bf944
12
+ remote: git://github.com/chetan/jeweler.git
13
+ revision: b1f048d0ee6bc9febbcadb52b75b77e734782eb4
12
14
  branch: bixby
13
15
  specs:
14
- jeweler (1.8.7)
16
+ jeweler (2.0.1)
15
17
  builder
16
- bundler (~> 1.0)
18
+ bundler (>= 1.0)
17
19
  git (>= 1.2.5)
18
- github_api (= 0.10.1)
20
+ github_api
19
21
  highline (>= 1.6.15)
20
- nokogiri (= 1.5.10)
22
+ nokogiri (>= 1.5.10)
21
23
  rake
22
24
  rdoc
23
25
 
24
26
  PATH
25
27
  remote: .
26
28
  specs:
27
- micron (0.5.0)
28
- colorize
29
+ micron (0.5.1)
30
+ ansi
29
31
  easycov
30
32
  hitimes
31
33
 
32
34
  GEM
33
35
  remote: https://rubygems.org/
34
36
  specs:
35
- addressable (2.3.5)
37
+ addressable (2.3.6)
38
+ ansi (1.4.3)
36
39
  builder (3.2.2)
37
- colorize (0.6.0)
38
- faraday (0.8.8)
39
- multipart-post (~> 1.2.0)
40
+ colorize (0.7.2)
41
+ descendants_tracker (0.0.4)
42
+ thread_safe (~> 0.3, >= 0.3.1)
43
+ docile (1.1.3)
44
+ faraday (0.9.0)
45
+ multipart-post (>= 1.2, < 3)
40
46
  git (1.2.6)
41
- github_api (0.10.1)
42
- addressable
43
- faraday (~> 0.8.1)
47
+ github_api (0.11.3)
48
+ addressable (~> 2.3)
49
+ descendants_tracker (~> 0.0.1)
50
+ faraday (~> 0.8, < 0.10)
44
51
  hashie (>= 1.2)
45
- multi_json (~> 1.4)
46
- nokogiri (~> 1.5.2)
52
+ multi_json (>= 1.7.5, < 2.0)
53
+ nokogiri (~> 1.6.0)
47
54
  oauth2
48
- hashie (2.0.5)
49
- highline (1.6.19)
55
+ hashie (2.1.1)
56
+ highline (1.6.21)
57
+ hirb (0.7.1)
50
58
  hitimes (1.2.1)
51
- httpauth (0.2.0)
52
- json (1.8.0)
53
- jwt (0.1.8)
59
+ json (1.8.1)
60
+ jwt (0.1.11)
54
61
  multi_json (>= 1.5)
55
- minitest (4.7.5)
56
- multi_json (1.8.0)
62
+ mini_portile (0.5.3)
63
+ multi_json (1.9.2)
57
64
  multi_xml (0.5.5)
58
- multipart-post (1.2.0)
59
- nokogiri (1.5.10)
60
- oauth2 (0.9.2)
61
- faraday (~> 0.8)
62
- httpauth (~> 0.2)
63
- jwt (~> 0.1.4)
64
- multi_json (~> 1.0)
65
+ multipart-post (2.0.0)
66
+ nokogiri (1.6.1)
67
+ mini_portile (~> 0.5.0)
68
+ oauth2 (0.9.3)
69
+ faraday (>= 0.8, < 0.10)
70
+ jwt (~> 0.1.8)
71
+ multi_json (~> 1.3)
65
72
  multi_xml (~> 0.5)
66
73
  rack (~> 1.2)
67
74
  rack (1.5.2)
68
- rake (10.1.0)
69
- rdoc (4.0.1)
75
+ rake (10.3.1)
76
+ rdoc (4.1.1)
70
77
  json (~> 1.4)
71
- simplecov (0.7.1)
72
- multi_json (~> 1.0)
73
- simplecov-html (~> 0.7.1)
74
- simplecov-html (0.7.1)
75
- yard (0.8.7.2)
78
+ simplecov (0.8.2)
79
+ docile (~> 1.1.0)
80
+ multi_json
81
+ simplecov-html (~> 0.8.0)
82
+ simplecov-console (0.1.3)
83
+ colorize
84
+ hirb
85
+ simplecov
86
+ simplecov-html (0.8.0)
87
+ thread_safe (0.3.3)
88
+ yard (0.8.7.4)
76
89
 
77
90
  PLATFORMS
78
91
  ruby
79
92
 
80
93
  DEPENDENCIES
94
+ ansi
81
95
  bundler (~> 1.1)
82
- colorize
83
96
  easycov!
84
97
  hitimes
85
98
  jeweler!
86
99
  micron!
87
- minitest (~> 4.0)
88
100
  yard (~> 0.8)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -46,12 +46,13 @@ module Micron
46
46
  # Spawn child runner if called
47
47
  if options[:runclass] then
48
48
  require "micron/proc_runner"
49
- Micron.runner = Micron::ProcRunner.new(nil, reporters)
49
+ methods = ENV["MICRON_METHODS"].split(/:/)
50
+ Micron.runner = Micron::ProcRunner.new(nil, methods, reporters)
50
51
  Micron.runner.run_class
51
52
  exit
52
53
  elsif options[:runmethod] then
53
54
  require "micron/proc_runner"
54
- Micron.runner = Micron::ProcRunner.new(nil, reporters)
55
+ Micron.runner = Micron::ProcRunner.new(nil, nil, reporters)
55
56
  Micron.runner.run_method
56
57
  exit
57
58
  end
@@ -81,20 +82,30 @@ module Micron
81
82
 
82
83
  files.sort!
83
84
 
85
+ # Optionally filter files
86
+ if options[:tests] and !options[:tests].empty? then
87
+ files.reject!{ |f|
88
+ options[:tests].find{ |t| f.include?(t) }.nil?
89
+ }
90
+ end
91
+
84
92
  # Run tests
85
93
  if options[:proc] then
86
94
  require "micron/proc_runner"
87
- Micron.runner = Micron::ProcRunner.new(files, reporters)
95
+ runner = Micron::ProcRunner
88
96
  elsif options[:fork] then
89
97
  require "micron/fork_runner"
90
- Micron.runner = Micron::ForkRunner.new(files, reporters)
98
+ runner = Micron::ForkRunner
91
99
  else
92
- Micron.runner = Micron::Runner.new(files, reporters)
100
+ runner = Micron::Runner
93
101
  end
102
+
103
+ Micron.runner = runner.new(files, options[:methods], reporters)
94
104
  results = Micron.runner.run
95
105
 
96
106
  Micron::Runner::Shim.cleanup!
97
107
 
108
+ # set a non-zero exit code if we had any failures
98
109
  exit(count_failures(results) > 0 ? 1 : 0)
99
110
  end
100
111
 
@@ -6,7 +6,9 @@ module Micron
6
6
  class Options
7
7
 
8
8
  DEFAULTS = {
9
- :coverage => true
9
+ :coverage => true,
10
+ :tests => [],
11
+ :methods => [],
10
12
  }
11
13
 
12
14
  def self.parse(options=nil)
@@ -34,6 +36,15 @@ module Micron
34
36
  parser = OptionParser.new do |opts|
35
37
  opts.banner = "usage: #{$0} [options]"
36
38
 
39
+ opts.on("-t", "--test PATTERN", "Only run test files matching pattern") do |p|
40
+ options[:tests] << p
41
+ end
42
+
43
+ opts.on("-m", "--method PATTERN", "Only run test methods matching pattern") do |p|
44
+ p.strip!
45
+ options[:methods] << p if not p.empty?
46
+ end
47
+
37
48
  opts.on("--nocov", "Disable coverage reporting") {
38
49
  options[:coverage] = false
39
50
  }
@@ -53,6 +64,11 @@ module Micron
53
64
  opts.on("--runmethod", "Run method in child process") {
54
65
  options[:runmethod] = true
55
66
  }
67
+
68
+ opts.on("-h", "--help", "Show this message") do
69
+ puts opts
70
+ exit
71
+ end
56
72
  end
57
73
 
58
74
  begin
@@ -0,0 +1,45 @@
1
+
2
+ # Compatibility layer for MiniTest
3
+
4
+ require "micron"
5
+
6
+ old_verbose = $VERBOSE
7
+ $VERBOSE = nil
8
+
9
+ module MiniTest
10
+ Assertion = Micron::Assertion
11
+
12
+ class Unit
13
+
14
+ VERSION = "4.7"
15
+ TestCase = Micron::TestCase
16
+
17
+ def self.autorun
18
+ # noop
19
+ end
20
+
21
+ class TestCase
22
+
23
+ def name
24
+ self.class.name
25
+ end
26
+ alias_method :__name__, :name
27
+
28
+ def micron_method=(method)
29
+ @micron_method = method
30
+ end
31
+
32
+ def passed?
33
+ @micron_method.passed?
34
+ end
35
+
36
+ def self.parallelize_me!
37
+ # noop
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ $VERBOSE = old_verbose
@@ -0,0 +1,47 @@
1
+
2
+ # Compatibility layer for MiniTest
3
+
4
+ require "micron"
5
+
6
+ old_verbose = $VERBOSE
7
+ $VERBOSE = nil
8
+
9
+ module Minitest
10
+
11
+ Assertion = Micron::Assertion
12
+
13
+ VERSION = "5.3.3"
14
+ Test = Micron::TestCase
15
+
16
+ def self.autorun
17
+ # noop
18
+ end
19
+
20
+ class Test
21
+
22
+ def name
23
+ self.class.name
24
+ end
25
+ alias_method :__name__, :name
26
+
27
+ def micron_method=(method)
28
+ @micron_method = method
29
+ end
30
+
31
+ def passed?
32
+ @micron_method.passed?
33
+ end
34
+
35
+ def self.parallelize_me!
36
+ # noop
37
+ end
38
+
39
+ def self.i_suck_and_my_tests_are_order_dependent!
40
+ # noop
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ $VERBOSE = old_verbose
@@ -17,7 +17,7 @@ module Micron
17
17
  $0 = "micron: class"
18
18
  # ERR.puts "micron: class (#{$$})"
19
19
 
20
- test_file = TestFile.new(file)
20
+ test_file = TestFile.new(file, @method_patterns)
21
21
  report(:start_file, test_file)
22
22
 
23
23
  begin
@@ -34,9 +34,9 @@ module Micron
34
34
  results = worker.wait.result
35
35
  results.each do |clazz|
36
36
  if clazz.kind_of? Exception then
37
- puts "Error loading test file: #{file}"
38
- puts clazz
39
- puts clazz.backtrace
37
+ STDERR.puts "Error loading test file: #{file}"
38
+ STDERR.puts clazz
39
+ STDERR.puts clazz.backtrace
40
40
  exit 1
41
41
  end
42
42
 
@@ -1,45 +1,14 @@
1
1
 
2
- # Compatibility layer for MiniTest
3
-
4
- require "micron"
5
-
6
- old_verbose = $VERBOSE
7
- $VERBOSE = nil
8
-
9
- module MiniTest
10
- Assertion = Micron::Assertion
11
-
12
- class Unit
13
-
14
- VERSION = "4.7"
15
- TestCase = Micron::TestCase
16
-
17
- def self.autorun
18
- # noop
19
- end
20
-
21
- class TestCase
22
-
23
- def name
24
- self.class.name
25
- end
26
- alias_method :__name__, :name
27
-
28
- def micron_method=(method)
29
- @micron_method = method
30
- end
31
-
32
- def passed?
33
- @micron_method.passed?
34
- end
35
-
36
- def self.parallelize_me!
37
- # noop
38
- end
39
-
40
- end
41
-
42
- end
2
+ # for backwards compat with older micron
3
+ version = "4"
4
+ begin
5
+ require "minitest"
6
+ version = Minitest::VERSION[0]
7
+ rescue LoadError
43
8
  end
44
9
 
45
- $VERBOSE = old_verbose
10
+ if version == "4" then
11
+ require "micron/compat/minitest47"
12
+ elsif version == "5"
13
+ require "micron/compat/minitest5"
14
+ end
@@ -7,8 +7,8 @@ require "micron/test_case/teardown_coverage"
7
7
  module Micron
8
8
  class ProcRunner < Runner
9
9
 
10
- def initialize(files=nil, reporters=nil)
11
- super(files, reporters)
10
+ def initialize(files=nil, method_patterns=nil, reporters=nil)
11
+ super(files, method_patterns, reporters)
12
12
  end
13
13
 
14
14
  def run
@@ -37,9 +37,9 @@ module Micron
37
37
  while !f.eof
38
38
  clazz = Marshal.load(f) # read Clazz from child via file
39
39
  if clazz.kind_of? Exception then
40
- puts "Error loading test file: #{file}"
41
- puts clazz
42
- puts clazz.backtrace
40
+ STDERR.puts "Error loading test file: #{file}"
41
+ STDERR.puts clazz
42
+ STDERR.puts clazz.backtrace
43
43
  exit 1
44
44
  end
45
45
 
@@ -11,9 +11,18 @@ module Micron
11
11
  def start_class(clazz)
12
12
  end
13
13
 
14
+ def before_class_error(ex)
15
+ end
16
+
17
+ def start_method(method)
18
+ end
19
+
14
20
  def end_method(method)
15
21
  end
16
22
 
23
+ def after_class_error(ex)
24
+ end
25
+
17
26
  def end_class(clazz)
18
27
  end
19
28
 
@@ -1,5 +1,5 @@
1
1
 
2
- require "colorize"
2
+ require "ansi"
3
3
 
4
4
  module Micron
5
5
  class Reporter
@@ -19,6 +19,20 @@ module Micron
19
19
  puts clazz.name
20
20
  end
21
21
 
22
+ def before_class_error(ex)
23
+ puts
24
+ puts indent(bar(underline("Error during before_class; skipping tests")))
25
+ puts indent(bar(Micron.dump_ex(ex, true)))
26
+ puts
27
+ end
28
+
29
+ def after_class_error(ex)
30
+ puts
31
+ puts indent(bar(underline("Error during after_class")))
32
+ puts indent(bar(Micron.dump_ex(ex, true)))
33
+ puts
34
+ end
35
+
22
36
  def end_method(m)
23
37
  name = m.name.to_s
24
38
  duration = sprintf("%0.3f", m.total_duration)
@@ -29,11 +43,11 @@ module Micron
29
43
 
30
44
  # inject color after so we don't screw up the alignment
31
45
  if m.skipped? then
32
- str.gsub!(/#{status}$/, status.colorize(:light_yellow))
46
+ str.gsub!(/#{status}$/, colorize(status, :yellow))
33
47
  elsif m.passed? then
34
- str.gsub!(/#{status}$/, status.colorize(:light_green))
48
+ str.gsub!(/#{status}$/, colorize(status, :green))
35
49
  else
36
- str.gsub!(/#{status}$/, status.colorize(:light_red))
50
+ str.gsub!(/#{status}$/, colorize(status, :red))
37
51
  end
38
52
  puts str
39
53
 
@@ -101,7 +115,7 @@ module Micron
101
115
  real_runtime = sprintf("%0.3f", @runtime.duration)
102
116
 
103
117
  puts
104
- puts ("="*CONSOLE_WIDTH).colorize((fail > 0 ? :light_red : :light_green))
118
+ puts divider(fail > 0 ? :red : (skip > 0 ? :yellow : :green))
105
119
  puts " PASS: #{pass}, FAIL: #{fail}, SKIP: #{skip}"
106
120
  puts " TOTAL: #{total} with #{total_assertions} assertions in #{total_duration} seconds (wall time: #{real_runtime})"
107
121
 
@@ -116,7 +130,7 @@ module Micron
116
130
  }
117
131
  }
118
132
  end
119
- puts ("="*CONSOLE_WIDTH).colorize((fail > 0 ? :light_red : :light_green))
133
+ puts divider(fail > 0 ? :red : (skip > 0 ? :yellow : :green))
120
134
  end
121
135
 
122
136
 
@@ -137,10 +151,35 @@ module Micron
137
151
  (i + str.gsub(/\n/, "\n#{i}")).rstrip
138
152
  end
139
153
 
154
+ def bar(str)
155
+ b = "|"
156
+ str = b + indent(str, 1)
157
+ str.gsub(/\n/, "\n#{b}")
158
+ end
159
+
160
+ # Add an underline to the given string
161
+ #
162
+ # @param [String] str string to underline
163
+ #
164
+ # @return [String] underlined string
140
165
  def underline(str)
141
166
  str += "\n" + "-"*str.length
142
167
  end
143
168
 
169
+ # Draw a divider CONSOLE_WIDTH chars wide in the given color
170
+ def divider(color)
171
+ colorize(("="*CONSOLE_WIDTH), color)
172
+ end
173
+
174
+ def colorize(str, color, bold=true)
175
+ ret = ANSI.reset
176
+ ret += ANSI.bold if bold
177
+ ret += ANSI.send(color)
178
+ ret += str
179
+ ret += ANSI.reset
180
+ ret
181
+ end
182
+
144
183
  end
145
184
  end
146
185
  end
@@ -24,12 +24,13 @@ module Micron
24
24
  NoMemoryError, SignalException, Interrupt, SystemExit
25
25
  ]
26
26
 
27
- attr_reader :results
27
+ attr_reader :results, :reporters, :files
28
28
 
29
- def initialize(files, reporters)
30
- @files = files
31
- @results = []
32
- @reporters = reporters || []
29
+ def initialize(files, method_patterns, reporters)
30
+ @files = files
31
+ @method_patterns = method_patterns || []
32
+ @reporters = reporters || []
33
+ @results = []
33
34
 
34
35
  @mutex = Mutex.new
35
36
 
@@ -46,7 +47,7 @@ module Micron
46
47
 
47
48
  @files.each do |file|
48
49
 
49
- test_file = TestFile.new(file)
50
+ test_file = TestFile.new(file, @method_patterns)
50
51
  report(:start_file, test_file)
51
52
 
52
53
  begin
@@ -58,9 +59,9 @@ module Micron
58
59
 
59
60
  results.each do |clazz|
60
61
  if clazz.kind_of? Exception then
61
- puts "Error loading test file: #{file}"
62
- puts clazz
63
- puts clazz.backtrace
62
+ STDERR.puts "Error loading test file: #{file}"
63
+ STDERR.puts clazz
64
+ STDERR.puts clazz.backtrace
64
65
  exit 1
65
66
  end
66
67
 
@@ -25,7 +25,7 @@ module Micron
25
25
  end
26
26
 
27
27
  # make sure we didn't remove everything - if we did, the error was in our code
28
- new_bt = bt.reject { |line| line =~ %r{(bin|lib)/micron} } if new_bt.empty?
28
+ new_bt = bt.reject { |line| line =~ %r{(bin|lib)/(micron|zeus|spork)} } if new_bt.empty?
29
29
  new_bt = bt.dup if new_bt.empty?
30
30
  else
31
31
  new_bt = bt.dup
@@ -7,10 +7,10 @@ module Micron
7
7
 
8
8
  attr_reader :name, :methods
9
9
 
10
- def initialize(clazz, file)
10
+ def initialize(clazz, file, method_patterns)
11
11
  @name = clazz.to_s
12
12
  @file = file
13
- @methods = test_methods.map { |m| Method.new(self, m) }
13
+ @methods = test_methods(method_patterns).map { |m| Method.new(self, m) }
14
14
  end
15
15
 
16
16
  # Create a new instance of the Class represented by this object
@@ -20,6 +20,7 @@ module Micron
20
20
 
21
21
  def run
22
22
  methods.each do |method|
23
+ Micron.runner.report(:start_method, method)
23
24
  method.run
24
25
  Micron.runner.report(:end_method, method)
25
26
  end
@@ -28,12 +29,33 @@ module Micron
28
29
 
29
30
  private
30
31
 
31
- def test_methods
32
- create.public_methods.find_all { |m|
32
+ # Get all test methods in the TestCase, optionally matching the given
33
+ # patterns
34
+ #
35
+ # @param [Array<String>] patterns list of patterns to filter by
36
+ #
37
+ # @return [Array<Symbol>] methods
38
+ def test_methods(patterns=[])
39
+ return @test_methods if !@test_methods.nil?
40
+
41
+ @test_methods = create.public_methods.find_all { |m|
33
42
  m.to_s =~ /^test_/
34
43
  }
44
+
45
+ if !(patterns.nil? or patterns.empty?) then
46
+ # filter
47
+ @test_methods.reject!{ |m|
48
+ patterns.find{ |t| m.to_s.include?(t.to_s) }.nil?
49
+ }
50
+ end
51
+
52
+ @test_methods
35
53
  end
36
54
 
55
+ # Convert the @name to a Constant
56
+ #
57
+ # Ruby 2.0+ correctly handles module namespaces while older versions do
58
+ # not. See clazz19.rb for the workaround (included at bottom).
37
59
  def name_to_const
38
60
  Module.const_get(name)
39
61
  end
@@ -163,6 +163,9 @@ module Micron
163
163
  # Cleanup all FDs inherited from the parent. We don't need them and we
164
164
  # may throw errors if they are left open. 8192 should be high enough.
165
165
  def clean_parent_file_descriptors
166
+ ObjectSpace.each_object(File) {|f| f.close unless f.closed? rescue nil}
167
+ return
168
+
166
169
  # Don't clean $stdin, $stdout, $stderr (0-2) or our own pipes
167
170
  keep = [ @child_write.to_i, @out.last.to_i, @err.last.to_i ]
168
171
  keep += @liveness_checker.fds if @liveness_checker
@@ -39,13 +39,18 @@ module Micron
39
39
 
40
40
  time(:setup) { setup(t) }
41
41
 
42
- time(:runtime) { t.send(name) }
42
+ # run actual test method and measure runtime
43
+ @runtime = Hitimes::Interval.now
44
+ t.send(name)
45
+ @durations[:runtime] = @runtime.stop
43
46
  self.passed = true
44
47
 
45
48
  rescue *PASSTHROUGH_EXCEPTIONS
49
+ @durations[:runtime] = @runtime.stop if @runtime
46
50
  raise
47
51
 
48
52
  rescue Exception => e
53
+ @durations[:runtime] = @runtime.stop if @runtime
49
54
  self.passed = false
50
55
  self.ex = ExceptionInfo.new(e)
51
56
 
@@ -54,6 +59,7 @@ module Micron
54
59
  time(:teardown) {
55
60
  teardown(t) if not t.nil?
56
61
  }
62
+ @runtime = nil
57
63
  end
58
64
  end
59
65
 
@@ -14,6 +14,7 @@ module Micron
14
14
  tests = []
15
15
  debug "spawning #{methods.size} methods"
16
16
  methods.each do |method|
17
+ Micron.runner.report(:start_method, method) # TODO not sure about this
17
18
  tests << spawn_test(method)
18
19
  end
19
20
 
@@ -14,7 +14,7 @@ module Micron
14
14
 
15
15
  if ENV["BUNDLE_GEMFILE"] then
16
16
  require "bundler"
17
- Bundler.setup(:default, :development)
17
+ Bundler.setup(:default, :development, :test)
18
18
  end
19
19
 
20
20
  require "easycov"
@@ -3,8 +3,9 @@ module Micron
3
3
  class Runner
4
4
  class TestFile
5
5
 
6
- def initialize(filename)
7
- @filename = filename
6
+ def initialize(filename, method_patterns)
7
+ @filename = filename
8
+ @method_patterns = method_patterns
8
9
  end
9
10
 
10
11
  # Load the test file
@@ -40,14 +41,30 @@ module Micron
40
41
  results = []
41
42
  test_clazz = TestCase.subclasses.last
42
43
 
44
+ # run before_class
43
45
  begin
44
- clazz = run_clazz.new(test_clazz, @filename)
46
+ test_clazz.before_class
47
+ rescue Exception => ex
48
+ # skip rest of class on error
49
+ return skip_all_tests(test_clazz, ex)
50
+ end
51
+
52
+ begin
53
+ clazz = run_clazz.new(test_clazz, @filename, @method_patterns)
45
54
 
46
55
  Micron.runner.report(:start_class, clazz)
47
56
  if !clazz.methods.empty? then
48
57
  clazz.run
49
58
  results << clazz
50
59
  end
60
+
61
+ # run after_class
62
+ begin
63
+ test_clazz.after_class
64
+ rescue Exception => ex
65
+ Micron.runner.report(:after_class_error, ex)
66
+ end
67
+
51
68
  Micron.runner.report(:end_class, clazz)
52
69
 
53
70
  rescue Exception => ex
@@ -74,6 +91,31 @@ module Micron
74
91
  return method
75
92
  end
76
93
 
94
+
95
+ private
96
+
97
+ # Mark all tests as skipped due to some error
98
+ def skip_all_tests(test_clazz, ex)
99
+ results = []
100
+ clazz = Clazz.new(test_clazz, @filename, @method_patterns)
101
+
102
+ Micron.runner.report(:start_class, clazz)
103
+ Micron.runner.report(:before_class_error, ex)
104
+
105
+ if !clazz.methods.empty? then
106
+ clazz.methods.each do |method|
107
+ Micron.runner.report(:start_method, method)
108
+ method.ex = Micron::Skip.new("before_class failed")
109
+ Micron.runner.report(:end_method, method)
110
+ end
111
+ results << clazz
112
+ end
113
+
114
+ Micron.runner.report(:end_class, clazz)
115
+
116
+ results
117
+ end
118
+
77
119
  end # TestFile
78
120
  end # Runner
79
121
  end # Micron
@@ -9,13 +9,22 @@ module Micron
9
9
  include LifecycleHooks
10
10
  include Assertions
11
11
 
12
+ # Run before all test methods in the class
13
+ def self.before_class
14
+ end
15
+
16
+ # Run after all test methods in the class
17
+ def self.after_class
18
+ end
19
+
20
+ # Run before each test method
12
21
  def setup
13
22
  end
14
23
 
24
+ # Run after each test method
15
25
  def teardown
16
26
  end
17
27
 
18
-
19
28
  # retrieve all loaded subclasses of this class
20
29
  #
21
30
  # @return [Array<Class>] List of subclasses
@@ -2,17 +2,7 @@
2
2
  module Micron
3
3
  class TestCase
4
4
  module LifecycleHooks
5
- ##
6
- # Runs before every test, after setup. This hook is meant for
7
- # libraries to extend minitest. It is not meant to be used by
8
- # test developers.
9
- #
10
- # See #before_setup for an example.
11
5
 
12
- def after_setup
13
- end
14
-
15
- ##
16
6
  # Runs before every test, before setup. This hook is meant for
17
7
  # libraries to extend minitest. It is not meant to be used by
18
8
  # test developers.
@@ -44,27 +34,30 @@ module Micron
44
34
  # class MiniTest::Unit::TestCase
45
35
  # include MyMinitestPlugin
46
36
  # end
47
-
48
37
  def before_setup
49
38
  end
50
39
 
51
- ##
52
- # Runs after every test, before teardown. This hook is meant for
40
+ # Runs before every test, after setup. This hook is meant for
53
41
  # libraries to extend minitest. It is not meant to be used by
54
42
  # test developers.
55
43
  #
56
44
  # See #before_setup for an example.
45
+ def after_setup
46
+ end
57
47
 
48
+ # Runs after every test, before teardown. This hook is meant for
49
+ # libraries to extend minitest. It is not meant to be used by
50
+ # test developers.
51
+ #
52
+ # See #before_setup for an example.
58
53
  def before_teardown
59
54
  end
60
55
 
61
- ##
62
56
  # Runs after every test, after teardown. This hook is meant for
63
57
  # libraries to extend minitest. It is not meant to be used by
64
58
  # test developers.
65
59
  #
66
60
  # See #before_setup for an example.
67
-
68
61
  def after_teardown
69
62
  end
70
63
 
@@ -1,6 +1,23 @@
1
1
 
2
2
  require "logging"
3
3
 
4
+ # Helper for redirecting 'logging' messages to STDOUT when running tests
5
+ #
6
+ # You can redirect all logs (root logger) with the following:
7
+ #
8
+ # class TestCase < ActiveSupport::TestCase
9
+ # include Micron::TestCase::RedirLogging
10
+ # self.redir_logger = Logging.logger.root
11
+ # end
12
+ #
13
+ # Or only a specific hierarchy like so:
14
+ #
15
+ # class TestCase < ActiveSupport::TestCase
16
+ # include Micron::TestCase::RedirLogging
17
+ # self.redir_logger = Logging.logger[Bixby]
18
+ # end
19
+ #
20
+
4
21
  module Micron
5
22
  class TestCase
6
23
  module RedirLogging
@@ -41,7 +58,10 @@ module Micron
41
58
  end
42
59
 
43
60
  module ClassMethods
44
- attr_writer :redir_logger
61
+
62
+ def redir_logger=(logger)
63
+ @redir_logger = logger
64
+ end
45
65
 
46
66
  # Search up the TestCase hierarchy for a redir_logger
47
67
  def redir_logger
@@ -2,15 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: micron 0.5.0 ruby lib
5
+ # stub: micron 0.5.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "micron"
9
- s.version = "0.5.0"
9
+ s.version = "0.5.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
12
13
  s.authors = ["Chetan Sarva"]
13
- s.date = "2013-10-14"
14
+ s.date = "2014-04-22"
14
15
  s.description = "An extremely minimal unit test library for Ruby"
15
16
  s.email = "chetan@pixelcop.net"
16
17
  s.executables = ["micron"]
@@ -24,6 +25,8 @@ Gem::Specification.new do |s|
24
25
  "lib/micron/app.rb",
25
26
  "lib/micron/app/options.rb",
26
27
  "lib/micron/assertion.rb",
28
+ "lib/micron/compat/minitest47.rb",
29
+ "lib/micron/compat/minitest5.rb",
27
30
  "lib/micron/fork_runner.rb",
28
31
  "lib/micron/minitest.rb",
29
32
  "lib/micron/proc_runner.rb",
@@ -60,8 +63,7 @@ Gem::Specification.new do |s|
60
63
  ]
61
64
  s.homepage = "http://github.com/chetan/micron"
62
65
  s.licenses = ["MIT"]
63
- s.require_paths = ["lib"]
64
- s.rubygems_version = "2.1.5"
66
+ s.rubygems_version = "2.2.2"
65
67
  s.summary = "Minimal unit tests for Ruby"
66
68
 
67
69
  if s.respond_to? :specification_version then
@@ -70,28 +72,25 @@ Gem::Specification.new do |s|
70
72
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
71
73
  s.add_runtime_dependency(%q<easycov>, [">= 0"])
72
74
  s.add_runtime_dependency(%q<hitimes>, [">= 0"])
73
- s.add_runtime_dependency(%q<colorize>, [">= 0"])
75
+ s.add_runtime_dependency(%q<ansi>, [">= 0"])
74
76
  s.add_development_dependency(%q<yard>, ["~> 0.8"])
75
77
  s.add_development_dependency(%q<bundler>, ["~> 1.1"])
76
78
  s.add_development_dependency(%q<jeweler>, [">= 0"])
77
- s.add_development_dependency(%q<minitest>, ["~> 4.0"])
78
79
  else
79
80
  s.add_dependency(%q<easycov>, [">= 0"])
80
81
  s.add_dependency(%q<hitimes>, [">= 0"])
81
- s.add_dependency(%q<colorize>, [">= 0"])
82
+ s.add_dependency(%q<ansi>, [">= 0"])
82
83
  s.add_dependency(%q<yard>, ["~> 0.8"])
83
84
  s.add_dependency(%q<bundler>, ["~> 1.1"])
84
85
  s.add_dependency(%q<jeweler>, [">= 0"])
85
- s.add_dependency(%q<minitest>, ["~> 4.0"])
86
86
  end
87
87
  else
88
88
  s.add_dependency(%q<easycov>, [">= 0"])
89
89
  s.add_dependency(%q<hitimes>, [">= 0"])
90
- s.add_dependency(%q<colorize>, [">= 0"])
90
+ s.add_dependency(%q<ansi>, [">= 0"])
91
91
  s.add_dependency(%q<yard>, ["~> 0.8"])
92
92
  s.add_dependency(%q<bundler>, ["~> 1.1"])
93
93
  s.add_dependency(%q<jeweler>, [">= 0"])
94
- s.add_dependency(%q<minitest>, ["~> 4.0"])
95
94
  end
96
95
  end
97
96
 
metadata CHANGED
@@ -1,113 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chetan Sarva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-14 00:00:00.000000000 Z
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: easycov
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hitimes
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: colorize
42
+ name: ansi
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.8'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: jeweler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: minitest
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: '4.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: '4.0'
111
97
  description: An extremely minimal unit test library for Ruby
112
98
  email: chetan@pixelcop.net
113
99
  executables:
@@ -124,6 +110,8 @@ files:
124
110
  - lib/micron/app.rb
125
111
  - lib/micron/app/options.rb
126
112
  - lib/micron/assertion.rb
113
+ - lib/micron/compat/minitest47.rb
114
+ - lib/micron/compat/minitest5.rb
127
115
  - lib/micron/fork_runner.rb
128
116
  - lib/micron/minitest.rb
129
117
  - lib/micron/proc_runner.rb
@@ -167,17 +155,17 @@ require_paths:
167
155
  - lib
168
156
  required_ruby_version: !ruby/object:Gem::Requirement
169
157
  requirements:
170
- - - '>='
158
+ - - ">="
171
159
  - !ruby/object:Gem::Version
172
160
  version: '0'
173
161
  required_rubygems_version: !ruby/object:Gem::Requirement
174
162
  requirements:
175
- - - '>='
163
+ - - ">="
176
164
  - !ruby/object:Gem::Version
177
165
  version: '0'
178
166
  requirements: []
179
167
  rubyforge_project:
180
- rubygems_version: 2.1.5
168
+ rubygems_version: 2.2.2
181
169
  signing_key:
182
170
  specification_version: 4
183
171
  summary: Minimal unit tests for Ruby