baretest 0.2.4 → 0.4.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/LICENSE.txt +6 -6
  2. data/MANIFEST.txt +40 -18
  3. data/README.rdoc +8 -1
  4. data/bin/baretest +126 -118
  5. data/doc/baretest.rdoc +1 -1
  6. data/doc/mocking_stubbing_test_doubles.rdoc +31 -3
  7. data/doc/news/news-0.3.0.rdoc +7 -0
  8. data/doc/quickref.rdoc +74 -28
  9. data/doc/whats_going_on.rdoc +5 -0
  10. data/doc/writing_tests.rdoc +25 -13
  11. data/examples/components/rack-test.rb +17 -0
  12. data/examples/{tests/irb_mode → irb_mode}/failures.rb +0 -0
  13. data/examples/rake/test.rake +40 -0
  14. data/examples/tests/01_basics_I.rb +34 -0
  15. data/examples/tests/02_basics_II_helpers.rb +25 -0
  16. data/examples/tests/03_basics_III_setup_and_teardown.rb +53 -0
  17. data/examples/tests/04_advanced_I_dependencies.rb +31 -0
  18. data/examples/tests/05_advanced_II_tags.rb +12 -0
  19. data/examples/tests/06_advanced_III_requires.rb +21 -0
  20. data/examples/tests/07_advanced_IV_components.rb +48 -0
  21. data/examples/tests/08_expert_I_setup_variants.rb +46 -0
  22. data/lib/baretest.rb +142 -21
  23. data/lib/baretest/assertion.rb +83 -92
  24. data/lib/baretest/assertion/context.rb +9 -0
  25. data/lib/baretest/assertion/support.rb +88 -61
  26. data/lib/baretest/commandline.rb +268 -0
  27. data/lib/baretest/formatter.rb +58 -0
  28. data/lib/baretest/invalidselectors.rb +24 -0
  29. data/lib/baretest/irb_mode.rb +100 -58
  30. data/lib/baretest/persistence.rb +94 -0
  31. data/lib/baretest/run.rb +138 -37
  32. data/lib/baretest/run/cli.rb +97 -43
  33. data/lib/baretest/run/minimal.rb +2 -1
  34. data/lib/baretest/run/none.rb +21 -0
  35. data/lib/baretest/run/xml.rb +21 -19
  36. data/lib/baretest/setup.rb +2 -0
  37. data/lib/baretest/status.rb +93 -0
  38. data/lib/baretest/suite.rb +185 -59
  39. data/lib/baretest/uid.rb +51 -0
  40. data/lib/baretest/use/mocha.rb +24 -0
  41. data/lib/baretest/use/rack_test.rb +9 -0
  42. data/lib/baretest/use/rr.rb +17 -0
  43. data/lib/baretest/version.rb +18 -4
  44. data/lib/command.rb +36 -0
  45. data/lib/command/argument.rb +11 -0
  46. data/lib/command/decoratinghash.rb +31 -0
  47. data/lib/command/definition.rb +294 -0
  48. data/lib/command/directorynotfounderror.rb +11 -0
  49. data/lib/command/env.rb +11 -0
  50. data/lib/command/filenotfounderror.rb +11 -0
  51. data/lib/command/kernel.rb +14 -0
  52. data/lib/command/nodirectoryerror.rb +11 -0
  53. data/lib/command/nofileerror.rb +11 -0
  54. data/lib/command/option.rb +16 -0
  55. data/lib/command/parser.rb +145 -0
  56. data/lib/command/result.rb +11 -0
  57. data/lib/command/types.rb +33 -0
  58. data/lib/command/version.rb +28 -0
  59. data/test/setup.rb +3 -0
  60. data/test/suite/lib/baretest.rb +0 -178
  61. data/test/suite/lib/baretest/assertion.rb +133 -112
  62. data/test/suite/lib/baretest/assertion/context.rb +40 -0
  63. data/test/suite/lib/baretest/assertion/failure.rb +19 -0
  64. data/test/suite/lib/baretest/assertion/skip.rb +19 -0
  65. data/test/suite/lib/baretest/assertion/support.rb +366 -84
  66. data/test/suite/lib/baretest/run.rb +114 -15
  67. data/test/suite/lib/baretest/suite.rb +70 -29
  68. metadata +46 -24
  69. data/examples/test.rake +0 -65
  70. data/examples/tests/mock_developer/test/helper/mocks.rb +0 -0
  71. data/examples/tests/mock_developer/test/setup.rb +0 -57
  72. data/examples/tests/mock_developer/test/suite/mock_demo.rb +0 -19
  73. data/examples/tests/overview/test.rb +0 -89
  74. data/examples/tests/variations/variations_01.rb +0 -14
  75. data/examples/tests/variations/variations_02.rb +0 -19
  76. data/examples/tests/variations/variations_03.rb +0 -19
  77. data/lib/baretest/mocha.rb +0 -18
  78. data/lib/baretest/rr.rb +0 -16
  79. data/lib/baretest/run/errors.rb +0 -49
  80. data/lib/baretest/skipped.rb +0 -15
  81. data/lib/baretest/skipped/assertion.rb +0 -20
  82. data/lib/baretest/skipped/suite.rb +0 -49
  83. data/test/external/bootstraptest.rb +0 -5
  84. data/test/external/bootstrapwrap.rb +0 -2
  85. data/test/helper/mocks.rb +0 -0
@@ -8,10 +8,19 @@
8
8
 
9
9
  module BareTest
10
10
  class Assertion
11
+
12
+ # Serves as the exercise- and verify-container for Assertions. Upon
13
+ # Assertion#execute, a new Context is created, the setups, the assertions'
14
+ # defining block and the teardowns instance evaled.
15
+ # Components will want to extend this class.
11
16
  class Context
17
+
18
+ # The Assertion instance this Context was created for
12
19
  attr_reader :__assertion__
13
20
  alias assertion __assertion__
14
21
 
22
+ # Accepts the Assertion instance this Context is created for as first
23
+ # and only argument.
15
24
  def initialize(assertion)
16
25
  @__assertion__ = assertion
17
26
  end
@@ -18,7 +18,7 @@ module BareTest
18
18
  @touch = {}
19
19
 
20
20
  # We don't want to litter in Assertion
21
- # Touches are associated withx
21
+ # Touches are associated with
22
22
  # Used by BareTest::Assertion::Support#touch
23
23
  def self.touch(assertion, thing=nil) # :nodoc:
24
24
  @touch[assertion] ||= Hash.new(0)
@@ -72,26 +72,24 @@ module BareTest
72
72
 
73
73
  # FIXME: incomplete and untested
74
74
  def throws(symbol) # :nodoc:
75
- begin
76
- passed = false
77
- catch(sym) {
78
- yield
79
- passed = true
80
- return false
81
- }
82
- passed = true
83
- return true
84
- rescue NameError => e
85
- return false if e.message =~ 'uncaught throw'
86
- raise
87
- rescue Exception
88
- passed = true
75
+ passed = false
76
+ catch(symbol) {
77
+ yield
78
+ failure "Expected the code to throw %p, but nothing was thrown", symbol
79
+ }
80
+ return true
81
+ # throw raises a NameError if no catch with appropriate symbol is set up
82
+ rescue ArgumentError, NameError => e
83
+ # Make sure it's not a NameError with a different reason than the throw
84
+ # ruby 1.8.7: NameError, "uncaught throw `symbol'"
85
+ # ruby 1.9.1: ArgumentError, "uncaught throw :symbol"
86
+ threw_instead = e.message[/\Auncaught throw `(.*)'\z/, 1] || e.message[/\Auncaught throw :(.*)\z/, 1]
87
+ if threw_instead then
88
+ failure "Expected the code to throw %p, but it threw %p instead", symbol, threw_instead.to_sym
89
+ else
90
+ # It was some other name error, reraise
89
91
  raise
90
- ensure
91
- raise ThrewSomethingElse unless passed
92
92
  end
93
- rescue ThrewSomethingElse => e
94
- return false
95
93
  end
96
94
 
97
95
  # FIXME: incomplete and untested
@@ -109,21 +107,28 @@ module BareTest
109
107
  # raises :with_message => "bar" do raise "bar" end # => true
110
108
  # raises SomeException, :with_message => "bar"; raise SomeException, "bar" end # => true
111
109
  # raises :with_message => /\Aknown \w+\z/; raise "known unknown" end # => true
112
- def raises(exception_class=StandardError, opts={})
110
+ def raises(expected_exception_class=nil, with_message=nil, opts={})
111
+ exception_class = expected_exception_class || StandardError
113
112
  yield
114
113
  rescue exception_class => exception
115
- if opts[:with_message] && !(opts[:with_message] === exception.message) then
116
- failure "Expected block to raise with the message %p, but the message was %p",
117
- exception.message, opts[:with_message]
114
+ if expected_exception_class && exception.class != expected_exception_class then
115
+ failure "Expected the code to raise #{expected_exception_class}, but it raised #{exception.class} instead"
116
+ elsif with_message && !(with_message === exception.message) then
117
+ failure "Expected the code to raise with the message %p, but the message was %p",
118
+ with_message, exception.message
118
119
  else
119
120
  true
120
121
  end
121
122
  rescue ::BareTest::Assertion::Failure, *::BareTest::Assertion::PassthroughExceptions
122
123
  ::Kernel.raise
123
124
  rescue => exception
124
- failure "Expected block to raise #{exception_class}, but it raised #{exception.class}."
125
+ failure "Expected the code to raise #{expected_exception_class}, but it raised #{exception.class} instead"
125
126
  else
126
- failure "Expected block to raise #{exception_class}, but nothing was raised."
127
+ if expected_exception_class then
128
+ failure "Expected the code to raise #{expected_exception_class}, but nothing was raised"
129
+ else
130
+ failure "Expected the code to raise, but nothing was raised"
131
+ end
127
132
  end
128
133
 
129
134
  # Will raise a Failure if the given block raises.
@@ -132,7 +137,7 @@ module BareTest
132
137
  rescue ::BareTest::Assertion::Failure, *::BareTest::Assertion::PassthroughExceptions
133
138
  ::Kernel.raise
134
139
  rescue Exception => exception
135
- failure "Expected block to raise nothing, but it raised #{exception.class}."
140
+ failure "Expected the code to raise nothing, but it raised #{exception.class} (#{exception.message})"
136
141
  else
137
142
  true
138
143
  end
@@ -141,7 +146,12 @@ module BareTest
141
146
  # for example a delta comparison instead, to take care
142
147
  # of the possible rounding differences.
143
148
  def within_delta(a, b, delta)
144
- (a-b).abs < delta
149
+ actual_delta = (a-b).abs
150
+ if actual_delta >= delta then
151
+ failure "Expected %p and %p to differ less than %p, but they were different by %p", a, b, delta, actual_delta
152
+ else
153
+ true
154
+ end
145
155
  rescue ::BareTest::Assertion::Failure, *::BareTest::Assertion::PassthroughExceptions
146
156
  ::Kernel.raise
147
157
  rescue Exception => e
@@ -152,7 +162,7 @@ module BareTest
152
162
  # touch marks that it was reached, #touched tests for whether it was reached.
153
163
  #
154
164
  # Example:
155
- # assert "Code in a Proc object is executed when invoking #call on it." do
165
+ # assert "Code in a Proc object is executed when invoking #call on it" do
156
166
  # a_proc = proc { touch :executed }
157
167
  # a_proc.call
158
168
  # touched(:executed)
@@ -170,16 +180,16 @@ module BareTest
170
180
  if times then
171
181
  unless touched_times == times then
172
182
  if thing then
173
- failure "Expected the code to touch %p %s times, but did %s times.", thing, times, touched_times
183
+ failure "Expected the code to touch %p %s times, but did %s times", thing, times, touched_times
174
184
  else
175
- failure "Expected the code to touch %s times, but did %s times.", times, touched_times
185
+ failure "Expected the code to touch %s times, but did %s times", times, touched_times
176
186
  end
177
187
  end
178
188
  elsif touched_times < 1 then
179
189
  if thing then
180
- failure "Expected the code to touch %p, but it was not touched.", thing
190
+ failure "Expected the code to touch %p, but it was not touched", thing
181
191
  else
182
- failure "Expected the code to touch, but no touch happened."
192
+ failure "Expected the code to touch, but no touch happened"
183
193
  end
184
194
  end
185
195
  true
@@ -202,9 +212,9 @@ module BareTest
202
212
 
203
213
  unless expected.equal?(actual) then
204
214
  if message then
205
- failure "Expected %s to be the same (equal?) as %p but was %p.", message, expected, actual
215
+ failure "Expected %s to be the same (equal?) as %p but was %p", message, expected, actual
206
216
  else
207
- failure "Expected %p but got %p.", expected, actual
217
+ failure "Expected %p but got %p", expected, actual
208
218
  end
209
219
  end
210
220
  true
@@ -225,9 +235,9 @@ module BareTest
225
235
 
226
236
  unless expected.eql?(actual) then
227
237
  if message then
228
- failure "Expected %s to be hash-key equal (eql?) to %p but was %p.", message, expected, actual
238
+ failure "Expected %s to be hash-key equal (eql?) to %p but was %p", message, expected, actual
229
239
  else
230
- failure "Expected %p but got %p.", expected, actual
240
+ failure "Expected %p but got %p", expected, actual
231
241
  end
232
242
  end
233
243
  true
@@ -248,9 +258,9 @@ module BareTest
248
258
 
249
259
  unless expected == actual then
250
260
  if message then
251
- failure "Expected %s to be order equal (==) to %p but was %p.", message, expected, actual
261
+ failure "Expected %s to be order equal (==) to %p but was %p", message, expected, actual
252
262
  else
253
- failure "Expected %p but got %p.", expected, actual
263
+ failure "Expected %p but got %p", expected, actual
254
264
  end
255
265
  end
256
266
  true
@@ -272,8 +282,8 @@ module BareTest
272
282
 
273
283
  unless expected === actual then
274
284
  failure_with_optional_message \
275
- "Expected %s to be case equal (===) to %p but was %p.",
276
- "Expected %p but got %p.",
285
+ "Expected %s to be case equal (===) to %p but was %p",
286
+ "Expected %p but got %p",
277
287
  message, expected, actual
278
288
  end
279
289
  true
@@ -299,11 +309,11 @@ module BareTest
299
309
  only_in_actual = count.select { |ele, n| n < 0 }.map { |ele, n| ele }
300
310
  if message then
301
311
  failure "Expected %s to have the same items the same number of times, " \
302
- "but %p are only in expected, and %p only in actual.",
312
+ "but %p are only in expected, and %p only in actual",
303
313
  message, only_in_expected, only_in_actual
304
314
  else
305
315
  failure "Expected %p and %p to have the same items the same number of times, " \
306
- "but %p are only in expected, and %p only in actual.",
316
+ "but %p are only in expected, and %p only in actual",
307
317
  expected, actual, only_in_expected, only_in_actual
308
318
  end
309
319
  end
@@ -330,7 +340,42 @@ module BareTest
330
340
  rescue ::BareTest::Assertion::Failure, *::BareTest::Assertion::PassthroughExceptions
331
341
  ::Kernel.raise
332
342
  rescue Exception => e
333
- failure "Could not test whether %p is a child of %p due to %s", actual, expected, e
343
+ failure "Could not test whether %p is a kind of %p due to %s", actual, expected, e
344
+ end
345
+
346
+ # Raises a Failure if the given object is not an instance of the given class
347
+ def instance_of(*args)
348
+ expected, actual, message = extract_args(args, :expected, :actual, :message)
349
+ unless actual.instance_of?(expected) then
350
+ failure_with_optional_message \
351
+ "Expected %1$s to be an instance of %3$p, but was a %4$p",
352
+ "Expected %2$p to be an instance of %1$p, but was a %3$p",
353
+ message, expected, actual, actual.class
354
+ end
355
+ true
356
+
357
+ rescue ::BareTest::Assertion::Failure, *::BareTest::Assertion::PassthroughExceptions
358
+ ::Kernel.raise
359
+ rescue Exception => e
360
+ failure "Could not test whether %p is an instance of %p due to %s", actual, expected, e
361
+ end
362
+
363
+ # Raises a Failure if the given object does not respond to all of the given
364
+ # method names. The method names may be specified as String or Symbol.
365
+ def respond_to(obj, *methods)
366
+ not_responded_to = methods.reject { |method_name| obj.respond_to?(method_name) }
367
+ unless not_responded_to.empty? then
368
+ must_respond_to = methods.map { |m| m.to_sym.inspect }.join(', ')
369
+ not_responded_to = not_responded_to.map { |m| m.to_sym.inspect }.join(', ')
370
+ failure "Expected %1$s to respond to all of %2$s, but it did not respond to %3$s",
371
+ obj, must_respond_to, not_responded_to
372
+ end
373
+ true
374
+
375
+ rescue ::BareTest::Assertion::Failure, *::BareTest::Assertion::PassthroughExceptions
376
+ ::Kernel.raise
377
+ rescue Exception => e
378
+ failure "Could not test whether %p responds to %p due to %s", obj, methods, e
334
379
  end
335
380
 
336
381
  # A method to make raising failures that only optionally have a message easier.
@@ -356,7 +401,6 @@ module BareTest
356
401
  raise ::BareTest::Assertion::Skip, sprintf(message, *args)
357
402
  end
358
403
 
359
- private
360
404
  # extract arg allows to use named or positional args
361
405
  #
362
406
  # Example:
@@ -384,20 +428,3 @@ module BareTest
384
428
  end
385
429
  end # Assertion
386
430
  end # BareTest
387
-
388
- module Enumerable
389
-
390
- # Part of BareTest - require 'baretest/assertion/support'
391
- #
392
- # Returns true if all elements of self occur the same amount of times in other, regardless
393
- # of order. Uses +eql?+ to determine equality.
394
- #
395
- # Example:
396
- # [2,1,3,2].equal_unordered?([3,2,2,1]) # => true
397
- def equal_unordered?(other)
398
- count = Hash.new(0)
399
- other.each { |element| count[element] += 1 }
400
- each { |element| count[element] -= 1 }
401
- count.all? { |key, value| value.zero? }
402
- end
403
- end
@@ -0,0 +1,268 @@
1
+ #--
2
+ # Copyright 2009-2010 by Stefan Rusterholz.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+
8
+
9
+ require 'baretest/assertion/context'
10
+ require 'baretest/assertion/failure'
11
+ require 'baretest/assertion/skip'
12
+
13
+
14
+
15
+ module BareTest
16
+
17
+ # The CommandLine module provides all the functionality the
18
+ # baretest executable uses in a programmatic way.
19
+ # It in fact even is what the baretest executable itself uses.
20
+ module CommandLine
21
+
22
+ # Load a formatter (see Run::new)
23
+ def load_formatter(format)
24
+ require "baretest/run/#{format}" if String === format
25
+ BareTest.format["baretest/run/#{format}"]
26
+ end
27
+ module_function :load_formatter
28
+
29
+ # Run the tests and display information about them.
30
+ # * arguments: array of dirs/globs of files to load and run as tests
31
+ # * options: a hash with options (all MUST be provided)
32
+ #
33
+ # :format => String - the formatter
34
+ # :interactive => Boolean - activate interactive mode (drops into irb on failure/error)
35
+ # :verbose => Boolean - provide verbose output
36
+ def run(arguments, options)
37
+ setup_path = nil
38
+ selectors = BareTest.process_selectors(arguments)
39
+ options = selectors.merge(options)
40
+ options[:persistence] ||= Persistence.new
41
+
42
+ # Load the setup file, all helper files and all test files
43
+ BareTest.load_standard_test_files(
44
+ :verbose => options[:verbose],
45
+ :setup_path => options[:setup_path],
46
+ :files => options[:files],
47
+ :chdir => '.'
48
+ )
49
+
50
+ # Run the tests
51
+ puts if options[:verbose]
52
+ ARGV.clear # IRB is being stupid
53
+ runner = BareTest::Run.new(BareTest.toplevel_suite, options)
54
+ runner.run_all
55
+
56
+ # Return whether all tests ran successful
57
+ runner.global_status == :success
58
+ end
59
+ module_function :run
60
+
61
+ # Create a basic skeleton of directories and files to contain baretests
62
+ # test-suite. Non-destructive (existing files won't be overriden or
63
+ # deleted).
64
+ def init(arguments, options)
65
+ core = %w[
66
+ test
67
+ test/external
68
+ test/helper
69
+ test/helper/suite
70
+ test/suite
71
+ ]
72
+ mirror = {
73
+ 'bin' => %w[test/helper/suite test/suite],
74
+ 'lib' => %w[test/helper/suite test/suite],
75
+ 'rake' => %w[test/helper/suite test/suite],
76
+ }
77
+ files = {
78
+ 'test/setup.rb' => <<-END_OF_SETUP.gsub(/^ {10}/, '')
79
+ BareTest.require_ruby #{RUBY_VERSION.inspect}
80
+ BareTest.require_baretest #{BareTest::VERSION.to_a.first(3).join('.').inspect}
81
+ $LOAD_PATH.unshift(File.expand_path("\#{__FILE__}/../../lib")) # Add PROJECT/lib to $LOAD_PATH
82
+ END_OF_SETUP
83
+ }
84
+
85
+ puts "Creating all directories and files needed in #{File.expand_path('.')}"
86
+ core.each do |dir|
87
+ if File.exist?(dir) then
88
+ puts "Directory #{dir} exists already -- skipping"
89
+ else
90
+ puts "Creating #{dir}"
91
+ Dir.mkdir(dir)
92
+ end
93
+ end
94
+ mirror.each do |path, destinations|
95
+ if File.exist?(path) then
96
+ destinations.each do |destination|
97
+ destination = File.join(destination,path)
98
+ if File.exist?(destination) then
99
+ puts "Mirror #{destination} of #{path} exists already -- skipping"
100
+ else
101
+ puts "Mirroring #{path} in #{destination}"
102
+ Dir.mkdir(destination)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ files.each do |path, data|
108
+ if File.exist?(path) then
109
+ puts "File #{path} exists already -- skipping"
110
+ else
111
+ puts "Writing #{path}"
112
+ File.open(path, 'wb') do |fh|
113
+ fh.write(data)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ module_function :init
119
+
120
+ # Shows all formats available in run's -f/--format option.
121
+ def formats(arguments, options)
122
+ puts "Available formats:"
123
+ Dir.glob("{#{$LOAD_PATH.join(',')}}/baretest/run/*.rb") { |path|
124
+ puts "- #{File.basename(path, '.rb')}"
125
+ }
126
+ end
127
+ module_function :formats
128
+
129
+ # List the available commands.
130
+ def commands(arguments, options)
131
+ colors = $stdout.tty?
132
+
133
+ description = <<-END_OF_DESCRIPTION.gsub(/^ {8}/, '') # |<- 80 cols ends here
134
+ \e[1mCOMMANDS\e[0m
135
+
136
+ The following commands are available in baretest:
137
+
138
+ \e[1mcommands\e[0m
139
+ List the available commands.
140
+
141
+ \e[1menv\e[0m
142
+ Show the baretest environment. This contains all data that influences
143
+ baretests behaviour. That is: ruby version, ruby engine, determined
144
+ test directory, stored data about this suite etc.
145
+
146
+ \e[1mformats\e[0m
147
+ Shows all formats available in \e[34mrun\e[0m's -f/--format option.
148
+
149
+ \e[1mhelp\e[0m
150
+ Provides help for all commands. Describes options, arguments and env
151
+ variables each command accepts.
152
+
153
+ \e[1minit\e[0m
154
+ Create a basic skeleton of directories and files to contain baretests test-
155
+ suite. Non-destructive (existing files won't be overriden or deleted).
156
+
157
+ \e[1mrun\e[0m (default command)
158
+ Run the tests and display information about them.
159
+
160
+ \e[1mselectors\e[0m
161
+ Detailed information about the selectors available to \e[34mrun\e[0m's
162
+ arguments.
163
+
164
+ \e[1mversion\e[0m
165
+ Show the baretest executable and library versions.
166
+
167
+ END_OF_DESCRIPTION
168
+ #'# |<- 80 cols ends here
169
+ description.gsub!(/\e.*?m/, '') unless colors
170
+
171
+ puts description
172
+ end
173
+ module_function :commands
174
+
175
+ # Detailed information about the selectors available to run's arguments.
176
+ def selectors(arguments, options)
177
+ colors = $stdout.tty?
178
+
179
+ description = <<-END_OF_DESCRIPTION.gsub(/^ {8}/, '') # |<- 80 cols ends here
180
+ \e[1mSELECTORS\e[0m
181
+
182
+ \e[1mDescription\e[0m
183
+ Selectors are used to identify what tests to run. Baretest knows 3 kinds of
184
+ selectors: globs, tags and last-run-states. All of these can be preceeded
185
+ with a minus sign (-), to negate the expression.
186
+ Beware that you must use negated expressions only after a -- separator,
187
+ as otherwise baretest will try to interpret them as short options (like -f).
188
+
189
+ \e[1mExample\e[0m
190
+ `baretest -- test/suite -test/suite/foo :a -:b #failure -#pending`
191
+
192
+ This will run all tests that
193
+ * Are in the directory test/suite or any of its subdirectories
194
+ * Are NOT in the directory test/suite/foo, or any of its subdirectories
195
+ * Have the tag 'a'
196
+ * Do NOT have the tag 'b'
197
+ * Terminated with a failure status on the last run
198
+ * Did NOT terminate with a pending status on the last run
199
+
200
+ \e[1mGlobs\e[0m
201
+ * '**' recursively matches all files and directories
202
+ * '*' wildcard, matches any amount of any character
203
+ * '?' wildcard, matches one character
204
+ * '{a,b,c}' alternation, matches any pattern in the comma separated list
205
+ * Directories are equivalent to `directory/**/*` patterns
206
+
207
+ \e[1mTags\e[0m
208
+ Tags are preceeded with an :.
209
+ Examples:
210
+ baretest :focus
211
+ baretest -- -:hocus
212
+ baretest -- :focus :important -:irrelevant -:obsolete
213
+
214
+ \e[1mLast-run-status\e[0m
215
+ Last run states are preceeded with a %.
216
+ * %success, %failure, %error, %skipped, %pending
217
+ * %error, %skipped and %pending are a subset of %failure
218
+ * %pending is a subset of %skipped
219
+
220
+ END_OF_DESCRIPTION
221
+
222
+ description.gsub!(/\e.*?m/, '') unless colors
223
+
224
+ puts description
225
+ end
226
+ module_function :selectors
227
+
228
+ # Provides help for all commands. Describes options, arguments and env
229
+ # variables each command accepts.
230
+ def help(arguments, options)
231
+ colors = $stdout.tty?
232
+
233
+ description = <<-END_OF_DESCRIPTION.gsub(/^ {8}/, '') # |<- 80 cols ends here
234
+ \e[1mHELP\e[0m
235
+
236
+ See `#{$0} commands` for a list of available commands.
237
+ You can also use `#{$0} COMMAND --help` to get information about
238
+ the command COMMAND.
239
+ END_OF_DESCRIPTION
240
+
241
+ description.gsub!(/\e.*?m/, '') unless colors
242
+
243
+ puts description
244
+ end
245
+ module_function :help
246
+
247
+ # Show the baretest environment. This contains all data that influences
248
+ # baretests behaviour. That is: ruby version, ruby engine, determined test
249
+ # directory, stored data about this suite etc.
250
+ def env(arguments, options)
251
+ puts "Versions:",
252
+ "* executable: #{Version}",
253
+ "* library: #{BareTest::VERSION}",
254
+ "* ruby #{RUBY_VERSION}",
255
+ ""
256
+ end
257
+ module_function :env
258
+
259
+ # Show the baretest executable and library versions.
260
+ def version(arguments, options)
261
+ puts "baretest executable version #{Version}",
262
+ "library version #{BareTest::VERSION}",
263
+ "ruby version #{RUBY_VERSION}",
264
+ ""
265
+ end
266
+ module_function :version
267
+ end
268
+ end