micron 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +19 -0
  3. data/Gemfile.lock +88 -0
  4. data/Rakefile +40 -0
  5. data/VERSION +1 -0
  6. data/bin/micron +4 -0
  7. data/lib/micron.rb +29 -0
  8. data/lib/micron/app.rb +127 -0
  9. data/lib/micron/app/options.rb +73 -0
  10. data/lib/micron/assertion.rb +10 -0
  11. data/lib/micron/fork_runner.rb +55 -0
  12. data/lib/micron/minitest.rb +45 -0
  13. data/lib/micron/proc_runner.rb +114 -0
  14. data/lib/micron/rake.rb +29 -0
  15. data/lib/micron/reporter.rb +30 -0
  16. data/lib/micron/reporter/console.rb +146 -0
  17. data/lib/micron/reporter/coverage.rb +37 -0
  18. data/lib/micron/runner.rb +95 -0
  19. data/lib/micron/runner/backtrace_filter.rb +39 -0
  20. data/lib/micron/runner/clazz.rb +45 -0
  21. data/lib/micron/runner/clazz19.rb +24 -0
  22. data/lib/micron/runner/debug.rb +22 -0
  23. data/lib/micron/runner/exception_info.rb +16 -0
  24. data/lib/micron/runner/fork_worker.rb +185 -0
  25. data/lib/micron/runner/forking_clazz.rb +40 -0
  26. data/lib/micron/runner/liveness_checker.rb +40 -0
  27. data/lib/micron/runner/liveness_checker/ping.rb +65 -0
  28. data/lib/micron/runner/liveness_checker/pong.rb +36 -0
  29. data/lib/micron/runner/method.rb +124 -0
  30. data/lib/micron/runner/parallel_clazz.rb +135 -0
  31. data/lib/micron/runner/proc_clazz.rb +48 -0
  32. data/lib/micron/runner/process_reaper.rb +98 -0
  33. data/lib/micron/runner/shim.rb +68 -0
  34. data/lib/micron/runner/test_file.rb +79 -0
  35. data/lib/micron/test_case.rb +36 -0
  36. data/lib/micron/test_case/assertions.rb +701 -0
  37. data/lib/micron/test_case/lifecycle_hooks.rb +74 -0
  38. data/lib/micron/test_case/redir_logging.rb +85 -0
  39. data/lib/micron/test_case/teardown_coverage.rb +13 -0
  40. data/lib/micron/util/ex.rb +23 -0
  41. data/lib/micron/util/io.rb +54 -0
  42. data/lib/micron/util/thread_dump.rb +29 -0
  43. data/micron.gemspec +97 -0
  44. metadata +184 -0
@@ -0,0 +1,74 @@
1
+
2
+ module Micron
3
+ class TestCase
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
+
12
+ def after_setup
13
+ end
14
+
15
+ ##
16
+ # Runs before every test, before setup. This hook is meant for
17
+ # libraries to extend minitest. It is not meant to be used by
18
+ # test developers.
19
+ #
20
+ # As a simplistic example:
21
+ #
22
+ # module MyMinitestPlugin
23
+ # def before_setup
24
+ # super
25
+ # # ... stuff to do before setup is run
26
+ # end
27
+ #
28
+ # def after_setup
29
+ # # ... stuff to do after setup is run
30
+ # super
31
+ # end
32
+ #
33
+ # def before_teardown
34
+ # super
35
+ # # ... stuff to do before teardown is run
36
+ # end
37
+ #
38
+ # def after_teardown
39
+ # # ... stuff to do after teardown is run
40
+ # super
41
+ # end
42
+ # end
43
+ #
44
+ # class MiniTest::Unit::TestCase
45
+ # include MyMinitestPlugin
46
+ # end
47
+
48
+ def before_setup
49
+ end
50
+
51
+ ##
52
+ # Runs after every test, before teardown. This hook is meant for
53
+ # libraries to extend minitest. It is not meant to be used by
54
+ # test developers.
55
+ #
56
+ # See #before_setup for an example.
57
+
58
+ def before_teardown
59
+ end
60
+
61
+ ##
62
+ # Runs after every test, after teardown. This hook is meant for
63
+ # libraries to extend minitest. It is not meant to be used by
64
+ # test developers.
65
+ #
66
+ # See #before_setup for an example.
67
+
68
+ def after_teardown
69
+ end
70
+
71
+ end # LifecycleHooks
72
+
73
+ end # TestCase
74
+ end # Micron
@@ -0,0 +1,85 @@
1
+
2
+ require "logging"
3
+
4
+ module Micron
5
+ class TestCase
6
+ module RedirLogging
7
+
8
+ # Send logging to stdout for duration of test
9
+ def before_setup
10
+ super
11
+ logger = self.class.redir_logger
12
+ return if logger.nil?
13
+
14
+ @_old_log_appenders = logger.appenders
15
+ @_old_log_additive = logger.additive
16
+ @_old_log_level = logger.level
17
+
18
+ logger.clear_appenders
19
+ logger.additive = false
20
+ logger.level = :debug
21
+
22
+ # add original appenders which do not point to stdout, and our custom
23
+ # $stdout appender
24
+ logger.add_appenders(@_old_log_appenders.reject{ |a| a.kind_of? Logging::Appenders::Stdout })
25
+ logger.add_appenders("stdout_test")
26
+ end
27
+
28
+ # Restore appenders
29
+ def after_teardown
30
+ super
31
+ logger = self.class.redir_logger
32
+ return if logger.nil?
33
+ logger.clear_appenders
34
+ logger.add_appenders(@_old_log_appenders)
35
+ logger.additive = @_old_log_additive
36
+ logger.level = @_old_log_level
37
+ end
38
+
39
+ def self.included(receiver)
40
+ receiver.extend(ClassMethods)
41
+ end
42
+
43
+ module ClassMethods
44
+ attr_writer :redir_logger
45
+
46
+ # Search up the TestCase hierarchy for a redir_logger
47
+ def redir_logger
48
+ return @redir_logger if !@redir_logger.nil?
49
+ return superclass.redir_logger if superclass.respond_to? :redir_logger
50
+ nil
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+
58
+ # A simple subclass of the Stdout appender which writes to whatever
59
+ # $stdout is currently pointing to
60
+ module Logging::Appenders
61
+ class StdoutTest < Stdout
62
+ def canonical_write( str )
63
+ return self if @io.nil?
64
+ str = str.force_encoding(encoding) if encoding and str.encoding != encoding
65
+ # STDOUT.puts "writing log to $stdout: #{str}"
66
+ # STDOUT.puts "$stdout is currently #{$stdout.inspect}"
67
+ $stdout.syswrite str
68
+ self
69
+ rescue StandardError => err
70
+ self.level = :off
71
+ ::Logging.log_internal {"appender #{name.inspect} has been disabled"}
72
+ ::Logging.log_internal(-2) {err}
73
+ end
74
+ end
75
+ end
76
+
77
+ # Configure test appender
78
+ Logging::Appenders::StdoutTest.new( 'stdout_test',
79
+ :auto_flushing => true,
80
+ :layout => Logging.layouts.pattern(
81
+ :pattern => '%.1l, [%d] %5l -- %c: %m\n',
82
+ :color_scheme => 'bright'
83
+ )
84
+ )
85
+
@@ -0,0 +1,13 @@
1
+
2
+ module Micron
3
+ class TestCase
4
+
5
+ module TeardownCoverage
6
+ def before_teardown
7
+ super
8
+ EasyCov.checkpoint
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module Micron
3
+ module Util
4
+ module Ex
5
+
6
+ # Utility method for converting Exceptions to Strings
7
+ #
8
+ # @param [Exception] ex
9
+ # @param [Boolean] include_backtrace
10
+ #
11
+ # @return [String]
12
+ def dump_ex(ex, include_backtrace=false)
13
+ name = ex.respond_to?(:name) ? ex.name : ex.class.to_s
14
+ s = "<#{name}> #{ex.message}"
15
+ if include_backtrace then
16
+ s += "\n " + filter_backtrace(ex.backtrace).join("\n ")
17
+ end
18
+ return s
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+
2
+ module Micron
3
+ module Util
4
+ module IO
5
+
6
+ # Captures $stdout and $stderr into strings:
7
+ #
8
+ # out, err = capture_io do
9
+ # puts "Some info"
10
+ # warn "You did a bad thing"
11
+ # end
12
+ #
13
+ # assert_match %r%info%, out
14
+ # assert_match %r%bad%, err
15
+ #
16
+ # NOTE: For efficiency, this method uses StringIO and does not
17
+ # capture IO for subprocesses. Use #capture_subprocess_io for
18
+ # that.
19
+ def capture_io
20
+ require 'stringio'
21
+
22
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
23
+
24
+ # synchronize do
25
+ orig_stdout, orig_stderr = $stdout, $stderr
26
+ $stdout, $stderr = captured_stdout, captured_stderr
27
+
28
+ begin
29
+ yield
30
+ ensure
31
+ $stdout = orig_stdout
32
+ $stderr = orig_stderr
33
+ end
34
+
35
+ # end
36
+
37
+ return captured_stdout.string, captured_stderr.string
38
+ end
39
+
40
+ # Dispose of STDOUT/STDERR
41
+ #
42
+ # @param [Array<IO>] out
43
+ # @param [Array<IO>] err
44
+ def dispose_io(out, err)
45
+ STDOUT.reopen out.last
46
+ out.last.close
47
+ STDERR.reopen err.last
48
+ err.last.close
49
+ STDOUT.sync = STDERR.sync = true
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module Micron
3
+ module Util
4
+ module ThreadDump
5
+
6
+ # Setup thread dump signal
7
+ def trap_thread_dump
8
+ # print a thread dump on SIGALRM
9
+ # kill -ALRM <pid>
10
+ Signal.trap 'SIGALRM' do
11
+ File.open(File.join(ENV["MICRON_PATH"], "#{$$}.threads.txt"), "w+") do |f|
12
+ f.puts
13
+ f.puts "=== micron thread dump: #{Time.now} ==="
14
+ f.puts
15
+ Thread.list.each do |thread|
16
+ f.puts "Thread-#{thread.object_id}" + (thread[:name] ? ": " + thread[:name] : "")
17
+ f.puts thread.backtrace.join("\n \\_ ")
18
+ f.puts "-"
19
+ f.puts
20
+ end
21
+ f.puts "=== end micron thread dump ==="
22
+ f.puts
23
+ end
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,97 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: micron 0.5.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "micron"
9
+ s.version = "0.5.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Chetan Sarva"]
13
+ s.date = "2013-10-14"
14
+ s.description = "An extremely minimal unit test library for Ruby"
15
+ s.email = "chetan@pixelcop.net"
16
+ s.executables = ["micron"]
17
+ s.files = [
18
+ "Gemfile",
19
+ "Gemfile.lock",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "bin/micron",
23
+ "lib/micron.rb",
24
+ "lib/micron/app.rb",
25
+ "lib/micron/app/options.rb",
26
+ "lib/micron/assertion.rb",
27
+ "lib/micron/fork_runner.rb",
28
+ "lib/micron/minitest.rb",
29
+ "lib/micron/proc_runner.rb",
30
+ "lib/micron/rake.rb",
31
+ "lib/micron/reporter.rb",
32
+ "lib/micron/reporter/console.rb",
33
+ "lib/micron/reporter/coverage.rb",
34
+ "lib/micron/runner.rb",
35
+ "lib/micron/runner/backtrace_filter.rb",
36
+ "lib/micron/runner/clazz.rb",
37
+ "lib/micron/runner/clazz19.rb",
38
+ "lib/micron/runner/debug.rb",
39
+ "lib/micron/runner/exception_info.rb",
40
+ "lib/micron/runner/fork_worker.rb",
41
+ "lib/micron/runner/forking_clazz.rb",
42
+ "lib/micron/runner/liveness_checker.rb",
43
+ "lib/micron/runner/liveness_checker/ping.rb",
44
+ "lib/micron/runner/liveness_checker/pong.rb",
45
+ "lib/micron/runner/method.rb",
46
+ "lib/micron/runner/parallel_clazz.rb",
47
+ "lib/micron/runner/proc_clazz.rb",
48
+ "lib/micron/runner/process_reaper.rb",
49
+ "lib/micron/runner/shim.rb",
50
+ "lib/micron/runner/test_file.rb",
51
+ "lib/micron/test_case.rb",
52
+ "lib/micron/test_case/assertions.rb",
53
+ "lib/micron/test_case/lifecycle_hooks.rb",
54
+ "lib/micron/test_case/redir_logging.rb",
55
+ "lib/micron/test_case/teardown_coverage.rb",
56
+ "lib/micron/util/ex.rb",
57
+ "lib/micron/util/io.rb",
58
+ "lib/micron/util/thread_dump.rb",
59
+ "micron.gemspec"
60
+ ]
61
+ s.homepage = "http://github.com/chetan/micron"
62
+ s.licenses = ["MIT"]
63
+ s.require_paths = ["lib"]
64
+ s.rubygems_version = "2.1.5"
65
+ s.summary = "Minimal unit tests for Ruby"
66
+
67
+ if s.respond_to? :specification_version then
68
+ s.specification_version = 4
69
+
70
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
71
+ s.add_runtime_dependency(%q<easycov>, [">= 0"])
72
+ s.add_runtime_dependency(%q<hitimes>, [">= 0"])
73
+ s.add_runtime_dependency(%q<colorize>, [">= 0"])
74
+ s.add_development_dependency(%q<yard>, ["~> 0.8"])
75
+ s.add_development_dependency(%q<bundler>, ["~> 1.1"])
76
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
77
+ s.add_development_dependency(%q<minitest>, ["~> 4.0"])
78
+ else
79
+ s.add_dependency(%q<easycov>, [">= 0"])
80
+ s.add_dependency(%q<hitimes>, [">= 0"])
81
+ s.add_dependency(%q<colorize>, [">= 0"])
82
+ s.add_dependency(%q<yard>, ["~> 0.8"])
83
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
84
+ s.add_dependency(%q<jeweler>, [">= 0"])
85
+ s.add_dependency(%q<minitest>, ["~> 4.0"])
86
+ end
87
+ else
88
+ s.add_dependency(%q<easycov>, [">= 0"])
89
+ s.add_dependency(%q<hitimes>, [">= 0"])
90
+ s.add_dependency(%q<colorize>, [">= 0"])
91
+ s.add_dependency(%q<yard>, ["~> 0.8"])
92
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
93
+ s.add_dependency(%q<jeweler>, [">= 0"])
94
+ s.add_dependency(%q<minitest>, ["~> 4.0"])
95
+ end
96
+ end
97
+
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Chetan Sarva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: easycov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hitimes
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
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
+ description: An extremely minimal unit test library for Ruby
112
+ email: chetan@pixelcop.net
113
+ executables:
114
+ - micron
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - Rakefile
121
+ - VERSION
122
+ - bin/micron
123
+ - lib/micron.rb
124
+ - lib/micron/app.rb
125
+ - lib/micron/app/options.rb
126
+ - lib/micron/assertion.rb
127
+ - lib/micron/fork_runner.rb
128
+ - lib/micron/minitest.rb
129
+ - lib/micron/proc_runner.rb
130
+ - lib/micron/rake.rb
131
+ - lib/micron/reporter.rb
132
+ - lib/micron/reporter/console.rb
133
+ - lib/micron/reporter/coverage.rb
134
+ - lib/micron/runner.rb
135
+ - lib/micron/runner/backtrace_filter.rb
136
+ - lib/micron/runner/clazz.rb
137
+ - lib/micron/runner/clazz19.rb
138
+ - lib/micron/runner/debug.rb
139
+ - lib/micron/runner/exception_info.rb
140
+ - lib/micron/runner/fork_worker.rb
141
+ - lib/micron/runner/forking_clazz.rb
142
+ - lib/micron/runner/liveness_checker.rb
143
+ - lib/micron/runner/liveness_checker/ping.rb
144
+ - lib/micron/runner/liveness_checker/pong.rb
145
+ - lib/micron/runner/method.rb
146
+ - lib/micron/runner/parallel_clazz.rb
147
+ - lib/micron/runner/proc_clazz.rb
148
+ - lib/micron/runner/process_reaper.rb
149
+ - lib/micron/runner/shim.rb
150
+ - lib/micron/runner/test_file.rb
151
+ - lib/micron/test_case.rb
152
+ - lib/micron/test_case/assertions.rb
153
+ - lib/micron/test_case/lifecycle_hooks.rb
154
+ - lib/micron/test_case/redir_logging.rb
155
+ - lib/micron/test_case/teardown_coverage.rb
156
+ - lib/micron/util/ex.rb
157
+ - lib/micron/util/io.rb
158
+ - lib/micron/util/thread_dump.rb
159
+ - micron.gemspec
160
+ homepage: http://github.com/chetan/micron
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.1.5
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Minimal unit tests for Ruby
184
+ test_files: []