Skip to content

Commit

Permalink
Add support for Verbose level (#33)
Browse files Browse the repository at this point in the history
- `-v`  Show debug info and each test output
- `-vv` Show STDOUT from each test execution

Signed-off-by: Aravinda Vishwanathapura <[email protected]>
  • Loading branch information
aravindavk authored Dec 18, 2022
1 parent 240ec68 commit a79597b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 43 deletions.
33 changes: 0 additions & 33 deletions docs/keywords.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -245,36 +245,3 @@ end
----

*Note*: Load path is relative to the current directory from where the `binnacle` command is called.

== Emit Stdout

Some times printing the `STDOUT` output in test report gives better understanding of the Test case.

[source,ruby]
----
TEST "command 1"
# On setting this all future tests will use this setting
EMIT_STDOUT true
TEST "command 2"
# Only use this setting for some commands
EMIT_STDOUT true do
TEST "command 3"
TEST "command 4"
end
----

Example output of `TEST "stat /var/www/html/index.html"`

----
# File: /var/www/html/index.html
# Size: 13 Blocks: 8 IO Block: 4096 regular file
# Device: 10307h/66311d Inode: 4325842 Links: 1
# Access: (0664/-rw-rw-r--) Uid: ( 1000/aravinda) Gid: ( 1000/aravinda)
# Access: 2022-06-17 13:11:52.807419056 +0530
# Modify: 2022-06-17 13:11:52.807419056 +0530
# Change: 2022-06-17 13:11:52.807419056 +0530
# Birth: -
ok 1 - node=local cmd="TEST stat /var/www/html/index.html"
----
2 changes: 2 additions & 0 deletions docs/quick-start.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ OK 1 1 0 0 0 0

Result: Pass
----

Use `-v` two times to show the output of each commands.
22 changes: 12 additions & 10 deletions src/binnacle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ def self.tests_count(test_file)

def self.run(test_file, total_tests, opts)
# First line TAP output
if opts.verbose
if opts.verbose > 0
puts
puts
STDERR.puts "------- STARTED(tests=#{total_tests}, file=\"#{test_file}\")"
end

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

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

passed = 0
skipped = 0
Expand Down Expand Up @@ -90,7 +91,7 @@ def self.run(test_file, total_tests, opts)
end

# Print output/error only in verbose mode
puts(line.start_with?("#") ? line : "# #{line}") if opts.verbose
puts(line.start_with?("#") ? line : "# #{line}") if opts.verbose > 0
end

# Print the last Test status
Expand All @@ -101,7 +102,7 @@ def self.run(test_file, total_tests, opts)
if status.success?
skipped = total_tests - (passed + failed)
else
STDERR.puts "# Failed to execute" if opts.verbose
STDERR.puts "# Failed to execute" if opts.verbose > 0
end
end

Expand Down Expand Up @@ -210,7 +211,7 @@ def self.run_all(options)
metrics = Metrics.new

# Indexing: Collect number of tests from each test file
STDERR.print "Indexing test files... " if options.verbose
STDERR.print "Indexing test files... " if options.verbose > 0

index_errors = []
tfiles.each do |test_file|
Expand All @@ -225,7 +226,7 @@ def self.run_all(options)
end
end

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

# Test file summary if -vv is provided
testfile_summary(metrics.file(test_file)) if options.verbose
testfile_summary(metrics.file(test_file)) if options.verbose > 0
end

puts
Expand All @@ -249,7 +250,7 @@ def self.run_all(options)
puts "============================================================================================"

# Show full summary if -v
verbose_summary(metrics) if options.verbose
verbose_summary(metrics) if options.verbose > 0

# Final Table Summary
summary(metrics)
Expand Down Expand Up @@ -279,15 +280,15 @@ def self.run_all(options)

def self.args
args = Options.new("binnacle - Simple Test Framework")
args.verbose = false
args.verbose = 0
args.runner = false
args.result_json = ""

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

opts.on("-v", "--verbose", "Verbose output") do
args.verbose = true
args.verbose += 1
end

opts.on("-r", "--runner", "Run the tests") do
Expand Down Expand Up @@ -330,6 +331,7 @@ def self.args
if options.runner
include BinnacleTestPlugins
BinnacleTestsRunner.dry_run = options.dry_run
BinnacleTestsRunner.emit_stdout = true if options.verbose > 1

begin
load File.expand_path(options.test_file)
Expand Down

0 comments on commit a79597b

Please sign in to comment.