Skip to content

Commit a79597b

Browse files
authored
Add support for Verbose level (#33)
- `-v` Show debug info and each test output - `-vv` Show STDOUT from each test execution Signed-off-by: Aravinda Vishwanathapura <[email protected]>
1 parent 240ec68 commit a79597b

File tree

3 files changed

+14
-43
lines changed

3 files changed

+14
-43
lines changed

docs/keywords.adoc

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -245,36 +245,3 @@ end
245245
----
246246

247247
*Note*: Load path is relative to the current directory from where the `binnacle` command is called.
248-
249-
== Emit Stdout
250-
251-
Some times printing the `STDOUT` output in test report gives better understanding of the Test case.
252-
253-
[source,ruby]
254-
----
255-
TEST "command 1"
256-
257-
# On setting this all future tests will use this setting
258-
EMIT_STDOUT true
259-
TEST "command 2"
260-
261-
# Only use this setting for some commands
262-
EMIT_STDOUT true do
263-
TEST "command 3"
264-
TEST "command 4"
265-
end
266-
----
267-
268-
Example output of `TEST "stat /var/www/html/index.html"`
269-
270-
----
271-
# File: /var/www/html/index.html
272-
# Size: 13 Blocks: 8 IO Block: 4096 regular file
273-
# Device: 10307h/66311d Inode: 4325842 Links: 1
274-
# Access: (0664/-rw-rw-r--) Uid: ( 1000/aravinda) Gid: ( 1000/aravinda)
275-
# Access: 2022-06-17 13:11:52.807419056 +0530
276-
# Modify: 2022-06-17 13:11:52.807419056 +0530
277-
# Change: 2022-06-17 13:11:52.807419056 +0530
278-
# Birth: -
279-
ok 1 - node=local cmd="TEST stat /var/www/html/index.html"
280-
----

docs/quick-start.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ OK 1 1 0 0 0 0
6868

6969
Result: Pass
7070
----
71+
72+
Use `-v` two times to show the output of each commands.

src/binnacle.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ def self.tests_count(test_file)
4949

5050
def self.run(test_file, total_tests, opts)
5151
# First line TAP output
52-
if opts.verbose
52+
if opts.verbose > 0
5353
puts
5454
puts
5555
STDERR.puts "------- STARTED(tests=#{total_tests}, file=\"#{test_file}\")"
5656
end
5757

5858
return [0, 0, 0, []] if total_tests <= 0
5959

60-
cmd = "ruby #{__FILE__} #{test_file} --runner"
60+
cmd_verbose_opts = ((0...opts.verbose).map {|o| "-v"}).join(" ")
61+
cmd = "ruby #{__FILE__} #{test_file} --runner #{cmd_verbose_opts}"
6162

6263
passed = 0
6364
skipped = 0
@@ -90,7 +91,7 @@ def self.run(test_file, total_tests, opts)
9091
end
9192

9293
# Print output/error only in verbose mode
93-
puts(line.start_with?("#") ? line : "# #{line}") if opts.verbose
94+
puts(line.start_with?("#") ? line : "# #{line}") if opts.verbose > 0
9495
end
9596

9697
# Print the last Test status
@@ -101,7 +102,7 @@ def self.run(test_file, total_tests, opts)
101102
if status.success?
102103
skipped = total_tests - (passed + failed)
103104
else
104-
STDERR.puts "# Failed to execute" if opts.verbose
105+
STDERR.puts "# Failed to execute" if opts.verbose > 0
105106
end
106107
end
107108

@@ -210,7 +211,7 @@ def self.run_all(options)
210211
metrics = Metrics.new
211212

212213
# Indexing: Collect number of tests from each test file
213-
STDERR.print "Indexing test files... " if options.verbose
214+
STDERR.print "Indexing test files... " if options.verbose > 0
214215

215216
index_errors = []
216217
tfiles.each do |test_file|
@@ -225,7 +226,7 @@ def self.run_all(options)
225226
end
226227
end
227228

228-
if options.verbose
229+
if options.verbose > 0
229230
STDERR.puts "done. tests=#{metrics.total} " +
230231
"test_files=#{metrics.total_files} " +
231232
"duration_seconds=#{metrics.index_duration_seconds}"
@@ -240,7 +241,7 @@ def self.run_all(options)
240241
metrics.file_completed(test_file, passed, failed, skipped, dur, failed_tests)
241242

242243
# Test file summary if -vv is provided
243-
testfile_summary(metrics.file(test_file)) if options.verbose
244+
testfile_summary(metrics.file(test_file)) if options.verbose > 0
244245
end
245246

246247
puts
@@ -249,7 +250,7 @@ def self.run_all(options)
249250
puts "============================================================================================"
250251

251252
# Show full summary if -v
252-
verbose_summary(metrics) if options.verbose
253+
verbose_summary(metrics) if options.verbose > 0
253254

254255
# Final Table Summary
255256
summary(metrics)
@@ -279,15 +280,15 @@ def self.run_all(options)
279280

280281
def self.args
281282
args = Options.new("binnacle - Simple Test Framework")
282-
args.verbose = false
283+
args.verbose = 0
283284
args.runner = false
284285
args.result_json = ""
285286

286287
opt_parser = OptionParser.new do |opts|
287288
opts.banner = "Usage: binnacle [options] <testfile>"
288289

289290
opts.on("-v", "--verbose", "Verbose output") do
290-
args.verbose = true
291+
args.verbose += 1
291292
end
292293

293294
opts.on("-r", "--runner", "Run the tests") do
@@ -330,6 +331,7 @@ def self.args
330331
if options.runner
331332
include BinnacleTestPlugins
332333
BinnacleTestsRunner.dry_run = options.dry_run
334+
BinnacleTestsRunner.emit_stdout = true if options.verbose > 1
333335

334336
begin
335337
load File.expand_path(options.test_file)

0 commit comments

Comments
 (0)