Class: Micron::App
- Inherits:
-
Object
- Object
- Micron::App
- Defined in:
- lib/micron/app.rb,
lib/micron/app/options.rb
Defined Under Namespace
Classes: Options
Instance Method Summary collapse
Instance Method Details
#run(options = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/micron/app.rb', line 10 def run(=nil) $0 = "micron: runner" Thread.current[:name] = "main thread" STDOUT.sync = true STDERR.sync = true Micron.trap_thread_dump() Micron::Runner::Shim.setup = Options.parse() ENV["PARALLEL_EASYCOV"] = "1" if ![:coverage] then ENV["DISABLE_EASYCOV"] = "1" end # Setup paths # TODO allow setting path/root some other way path = .delete(:path) path = File.(Dir.pwd) ENV["MICRON_PATH"] = File.join(path, ".micron") FileUtils.mkdir_p(ENV["MICRON_PATH"]) test_paths = [] %w{test .test}.each do |t| t = File.join(path, t) if File.directory?(t) then $: << t test_paths << t end end # Setup reporters reporters = [] reporters << Reporter::Console.new # Spawn child runner if called if [:runclass] then require "micron/proc_runner" methods = ENV["MICRON_METHODS"].split(/:/) Micron.runner = Micron::ProcRunner.new(nil, methods, reporters) Micron.runner.run_class exit elsif [:runmethod] then require "micron/proc_runner" Micron.runner = Micron::ProcRunner.new(nil, nil, reporters) Micron.runner.run_method exit end # Add coverage reporter if [:coverage] then reporters.unshift Reporter::Coverage.new end # Find tests to run files = [] if not ARGV.empty? then ARGV.each do |f| if File.file? f then files << File.(f) elsif File.directory? f then files += find_tests(File.(f)) end end end files.flatten! if files.empty? then files = [] test_paths.each{ |t| files += find_tests(t) } end files.sort! # Optionally filter files if [:tests] and ![:tests].empty? then files.reject!{ |f| [:tests].find{ |t| f.include?(t) }.nil? } end # Run tests if [:proc] then require "micron/proc_runner" runner = Micron::ProcRunner elsif [:fork] then require "micron/fork_runner" runner = Micron::ForkRunner else runner = Micron::Runner end Micron.runner = runner.new(files, [:methods], reporters) results = Micron.runner.run Micron::Runner::Shim.cleanup! # set a non-zero exit code if we had any failures exit(count_failures(results) > 0 ? 1 : 0) end |