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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29d7b92b84fd3c8da1f0d4c41f008153d8074f69
4
+ data.tar.gz: f76f16a5f3b5e8dbee5ee3b00a7624b72b8fb199
5
+ SHA512:
6
+ metadata.gz: e10e61aee8e0677d2b4bcecc29c4714b909164821ac630d9e54cc80041c49e87dc78332f39b48b6d77a0dcf9579f80bd081061dc0276d8f9022dd21ba27af5de
7
+ data.tar.gz: 4bc4917b3ddb759ccb2f5dde09b7898ac5bf788c310554a3e0335eba6e237c6c4fd986876baada9d0e5295e78bc9c762f4832069fa16033fdb5bbb20469310dd
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :local do
4
+ gem "micron", :path => "."
5
+ end
6
+
7
+ gem "easycov", :github => "chetan/easycov"
8
+
9
+ gem "hitimes"
10
+ gem "colorize"
11
+
12
+ group :development do
13
+ gem "yard", "~> 0.8"
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]
18
+ end
19
+
@@ -0,0 +1,88 @@
1
+ GIT
2
+ remote: git://github.com/chetan/easycov.git
3
+ revision: 58be40eddda14fb8db4f1b72427922e8054bae7a
4
+ specs:
5
+ easycov (0.1.1)
6
+ multi_json
7
+ simplecov
8
+
9
+ GIT
10
+ remote: https://github.com/chetan/jeweler.git
11
+ revision: c83ba18b074e82415052e80499a770bff87bf944
12
+ branch: bixby
13
+ specs:
14
+ jeweler (1.8.7)
15
+ builder
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ github_api (= 0.10.1)
19
+ highline (>= 1.6.15)
20
+ nokogiri (= 1.5.10)
21
+ rake
22
+ rdoc
23
+
24
+ PATH
25
+ remote: .
26
+ specs:
27
+ micron (0.5.0)
28
+ colorize
29
+ easycov
30
+ hitimes
31
+
32
+ GEM
33
+ remote: https://rubygems.org/
34
+ specs:
35
+ addressable (2.3.5)
36
+ builder (3.2.2)
37
+ colorize (0.6.0)
38
+ faraday (0.8.8)
39
+ multipart-post (~> 1.2.0)
40
+ git (1.2.6)
41
+ github_api (0.10.1)
42
+ addressable
43
+ faraday (~> 0.8.1)
44
+ hashie (>= 1.2)
45
+ multi_json (~> 1.4)
46
+ nokogiri (~> 1.5.2)
47
+ oauth2
48
+ hashie (2.0.5)
49
+ highline (1.6.19)
50
+ hitimes (1.2.1)
51
+ httpauth (0.2.0)
52
+ json (1.8.0)
53
+ jwt (0.1.8)
54
+ multi_json (>= 1.5)
55
+ minitest (4.7.5)
56
+ multi_json (1.8.0)
57
+ 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
+ multi_xml (~> 0.5)
66
+ rack (~> 1.2)
67
+ rack (1.5.2)
68
+ rake (10.1.0)
69
+ rdoc (4.0.1)
70
+ 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)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ bundler (~> 1.1)
82
+ colorize
83
+ easycov!
84
+ hitimes
85
+ jeweler!
86
+ micron!
87
+ minitest (~> 4.0)
88
+ yard (~> 0.8)
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+ require 'jeweler'
14
+
15
+ Jeweler::Tasks.new do |gemspec|
16
+ gemspec.name = "micron"
17
+ gemspec.summary = "Minimal unit tests for Ruby"
18
+ gemspec.description = "An extremely minimal unit test library for Ruby"
19
+ gemspec.email = "chetan@pixelcop.net"
20
+ gemspec.homepage = "http://github.com/chetan/micron"
21
+ gemspec.authors = ["Chetan Sarva"]
22
+ gemspec.license = "MIT"
23
+ gemspec.executables = ["micron"]
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'yard'
39
+ YARD::Rake::YardocTask.new
40
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "micron/app"
4
+ Micron::App.new.run
@@ -0,0 +1,29 @@
1
+
2
+ require "easycov"
3
+
4
+ require "micron/util/io"
5
+ require "micron/util/thread_dump"
6
+ require "micron/util/ex"
7
+
8
+ require "micron/assertion"
9
+ require "micron/test_case"
10
+ require "micron/runner"
11
+
12
+ module Micron
13
+
14
+ extend Micron::Util::IO
15
+ extend Micron::Util::ThreadDump
16
+ extend Micron::Util::Ex
17
+
18
+ class << self
19
+
20
+ attr_accessor :backtrace_filter, :runner
21
+
22
+ def filter_backtrace(bt)
23
+ backtrace_filter.call(bt)
24
+ end
25
+
26
+ end # self
27
+ self.backtrace_filter = BacktraceFilter.new # default filter
28
+
29
+ end
@@ -0,0 +1,127 @@
1
+
2
+ require "micron"
3
+ require "micron/app/options"
4
+
5
+ require "fileutils"
6
+
7
+ module Micron
8
+ class App
9
+
10
+ def run(options=nil)
11
+ $0 = "micron: runner"
12
+ Thread.current[:name] = "main thread"
13
+
14
+ STDOUT.sync = true
15
+ STDERR.sync = true
16
+ Micron.trap_thread_dump()
17
+ Micron::Runner::Shim.setup
18
+
19
+ options = Options.parse(options)
20
+
21
+ ENV["PARALLEL_EASYCOV"] = "1"
22
+ if !options[:coverage] then
23
+ ENV["DISABLE_EASYCOV"] = "1"
24
+ end
25
+
26
+ # Setup paths
27
+ # TODO allow setting path/root some other way
28
+ path = options.delete(:path)
29
+ path = File.expand_path(Dir.pwd)
30
+ ENV["MICRON_PATH"] = File.join(path, ".micron")
31
+ FileUtils.mkdir_p(ENV["MICRON_PATH"])
32
+
33
+ test_paths = []
34
+ %w{test .test}.each do |t|
35
+ t = File.join(path, t)
36
+ if File.directory?(t) then
37
+ $: << t
38
+ test_paths << t
39
+ end
40
+ end
41
+
42
+ # Setup reporters
43
+ reporters = []
44
+ reporters << Reporter::Console.new
45
+
46
+ # Spawn child runner if called
47
+ if options[:runclass] then
48
+ require "micron/proc_runner"
49
+ Micron.runner = Micron::ProcRunner.new(nil, reporters)
50
+ Micron.runner.run_class
51
+ exit
52
+ elsif options[:runmethod] then
53
+ require "micron/proc_runner"
54
+ Micron.runner = Micron::ProcRunner.new(nil, reporters)
55
+ Micron.runner.run_method
56
+ exit
57
+ end
58
+
59
+ # Add coverage reporter
60
+ if options[:coverage] then
61
+ reporters.unshift Reporter::Coverage.new
62
+ end
63
+
64
+ # Find tests to run
65
+ files = []
66
+ if not ARGV.empty? then
67
+ ARGV.each do |f|
68
+ if File.file? f then
69
+ files << File.expand_path(f)
70
+ elsif File.directory? f then
71
+ files += find_tests(File.expand_path(f))
72
+ end
73
+ end
74
+ end
75
+ files.flatten!
76
+
77
+ if files.empty? then
78
+ files = []
79
+ test_paths.each{ |t| files += find_tests(t) }
80
+ end
81
+
82
+ files.sort!
83
+
84
+ # Run tests
85
+ if options[:proc] then
86
+ require "micron/proc_runner"
87
+ Micron.runner = Micron::ProcRunner.new(files, reporters)
88
+ elsif options[:fork] then
89
+ require "micron/fork_runner"
90
+ Micron.runner = Micron::ForkRunner.new(files, reporters)
91
+ else
92
+ Micron.runner = Micron::Runner.new(files, reporters)
93
+ end
94
+ results = Micron.runner.run
95
+
96
+ Micron::Runner::Shim.cleanup!
97
+
98
+ exit(count_failures(results) > 0 ? 1 : 0)
99
+ end
100
+
101
+
102
+ private
103
+
104
+ def find_tests(path)
105
+ Dir.glob(File.join(path, "**/*.rb")).find_all { |f|
106
+ f = File.basename(f)
107
+ f =~ /^(test_.*|.*_test)\.rb$/
108
+ }
109
+ end
110
+
111
+ # Count the number of failures in the list of results
112
+ #
113
+ # @param [Array<Clazz>] results
114
+ #
115
+ # @return [Fixnum]
116
+ def count_failures(results)
117
+ fail = 0
118
+ results.each { |c|
119
+ c.methods.each { |m|
120
+ fail += 1 if !m.skipped? && !m.passed?
121
+ }
122
+ }
123
+ return fail
124
+ end
125
+
126
+ end
127
+ end
@@ -0,0 +1,73 @@
1
+
2
+ require 'optparse'
3
+
4
+ module Micron
5
+ class App
6
+ class Options
7
+
8
+ DEFAULTS = {
9
+ :coverage => true
10
+ }
11
+
12
+ def self.parse(options=nil)
13
+
14
+ # always try to use default options first
15
+ if options then
16
+ options = DEFAULTS.merge(options)
17
+ else
18
+ options = DEFAULTS.dup
19
+ end
20
+
21
+ # then rc file
22
+ rc = File.join(Dir.pwd, ".micronrc")
23
+ if File.exists? rc then
24
+ parse_opts(options, File.read(rc).split(" "))
25
+ end
26
+
27
+ # then anything on command line
28
+ parse_opts(options, ARGV)
29
+
30
+ return options
31
+ end
32
+
33
+ def self.parse_opts(options, argv)
34
+ parser = OptionParser.new do |opts|
35
+ opts.banner = "usage: #{$0} [options]"
36
+
37
+ opts.on("--nocov", "Disable coverage reporting") {
38
+ options[:coverage] = false
39
+ }
40
+
41
+ opts.on("--proc", "Use the process runner") {
42
+ options[:proc] = true
43
+ }
44
+
45
+ opts.on("--fork", "Use the forking runner") {
46
+ options[:fork] = true
47
+ }
48
+
49
+ opts.on("--runclass", "Run class in child process") {
50
+ options[:runclass] = true
51
+ }
52
+
53
+ opts.on("--runmethod", "Run method in child process") {
54
+ options[:runmethod] = true
55
+ }
56
+ end
57
+
58
+ begin
59
+ parser.parse!(argv)
60
+
61
+ rescue Exception => ex
62
+ exit if ex.kind_of? SystemExit
63
+ STDERR.puts "error: #{ex}"
64
+ STDERR.puts
65
+ STDERR.puts parser
66
+ exit 1
67
+ end
68
+
69
+ return options
70
+ end # self.parse_opts
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module Micron
3
+
4
+ class Assertion < Exception
5
+ end
6
+
7
+ class Skip < Assertion
8
+ end
9
+
10
+ end
@@ -0,0 +1,55 @@
1
+
2
+ require "micron/runner/parallel_clazz"
3
+ require "micron/runner/fork_worker"
4
+ require "micron/runner/forking_clazz"
5
+ require "micron/test_case/teardown_coverage"
6
+
7
+ module Micron
8
+ class ForkRunner < Runner
9
+
10
+ def run
11
+ report(:start_tests, @files)
12
+
13
+ @files.each do |file|
14
+
15
+ # fork for each file
16
+ worker = ForkWorker.new(nil, false) {
17
+ $0 = "micron: class"
18
+ # ERR.puts "micron: class (#{$$})"
19
+
20
+ test_file = TestFile.new(file)
21
+ report(:start_file, test_file)
22
+
23
+ begin
24
+ test_file.collect_coverage()
25
+ test_file.load()
26
+ results = test_file.run(ForkingClazz)
27
+ rescue Exception => ex
28
+ results = [ex]
29
+ end
30
+
31
+ results
32
+ }.run
33
+
34
+ results = worker.wait.result
35
+ results.each do |clazz|
36
+ if clazz.kind_of? Exception then
37
+ puts "Error loading test file: #{file}"
38
+ puts clazz
39
+ puts clazz.backtrace
40
+ exit 1
41
+ end
42
+
43
+ # should be a Clazz
44
+ @results << clazz
45
+ end
46
+
47
+ end
48
+
49
+ report(:end_tests, @files, @results)
50
+
51
+ return @results
52
+ end
53
+
54
+ end # ForkRunner
55
+ end # Micron