| Module | BareTest::CommandLine |
| In: |
lib/baretest/commandline.rb
|
The CommandLine module provides all the functionality the baretest executable uses in a programmatic way. It in fact even is what the baretest executable itself uses.
List the available commands.
# File lib/baretest/commandline.rb, line 149
149: def commands(arguments, options)
150: colors = $stdout.tty?
151:
152: description = "\\e[1mCOMMANDS\\e[0m\n\nThe following commands are available in baretest:\n\n\\e[1mcommands\\e[0m\nList the available commands.\n\n\\e[1menv\\e[0m\nShow the baretest environment. This contains all data that influences\nbaretests behaviour. That is: ruby version, ruby engine, determined\ntest directory, stored data about this suite etc.\n\n\\e[1mformats\\e[0m\nShows all formats available in \\e[34mrun\\e[0m's -f/--format option.\n\n\\e[1mhelp\\e[0m\nProvides help for all commands. Describes options, arguments and env\nvariables each command accepts.\n\n\\e[1minit\\e[0m\nCreate a basic skeleton of directories and files to contain baretests test-\nsuite. Non-destructive (existing files won't be overriden or deleted).\n\n\\e[1mreset\\e[0m (default command)\nDelete persistent data collected from previous runs.\n\n\\e[1mrun\\e[0m (default command)\nRun the tests and display information about them.\n\n\\e[1mselectors\\e[0m\nDetailed information about the selectors available to \\e[34mrun\\e[0m's\narguments.\n\n\\e[1mversion\\e[0m\nShow the baretest executable and library versions.\n\n".gsub(/^ {8}/, '') # |<- 80 cols ends here
153: #'# |<- 80 cols ends here
154: description.gsub!(/\e.*?m/, '') unless colors
155:
156: puts description
157: end
Show the baretest environment. This contains all data that influences baretests behaviour. That is: ruby version, ruby engine, determined test directory, stored data about this suite etc.
# File lib/baretest/commandline.rb, line 276
276: def env(arguments, options)
277: puts "Versions:",
278: "* executable: #{Version}",
279: "* library: #{BareTest::VERSION}",
280: "* ruby #{RUBY_VERSION}",
281: ""
282: end
Provides help for all commands. Describes options, arguments and env variables each command accepts.
# File lib/baretest/commandline.rb, line 255
255: def help(arguments, options)
256: colors = $stdout.tty?
257:
258: description = "\\e[1mHELP\\e[0m\n\nSee `\#{$0} commands` for a list of available commands.\nYou can also use `\#{$0} COMMAND --help` to get information about\nthe command COMMAND.\n".gsub(/^ {8}/, '') # |<- 80 cols ends here
259:
260: description.gsub!(/\e.*?m/, '') unless colors
261:
262: puts description
263: end
Create a basic skeleton of directories and files to contain baretests test-suite. Non-destructive (existing files won‘t be overriden or deleted).
# File lib/baretest/commandline.rb, line 64
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: baretest_version = BareTest::VERSION.to_a.first(3).join('.').inspect
78: ruby_version = RUBY_VERSION.inspect
79: files = {
80: 'test/setup.rb' => "# Add PROJECT/lib to $LOAD_PATH\n$LOAD_PATH.unshift(File.expand_path(\"\\\#{__FILE__}/../../lib\"))\n\n# Ensure baretest is required\nrequire 'baretest'\n\n# Some defaults on BareTest (see Kernel#BareTest)\nBareTest do\nrequire_baretest \#{baretest_version} # minimum baretest version to run these tests\nrequire_ruby \#{ruby_version} # minimum ruby version to run these tests\nuse :support # Use :support in all suites\nend\n".gsub(/^ {10}/, '')
81: }
82:
83: puts "Creating all directories and files needed in #{File.expand_path('.')}"
84: core.each do |dir|
85: if File.exist?(dir) then
86: puts "Directory #{dir} exists already -- skipping"
87: else
88: puts "Creating #{dir}"
89: Dir.mkdir(dir)
90: end
91: end
92: mirror.each do |path, destinations|
93: if File.exist?(path) then
94: destinations.each do |destination|
95: destination = File.join(destination,path)
96: if File.exist?(destination) then
97: puts "Mirror #{destination} of #{path} exists already -- skipping"
98: else
99: puts "Mirroring #{path} in #{destination}"
100: Dir.mkdir(destination)
101: end
102: end
103: end
104: end
105: files.each do |path, data|
106: if File.exist?(path) then
107: puts "File #{path} exists already -- skipping"
108: else
109: puts "Writing #{path}"
110: File.open(path, 'wb') do |fh|
111: fh.write(data)
112: end
113: end
114: end
115: end
Load a formatter (see Run::new)
# File lib/baretest/commandline.rb, line 23
23: def load_formatter(format)
24: require "baretest/run/#{format}" if String === format
25: BareTest.format["baretest/run/#{format}"]
26: end
Remove all files that store state, cache things etc. from persistence.
# File lib/baretest/commandline.rb, line 133
133: def reset(arguments, options)
134: options[:persistence] ||= Persistence.new
135: options[:persistence].clear
136: end
Run the tests and display information about them.
:format => String - the formatter :interactive => Boolean - activate interactive mode (drops into irb on failure/error) :verbose => Boolean - provide verbose output
# File lib/baretest/commandline.rb, line 36
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
Detailed information about the selectors available to run‘s arguments.
# File lib/baretest/commandline.rb, line 199
199: def selectors(arguments, options)
200: colors = $stdout.tty?
201:
202: description = "\\e[1mSELECTORS\\e[0m\n\n\\e[1mDescription\\e[0m\nSelectors are used to identify what tests to run. Baretest knows 3 kinds of\nselectors: globs, tags and last-run-states. All of these can be preceeded\nwith a minus sign (-), to negate the expression.\nBeware that you must use negated expressions only after a -- separator,\nas otherwise baretest will try to interpret them as short options (like -f).\n\n\\e[1mExample\\e[0m\n`baretest -- test/suite -test/suite/foo :a -:b %failure -%pending`\n\nThis will run all tests that\n* Are in the directory test/suite or any of its subdirectories\n* Are NOT in the directory test/suite/foo, or any of its subdirectories\n* Have the tag 'a'\n* Do NOT have the tag 'b'\n* Terminated with a failure status on the last run\n* Did NOT terminate with a pending status on the last run\n\n\\e[1mGlobs\\e[0m\n* '**' recursively matches all files and directories\n* '*' wildcard, matches any amount of any character\n* '?' wildcard, matches one character\n* '{a,b,c}' alternation, matches any pattern in the comma separated list\n* Directories are equivalent to `directory/**/*` patterns\n\n\\e[1mTags\\e[0m\nTags are preceeded with a ':'.\nExamples:\nbaretest :focus\nbaretest -- -:hocus\nbaretest -- :focus :important -:irrelevant -:obsolete\n\n\\e[1mLast-run-status\\e[0m\nLast run states are preceeded with a %.\n* %new, %success, %failure, %error, %skipped, %pending\n* %error, %skipped and %pending are a subset of %failure\n* %pending is a subset of %skipped\n* %new matches tests that are run for the very first time\n\n".gsub(/^ {8}/, '') # |<- 80 cols ends here
203:
204: description.gsub!(/\e.*?m/, '') unless colors
205:
206: puts description
207: end