Skip to content

Commit

Permalink
Show the list of failed tests in the end (#32)
Browse files Browse the repository at this point in the history
Fixes: #31
Signed-off-by: Aravinda Vishwanathapura <[email protected]>
  • Loading branch information
aravindavk authored Jul 9, 2022
1 parent 3051a07 commit bf2acf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
24 changes: 20 additions & 4 deletions src/binnacle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ def self.run(test_file, total_tests, opts)
STDERR.puts "------- STARTED(tests=#{total_tests}, file=\"#{test_file}\")"
end

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

cmd = "ruby #{__FILE__} #{test_file} --runner"

passed = 0
skipped = 0
failed = 0
failed_tests = []
Open3.popen2e(cmd) do |stdin, stdout_and_stderr, wait_thr|
outlines = []
summary_line = ""
Expand All @@ -83,6 +84,7 @@ def self.run(test_file, total_tests, opts)
next
elsif line.start_with?("not ok")
summary_line = line
failed_tests << line.strip
failed += 1
next
end
Expand All @@ -103,7 +105,7 @@ def self.run(test_file, total_tests, opts)
end
end

[passed, failed, skipped]
[passed, failed, skipped, failed_tests]
end

def self.test_files(test_file)
Expand Down Expand Up @@ -186,6 +188,18 @@ def self.summary(metrics)
"Failed=#{metrics.failed_files}")
end

def self.failed_tests_summary(metrics)
failed_test_data = ""
metrics.files.each do |tfile|
failed_test_data += "%s\n" % tfile[:file] if tfile[:failed_tests].size > 0
tfile[:failed_tests].each do |failed_test|
failed_test_data += " %s\n" % failed_test
end
end
puts "\n\nFailed Tests:" if failed_test_data != ""
puts failed_test_data
end

def self.run_all(options)
tfiles = test_files(options.test_file)
if tfiles.size == 0
Expand Down Expand Up @@ -221,9 +235,9 @@ def self.run_all(options)
metrics.files.each do |tfile|
test_file = tfile[:file]
t1 = Time.now
passed, failed, skipped = run(test_file, tfile[:total], options)
passed, failed, skipped, failed_tests = run(test_file, tfile[:total], options)
dur = Time.now - t1
metrics.file_completed(test_file, passed, failed, skipped, dur)
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
Expand All @@ -240,6 +254,8 @@ def self.run_all(options)
# Final Table Summary
summary(metrics)

failed_tests_summary(metrics)

if options.result_json != ""
File.open(options.result_json, "w") do |json_file|
json_file.write(metrics.to_json)
Expand Down
6 changes: 4 additions & 2 deletions src/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def file_add(test_file, count, index_duration_seconds)
:ok => false,
:duration_seconds => 0.0,
:speed_tpm => 0,
:index_duration_seconds => index_duration_seconds
:index_duration_seconds => index_duration_seconds,
:failed_tests => []
}

# Return the index of this file
Expand All @@ -65,7 +66,7 @@ def failed_files
@total_files - @passed_files
end

def file_completed(test_file, passed, failed, skipped, duration_seconds)
def file_completed(test_file, passed, failed, skipped, duration_seconds, failed_tests)
idx = @files_index[test_file]
@files[idx][:passed] = passed
@files[idx][:duration_seconds] = duration_seconds
Expand All @@ -75,6 +76,7 @@ def file_completed(test_file, passed, failed, skipped, duration_seconds)
@files[idx][:failed] = failed
@files[idx][:skipped] = skipped
@files[idx][:ok] = @files[idx][:total] == passed
@files[idx][:failed_tests] = failed_tests

@passed += passed
@failed += failed
Expand Down

0 comments on commit bf2acf1

Please sign in to comment.