Module: BareTest::Run::CLI
- Extended by:
- Formatter
- Defined in:
- lib/baretest/run/cli.rb
Overview
CLI runner is invoked with ‘-f cli` or `–format cli`. It is intended for use with an interactive shell, to provide a comfortable, human readable output. It prints colored output (requires ANSI colors compatible terminal).
Constant Summary collapse
- Formats =
{ :pending => "\e[43m%9s\e[0m %s%s\n", :manually_skipped => "\e[43m%9s\e[0m %s%s\n", :dependency_missing => "\e[43m%9s\e[0m %s%s\n", :library_missing => "\e[43m%9s\e[0m %s%s\n", :component_missing => "\e[43m%9s\e[0m %s%s\n", :ignored => "\e[43m%9s\e[0m %s%s\n", :skipped => "\e[43m%9s\e[0m %s%s\n", :success => "\e[42m%9s\e[0m %s%s\n", :failure => "\e[41m%9s\e[0m %s%s\n", :error => "\e[37;40;1m%9s\e[0m %s%s\n" # ]]]]]]]]]]]]]]]]]]]] - bbedit hates open brackets... }
- StatusLabel =
]]]]]]]]]]]]]]]]]]]] - bbedit hates open brackets…
{ :pending => " Pending ", :manually_skipped => " Skipped ", :dependency_missing => " Skipped ", :library_missing => " Skipped ", :component_missing => " Skipped ", :ignored => " Skipped ", :skipped => " Skipped ", :success => " Success ", :failure => " Failure ", :error => " Error ", }
- Map =
{ :pending => :incomplete, :manually_skipped => :incomplete, :dependency_missing => :incomplete, :library_missing => :incomplete, :component_missing => :incomplete, :ignored => :incomplete, :skipped => :incomplete, :success => :success, :failure => :failure, :error => :error, }
{ :incomplete => "\e[43m%9s\e[0m\n", :success => "\e[42m%9s\e[0m\n", :failure => "\e[41m%9s\e[0m\n", :error => "\e[37;40;1m%9s\e[0m\n" # ]]]]]]]] - bbedit hates open brackets... }
Instance Attribute Summary
Attributes included from Formatter
Instance Method Summary collapse
- #clear_deferred ⇒ Object
-
#defer(*output) ⇒ Object
Add data to output, but mark it as deferred We defer in order to be able to ignore suites.
- #pop_deferred ⇒ Object
- #run_all(*args) ⇒ Object
- #run_suite(suite) ⇒ Object
- #run_test(assertion, setup) ⇒ Object
- #word_wrap(string, cols) ⇒ Object
Methods included from Formatter
env_option, extended, initialize_options, option, option_defaults, text
Instance Method Details
#clear_deferred ⇒ Object
158 159 160 161 |
# File 'lib/baretest/run/cli.rb', line 158 def clear_deferred puts *@deferred unless @deferred.empty? @deferred.clear end |
#defer(*output) ⇒ Object
Add data to output, but mark it as deferred We defer in order to be able to ignore suites. Ignored suites that contain unignored suites/assertions must be displayed, ignored suites that don’t, will be popped from the deferred-stack
150 151 152 |
# File 'lib/baretest/run/cli.rb', line 150 def defer(*output) @deferred.concat(output.compact) end |
#pop_deferred ⇒ Object
154 155 156 |
# File 'lib/baretest/run/cli.rb', line 154 def pop_deferred @deferred.pop end |
#run_all(*args) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/baretest/run/cli.rb', line 76 def run_all(*args) puts "Running all tests#{' verbosly' if @options[:verbose]}" @depth = 0 @deferred = [] start = Time.now rv = super # run all suites duration = Time.now-start status = global_status test, success, pending, manually_skipped, dependency_missing, library_missing, component_missing, ignored, skipped, failure, error = *@count.values_at(:test, :success, :pending, :manually_skipped, :dependency_missing, :library_missing, :component_missing, :ignored, :skipped, :failure, :error) printf "\n%2$d tests run in %1$.1fs\n%3$d successful, %4$d pending, %5$d skipped, %6$d failures, %7$d errors\n", duration, test, success, pending, (skipped+manually_skipped+ dependency_missing+library_missing+component_missing), failure, error print "Final status: " printf FooterFormats[Map[status]], StatusLabel[status] rv end |
#run_suite(suite) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/baretest/run/cli.rb', line 101 def run_suite(suite) return super unless suite.description indent = " #{' '*@depth}" skip_reason = suite.reason(:indent => indent+' ', :first_indent => indent+' Reason: ') case size = suite.assertions.size when 0 defer "\n#{indent}\e[1m#{suite.description}\e[0m", skip_reason when 1 defer "\n#{indent}\e[1m#{suite.description}\e[0m (1 test)", skip_reason else defer "\n#{indent}\e[1m#{suite.description}\e[0m (#{size} tests)", skip_reason end @depth += 1 rv = super(suite) # run the suite pop_deferred @depth -= 1 rv end |
#run_test(assertion, setup) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/baretest/run/cli.rb', line 123 def run_test(assertion, setup) clear_deferred rv = super # run the assertion indent = ' '+' '*@depth backtrace = [] reason = rv.reason(:indent => indent, :first_indent => indent+'Reason: ') printf(Formats[rv.status], StatusLabel[rv.status], ' '*@depth, interpolated_description(assertion, setup)) if rv.status == :error then backtrace = @options[:verbose] ? rv.exception.backtrace : rv.exception.backtrace.first(1) elsif rv.status == :failure backtrace = ["#{assertion.file}:#{assertion.line}"] end puts reason if reason backtrace.each do |line| print(indent, ' ', line, "\n") end rv end |
#word_wrap(string, cols) ⇒ Object
142 143 144 |
# File 'lib/baretest/run/cli.rb', line 142 def word_wrap(string, cols) str.scan(/[^ ]+ /) end |