Class: Turn::Command
- Inherits:
-
Object
- Object
- Turn::Command
- Defined in:
- lib/turn/command.rb
Overview
Turn - Pretty Unit Test Runner for Ruby
SYNOPSIS
turn [OPTIONS] [RUN MODE] [OUTPUT MODE] [test globs...]
OPTIONS
-h --help display this help information
--live don't use loadpath
--log log results to a file
-n --name=PATTERN only run tests that match regexp PATTERN
-I --loadpath=PATHS add given PATHS to the $LOAD_PATH
-r --requires=LIBS require given LIBS before running tests
-m --minitest Force use of MiniTest framework.
RUN MODES
--normal run all tests in a single process [default]
--solo run each test in a separate process
--cross run each pair of test files in a separate process
OUTPUT MODES
-O --outline turn's original case/test outline mode [default]
-P --progress indicates progress with progress bar
-D --dotted test/unit's traditonal dot-progress mode
--pretty new pretty reporter
-M --marshal dump output as YAML (normal run mode only)
-Q --queued interactive testing
Instance Attribute Summary collapse
-
#framework ⇒ Object
readonly
Framework to use, :minitest or :testunit.
-
#live ⇒ Object
readonly
Do not use local loadpath.
-
#loadpath ⇒ Object
readonly
List of paths to add to $LOAD_PATH.
-
#log ⇒ Object
readonly
Log output.
-
#outmode ⇒ Object
readonly
Output mode.
-
#pattern ⇒ Object
readonly
Only run tests matching this pattern.
-
#requires ⇒ Object
readonly
Libraries to require before running tests.
-
#runmode ⇒ Object
readonly
Run mode.
Class Method Summary collapse
-
.main(*argv) ⇒ Object
Shortcut for new.main(*argv).
Instance Method Summary collapse
-
#initialize ⇒ Command
constructor
A new instance of Command.
-
#main(*argv) ⇒ Object
Run command.
- #option_parser ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/turn/command.rb', line 65 def initialize @live = nil @log = nil @pattern = nil @loadpath = [] @requires = [] @runmode = nil @outmode = nil @framework = RUBY_VERSION >= "1.9" ? :minitest : :testunit end |
Instance Attribute Details
#framework ⇒ Object (readonly)
Framework to use, :minitest or :testunit.
56 57 58 |
# File 'lib/turn/command.rb', line 56 def framework @framework end |
#live ⇒ Object (readonly)
Do not use local loadpath.
44 45 46 |
# File 'lib/turn/command.rb', line 44 def live @live end |
#loadpath ⇒ Object (readonly)
List of paths to add to $LOAD_PATH
50 51 52 |
# File 'lib/turn/command.rb', line 50 def loadpath @loadpath end |
#log ⇒ Object (readonly)
Log output.
41 42 43 |
# File 'lib/turn/command.rb', line 41 def log @log end |
#outmode ⇒ Object (readonly)
Output mode.
62 63 64 |
# File 'lib/turn/command.rb', line 62 def outmode @outmode end |
#pattern ⇒ Object (readonly)
Only run tests matching this pattern.
47 48 49 |
# File 'lib/turn/command.rb', line 47 def pattern @pattern end |
#requires ⇒ Object (readonly)
Libraries to require before running tests.
53 54 55 |
# File 'lib/turn/command.rb', line 53 def requires @requires end |
#runmode ⇒ Object (readonly)
Run mode.
59 60 61 |
# File 'lib/turn/command.rb', line 59 def runmode @runmode end |
Class Method Details
.main(*argv) ⇒ Object
Shortcut for new.main(*argv)
36 37 38 |
# File 'lib/turn/command.rb', line 36 def self.main(*argv) new.main(*argv) end |
Instance Method Details
#main(*argv) ⇒ Object
Run command.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/turn/command.rb', line 180 def main(*argv) option_parser.parse!(argv) @loadpath = ['lib'] if loadpath.empty? tests = ARGV.empty? ? nil : ARGV.dup controller = Turn::Controller.new do |c| c.live = live c.log = log c.loadpath = loadpath c.requires = requires c.tests = tests c.runmode = runmode c.format = outmode c.pattern = pattern c.framework = framework end result = controller.start if result exit result.passed? else # no tests exit end end |
#option_parser ⇒ Object
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/turn/command.rb', line 77 def option_parser OptionParser.new do |opts| opts. = "Turn - Pretty Unit Test Runner for Ruby" opts.separator " " opts.separator "SYNOPSIS" opts.separator " turn [OPTIONS] [RUN MODE] [OUTPUT MODE] [TEST GLOBS ...]" opts.separator " " opts.separator "GENERAL OPTIONS" opts.on('-I', '--loadpath=PATHS', "add paths to $LOAD_PATH") do |path| @loadpath.concat(path.split(':')) end opts.on('-r', '--require=LIBS', "require libraries") do |lib| @requires.concat(lib.split(':')) end opts.on('-n', '--name=PATTERN', "only run tests that match PATTERN") do |pattern| @pattern = Regexp.new(pattern, Regexp::IGNORECASE) end opts.on('-m', '--minitest', "Force use of MiniTest framework") do @framework = :minitest end # Turn does not support Test::Unit 2.0+ #opts.on('-u', '--testunit', "Force use of TestUnit framework") do # @framework = :testunit #end opts.on('--log', "log results to a file") do #|path| @log = true # TODO: support path/file end opts.on('--live', "do not use local load path") do @live = true end opts.separator " " opts.separator "RUN MODES" opts.on('--normal', "run all tests in a single process [default]") do @runmode = nil end opts.on('--solo', "run each test in a separate process") do @runmode = :solo end opts.on('--cross', "run each pair of test files in a separate process") do @runmode = :cross end #opts.on('--load', "") do #end opts.separator " " opts.separator "OUTPUT MODES" opts.on('--outline', '-O', "turn's original case/test outline mode [default]") do @outmode = :outline end opts.on('--progress', '-P', "indicates progress with progress bar") do @outmode = :progress end opts.on('--dotted', '-D', "test-unit's traditonal dot-progress mode") do @outmode = :dotted end opts.on('--pretty', '-T', "new pretty output mode") do @outmode = :pretty end opts.on('--cue', '-C', "cue for action on each failure/error") do @outmode = :cue end opts.on('--marshal', '-M', "dump output as YAML (normal run mode only)") do @runmode = :marshal @outmode = :marshal end opts.separator " " opts.separator "COMMAND OPTIONS" opts.on('--debug', "turn debug mode on") do $VERBOSE = true $DEBUG = true end opts.on_tail('--help', '-h', "display this help information") do puts opts exit end end end |