Class: Turn::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/turn/command.rb

Overview

Turn - Pretty Unit Test Runner for Ruby

SYNOPSIS

turn [OPTIONS] [RUN MODE] [OUTPUT MODE] [TEST GLOBS ...]

GENERAL OPTIONS

-I, --loadpath=PATHS             add paths to $LOAD_PATH
-r, --require=LIBS               require libraries
-n, --name=PATTERN               only run tests that match PATTERN
-c, --case=PATTERN               only run test cases that match PATTERN
-b, --backtrace, --trace INT     Limit the number of lines of backtrace.
    --natural                    Show natualized test names.
    --[no-]ansi                  Force use of ANSI codes on or off.
    --log                        log results to a file
    --live                       do not use local load path

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
-R, -T, --pretty                 new pretty output mode
-C, --cue                        cue for action on each failure/error
-M, --marshal                    dump output as YAML (normal run mode only)

COMMAND OPTIONS

    --debug                      turn debug mode on
    --version                    display version
-h, --help                       display this help information

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/turn/command.rb', line 83

def initialize
  @live      = nil
  @log       = nil
  @pattern   = nil
  @matchcase = nil
  @loadpath  = []
  @requires  = []
  @runmode   = nil
  @outmode   = nil
  @trace     = nil
  @natural   = false
  @ansi      = nil
end

Instance Attribute Details

#ansiObject (readonly)

Force ANSI use on or off.



80
81
82
# File 'lib/turn/command.rb', line 80

def ansi
  @ansi
end

#liveObject (readonly)

Do not use local loadpath.



50
51
52
# File 'lib/turn/command.rb', line 50

def live
  @live
end

#loadpathObject (readonly)

List of paths to add to $LOAD_PATH



59
60
61
# File 'lib/turn/command.rb', line 59

def loadpath
  @loadpath
end

#logObject (readonly)

Log output.



47
48
49
# File 'lib/turn/command.rb', line 47

def log
  @log
end

#matchcaseObject (readonly)

Only run testcases matching this pattern.



56
57
58
# File 'lib/turn/command.rb', line 56

def matchcase
  @matchcase
end

#naturalObject (readonly)

Use natural test case names.



77
78
79
# File 'lib/turn/command.rb', line 77

def natural
  @natural
end

#outmodeObject (readonly)

Output mode.



71
72
73
# File 'lib/turn/command.rb', line 71

def outmode
  @outmode
end

#patternObject (readonly)

Only run tests matching this pattern.



53
54
55
# File 'lib/turn/command.rb', line 53

def pattern
  @pattern
end

#requiresObject (readonly)

Libraries to require before running tests.



62
63
64
# File 'lib/turn/command.rb', line 62

def requires
  @requires
end

#runmodeObject (readonly)

Run mode.



68
69
70
# File 'lib/turn/command.rb', line 68

def runmode
  @runmode
end

#traceObject (readonly)

Enable full backtrace



74
75
76
# File 'lib/turn/command.rb', line 74

def trace
  @trace
end

Class Method Details

.main(*argv) ⇒ Object

Shortcut for new.main(*argv)



42
43
44
# File 'lib/turn/command.rb', line 42

def self.main(*argv)
  new.main(*argv)
end

Instance Method Details

#main(*argv) ⇒ Object

Run command.



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/turn/command.rb', line 229

def main(*argv)
  option_parser.parse!(argv)

  @loadpath = ['lib'] if loadpath.empty?

  tests = ARGV.empty? ? nil : argv.dup

  #config = Turn::Configuration.new do |c|
  config = Turn.config 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.matchcase = matchcase
    c.trace     = trace
    c.natural   = natural
    c.ansi      = ansi unless ansi.nil?
  end

  controller = Turn::Controller.new(config)

  result = controller.start

  if result
    exit (result.passed? ? 0 : -1)
  else # no tests
    exit -1
  end
end

#option_parserObject



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
178
179
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/turn/command.rb', line 98

def option_parser
  OptionParser.new do |opts|

    opts.banner = "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|
      if pattern =~ /\/(.*)\//
        @pattern = Regexp.new($1)
      else
        @pattern = Regexp.new(pattern, Regexp::IGNORECASE)
      end
    end

    opts.on('-c', '--case=PATTERN', "only run test cases that match PATTERN") do |pattern|
      if pattern =~ /\/(.*)\//
        @matchcase = Regexp.new($1)
      else
        @matchcase = Regexp.new(pattern, Regexp::IGNORECASE)
      end
    end

    opts.on('-b', '--backtrace', '--trace INT', "Limit the number of lines of backtrace.") do |int|
      @trace = int
    end

    opts.on('--natural', "Show natualized test names.") do |bool|
      @natural = bool
    end

    opts.on('--[no-]ansi', "Force use of ANSI codes on or off.") do |bool|
      @ansi = bool
    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', '-R', '-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
      $DEBUG   = true
    end

    opts.on('--warn', "turn warnings on") do
      $VERBOSE = true
    end

    opts.on_tail('--version', "display version") do
      puts VERSION
      exit
    end

    opts.on_tail('--help', '-h', "display this help information") do
      puts opts
      exit
    end
  end
end