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...]

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
-c --case=PATTERN     only run testcases 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.
-b --backtrace=INT    Set the number of lines to show in backtrace.

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 --pretty      new pretty reporter
-M --marshal     dump output as YAML (normal run mode only)
-C --cue         interactive testing

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/turn/command.rb', line 79

def initialize
  @live      = nil
  @log       = nil
  @pattern   = nil
  @matchcase = nil
  @loadpath  = []
  @requires  = []
  @runmode   = nil
  @outmode   = nil
  #@framework = RUBY_VERSION >= "1.9" ? :minitest : :testunit
  @trace     = nil
  @natural   = false
  @ansi      = nil
end

Instance Attribute Details

#ansiObject (readonly)

Force ANSI use on or off.



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

def ansi
  @ansi
end

#liveObject (readonly)

Do not use local loadpath.



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

def live
  @live
end

#loadpathObject (readonly)

List of paths to add to $LOAD_PATH



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

def loadpath
  @loadpath
end

#logObject (readonly)

Log output.



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

def log
  @log
end

#matchcaseObject (readonly)

Only run testcases matching this pattern.



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

def matchcase
  @matchcase
end

#naturalObject (readonly)

Use natural test case names.



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

def natural
  @natural
end

#outmodeObject (readonly)

Output mode.



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

def outmode
  @outmode
end

#patternObject (readonly)

Only run tests matching this pattern.



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

def pattern
  @pattern
end

#requiresObject (readonly)

Libraries to require before running tests.



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

def requires
  @requires
end

#runmodeObject (readonly)

Run mode.



64
65
66
# File 'lib/turn/command.rb', line 64

def runmode
  @runmode
end

#traceObject (readonly)

Enable full backtrace



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

def trace
  @trace
end

Class Method Details

.main(*argv) ⇒ Object

Shortcut for new.main(*argv)



38
39
40
# File 'lib/turn/command.rb', line 38

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

Instance Method Details

#main(*argv) ⇒ Object

Run command.



227
228
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
# File 'lib/turn/command.rb', line 227

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.framework = framework
    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?
  else # no tests
    exit
  end
end

#option_parserObject



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
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
# File 'lib/turn/command.rb', line 95

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('-m', '--minitest', "Force use of MiniTest framework") do
    #  @framework = :minitest
    #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
      $VERBOSE = true
      $DEBUG   = 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