From 5eedd9ff3df2137009869b8a5ce1d6fecdc18103 Mon Sep 17 00:00:00 2001 From: Julian Simpson Date: Fri, 15 Feb 2019 10:09:01 +1300 Subject: [PATCH] Add testcase count to output Sometimes we like to verify that our tests are being executed. For example, we've had minor tooling changes cause test to stop being run. This commit adds a summary of the test cases found while parsing for failures. --- ruby/bin/annotate | 3 +++ ruby/tests/annotate_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/ruby/bin/annotate b/ruby/bin/annotate index 607c97b..202f34d 100755 --- a/ruby/bin/annotate +++ b/ruby/bin/annotate @@ -20,6 +20,7 @@ class Failure < Struct.new(:name, :failed_test, :body, :job, :type) end junit_report_files = Dir.glob(File.join(junits_dir, "**", "*")) +testcases = 0 failures = [] def text_content(element) @@ -41,6 +42,7 @@ junit_report_files.sort.each do |file| doc = REXML::Document.new(xml) REXML::XPath.each(doc, '//testsuite//testcase') do |testcase| + testcases += 1 name = testcase.attributes['name'].to_s failed_test = testcase.attributes[failure_format].to_s testcase.elements.each("failure") do |failure| @@ -53,6 +55,7 @@ junit_report_files.sort.each do |file| end STDERR.puts "--- ❓ Checking failures" +STDERR.puts "#{testcases} testcases found" if failures.empty? STDERR.puts "There were no failures/errors 🙌" diff --git a/ruby/tests/annotate_test.rb b/ruby/tests/annotate_test.rb index 62df764..083c40a 100644 --- a/ruby/tests/annotate_test.rb +++ b/ruby/tests/annotate_test.rb @@ -10,6 +10,7 @@ Parsing junit-2.xml Parsing junit-3.xml --- ❓ Checking failures + 8 testcases found There were no failures/errors 🙌 OUTPUT @@ -24,6 +25,7 @@ Parsing junit-2.xml Parsing junit-3.xml --- ❓ Checking failures + 6 testcases found There are 4 failures/errors 😭 --- ✍️ Preparing annotation 4 failures: @@ -108,6 +110,7 @@ Parsing junit-2.xml Parsing junit-3.xml --- ❓ Checking failures + 6 testcases found There are 4 failures/errors 😭 --- ✍️ Preparing annotation 2 failures and 2 errors: @@ -190,6 +193,7 @@ assert_equal <<~OUTPUT, output Parsing junit-123-456-custom-pattern.xml --- ❓ Checking failures + 2 testcases found There is 1 failure/error 😭 --- ✍️ Preparing annotation 1 failure: @@ -223,6 +227,7 @@ Parsing junit-2.xml Parsing junit-3.xml --- ❓ Checking failures + 6 testcases found There are 4 failures/errors 😭 --- ✍️ Preparing annotation 2 failures and 2 errors: @@ -307,6 +312,7 @@ Parsing sub-dir/junit-2.xml Parsing sub-dir/junit-3.xml --- ❓ Checking failures + 6 testcases found There are 4 failures/errors 😭 --- ✍️ Preparing annotation 4 failures: @@ -389,6 +395,7 @@ assert_equal <<~OUTPUT, output Parsing junit.xml --- ❓ Checking failures + 2 testcases found There is 1 failure/error 😭 --- ✍️ Preparing annotation 1 failure: @@ -408,6 +415,7 @@ assert_equal <<~OUTPUT, output Parsing junit.xml --- ❓ Checking failures + 2 testcases found There is 1 failure/error 😭 --- ✍️ Preparing annotation 1 error: