|
| 1 | +module Minitest |
| 2 | + |
| 3 | + # Select report format. |
| 4 | + # |
| 5 | + # -T outline turn's original case/test outline mode |
| 6 | + # -T progress indicates progress with progress bar |
| 7 | + # -T dot test-unit's traditonal dot-progress mode |
| 8 | + # -T pretty new pretty output mode [default] |
| 9 | + # -T cue cue for action on each failure/error |
| 10 | + # -T marshal dump output as YAML (normal run mode only) |
| 11 | + # |
| 12 | + def self.plugin_turn_options(opts, options) |
| 13 | + unless $turn_command |
| 14 | + opts.on "-t", "--turn", "Use Turn for output." do |format| |
| 15 | + $turn_command = true |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + options[:loadpath] ||= [] |
| 20 | + options[:requires] ||= [] |
| 21 | + |
| 22 | + opts.separator " " |
| 23 | + opts.separator "turn options:" |
| 24 | + |
| 25 | + opts.on('-I', '--loadpath=PATHS', "add paths to $LOAD_PATH") do |path| |
| 26 | + options[:loadpath].concat(path.split(':')) |
| 27 | + end |
| 28 | + opts.on('-r', '--require=LIBS', "require libraries") do |lib| |
| 29 | + @options[:requires].concat(lib.split(':')) |
| 30 | + end |
| 31 | + #opts.on('-n', '--name=PATTERN', "only run tests that match PATTERN") do |pattern| |
| 32 | + # if pattern =~ /\/(.*)\// |
| 33 | + # options[:pattern] = Regexp.new($1) |
| 34 | + # else |
| 35 | + # options[:pattern] = Regexp.new(pattern, Regexp::IGNORECASE) |
| 36 | + # end |
| 37 | + #end |
| 38 | + #opts.on('-c', '--case=PATTERN', "only run test cases that match PATTERN") do |pattern| |
| 39 | + # if pattern =~ /\/(.*)\// |
| 40 | + # options[:matchcase] = Regexp.new($1) |
| 41 | + # else |
| 42 | + # options[:matchcase] = Regexp.new(pattern, Regexp::IGNORECASE) |
| 43 | + # end |
| 44 | + #end |
| 45 | + opts.on('-m', '--mark=SECONDS', "Mark test if it exceeds runtime threshold.") do |int| |
| 46 | + @options[:mark] = int.to_i |
| 47 | + end |
| 48 | + opts.on('-b', '--backtrace', '--trace INT', "Limit the number of lines of backtrace.") do |int| |
| 49 | + options[:trace] = int |
| 50 | + end |
| 51 | + opts.on('--natural', "Show natualized test names.") do |bool| |
| 52 | + options[:natural] = bool |
| 53 | + end |
| 54 | + opts.on('-v', '--verbose', "Show extra information.") do |bool| |
| 55 | + options[:verbose] = bool |
| 56 | + end |
| 57 | + opts.on('--[no-]ansi', "Force use of ANSI codes on or off.") do |bool| |
| 58 | + options[:ansi] = bool |
| 59 | + end |
| 60 | + opts.on('--log', "log results to a file") do #|path| |
| 61 | + options[:log] = true # TODO: support path/file |
| 62 | + end |
| 63 | + #opts.on('--live', "do not use local load path") do |
| 64 | + # options[:live] = true |
| 65 | + #end |
| 66 | + |
| 67 | + opts.on('--normal', "run all tests in a single process [default]") do |
| 68 | + options[:runmode] = nil |
| 69 | + end |
| 70 | + opts.on('--solo', "run each test in a separate process") do |
| 71 | + options[:runmode] = :solo |
| 72 | + end |
| 73 | + opts.on('--cross', "run each pair of test files in a separate process") do |
| 74 | + options[:runmode] = :cross |
| 75 | + end |
| 76 | + |
| 77 | + opts.on('--outline', '-O', "turn's original case/test outline mode") do |
| 78 | + options[:outmode] = :outline |
| 79 | + end |
| 80 | + opts.on('--progress', '-P', "indicates progress with progress bar") do |
| 81 | + options[:outmode] = :progress |
| 82 | + end |
| 83 | + opts.on('--dot', '--dotted', '-D', "test-unit's traditonal dot-progress mode") do |
| 84 | + options[:outmode] = :dot |
| 85 | + end |
| 86 | + opts.on('--pretty', '-R', '-T', "new pretty output mode [default]") do |
| 87 | + options[:outmode] = :pretty |
| 88 | + end |
| 89 | + opts.on('--cue', '-C', "cue for action on each failure/error") do |
| 90 | + options[:outmode] = :cue |
| 91 | + end |
| 92 | + opts.on('--marshal', '-M', "dump output as YAML (normal run mode only)") do |
| 93 | + options[:runmode] = :marshal |
| 94 | + options[:outmode] = :marshal |
| 95 | + end |
| 96 | + |
| 97 | + opts.on('--topten', "show only top ten slowest tests") do |
| 98 | + @options[:decmode] = :topten |
| 99 | + end |
| 100 | + opts.on('--debug', "turn debug mode on") do |
| 101 | + $DEBUG = true |
| 102 | + end |
| 103 | + opts.on('--warn', "turn warnings on") do |
| 104 | + $VERBOSE = true |
| 105 | + end |
| 106 | + |
| 107 | + # DEPRECATED Thanks to minitest-reporter-api gem. |
| 108 | + #unless options[:minitap] |
| 109 | + # if defined?(Minitest::TapY) && self.reporter == Minitest::TapY |
| 110 | + # options[:minitap] = 'tapy' |
| 111 | + # elsif defined?(Minitest::TapJ) && self.reporter == Minitest::TapJ |
| 112 | + # options[:minitap] = 'tapj' |
| 113 | + # end |
| 114 | + #end |
| 115 | + end |
| 116 | + |
| 117 | + # |
| 118 | + # |
| 119 | + def self.plugin_turn_init(options) |
| 120 | + if $turn_command || ENV['turn'] |
| 121 | + |
| 122 | + require 'turn' |
| 123 | + |
| 124 | + self.reporter.reporters.clear |
| 125 | + |
| 126 | + format = options[:outmode] || ENV['turn'] || 'pretty' |
| 127 | + |
| 128 | + case format.to_s |
| 129 | + when 'dot', 'd' |
| 130 | + require 'turn/reporters/dot_reporter' |
| 131 | + self.reporter << Turn::DotReporter.new(options) |
| 132 | + when 'cue', 'c' |
| 133 | + require 'turn/reporters/cue_reporter' |
| 134 | + self.reporter << Turn::CueReporter.new(options) |
| 135 | + when 'pretty', 't' |
| 136 | + require 'turn/reporters/pretty_reporter' |
| 137 | + self.reporter << Turn::PrettyReporter.new(options) |
| 138 | + when 'outline', 'o' |
| 139 | + require 'turn/reporters/outline_reporter' |
| 140 | + self.reporter << Turn::OutlineReporter.new(options) |
| 141 | + when 'progress', 'p' |
| 142 | + require 'turn/reporters/progress_reporter' |
| 143 | + self.reporter << Turn::ProgressReporter.new(options) |
| 144 | + when 'marshal', 'm' |
| 145 | + require 'turn/reporters/marshal_reporter' |
| 146 | + self.reporter << Turn::MarshalReporter.new(options) |
| 147 | + else |
| 148 | + raise "Unknown reporter -- `#{format}'" |
| 149 | + end |
| 150 | + |
| 151 | + options[:tests] = ARGV.empty? ? nil : ARGV.dup |
| 152 | + |
| 153 | + config = Turn.config |
| 154 | + config.tests = options[:tests] |
| 155 | + config.live = options[:live] |
| 156 | + config.log = options[:log] |
| 157 | + config.loadpath = options[:loadpath] |
| 158 | + config.requires = options[:requires] |
| 159 | + config.runmode = options[:runmode] |
| 160 | + config.format = options[:outmode] |
| 161 | + config.mode = options[:decmode] |
| 162 | + config.pattern = options[:pattern] |
| 163 | + config.matchcase = options[:matchcase] |
| 164 | + config.trace = options[:trace] |
| 165 | + config.natural = options[:natural] |
| 166 | + config.verbose = options[:verbose] |
| 167 | + config.mark = options[:mark] |
| 168 | + config.ansi = options[:ansi] unless options[:ansi].nil? |
| 169 | + |
| 170 | + config.loadpath.each{ |path| $: << path } unless config.live? |
| 171 | + config.requires.each{ |path| require(path) } |
| 172 | + |
| 173 | + # load'em up |
| 174 | + if $turn_command |
| 175 | + config.files.each{ |path| require(path) } |
| 176 | + end |
| 177 | + end |
| 178 | + end |
| 179 | + |
| 180 | +end |
| 181 | + |
0 commit comments