From b465f05e7ed60a2a9bec1b2eab5ddf853ce18091 Mon Sep 17 00:00:00 2001 From: Derek Abdine Date: Mon, 6 Dec 2021 15:11:05 -0800 Subject: [PATCH] Update logging format (suggested by @mkienow-r7) --- features/verify.feature | 12 ++++++------ lib/recog/verifier.rb | 8 ++++---- lib/recog/verify_reporter.rb | 13 +++++++------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/features/verify.feature b/features/verify.feature index d221199c..66c5b79f 100644 --- a/features/verify.feature +++ b/features/verify.feature @@ -20,8 +20,8 @@ Feature: Verify When I run `recog_verify tests_with_warnings.xml` Then it should fail with: """ - tests_with_warnings.xml: WARN (line 10): 'Pure-FTPd' has no test cases - tests_with_warnings.xml: WARN (line 10): 'Pure-FTPd' is missing an example that checks for parameter 'pureftpd.config' which is derived from a capture group + tests_with_warnings.xml:10: WARN: 'Pure-FTPd' has no test cases + tests_with_warnings.xml:10: WARN: 'Pure-FTPd' is missing an example that checks for parameter 'pureftpd.config' which is derived from a capture group tests_with_warnings.xml: SUMMARY: Test completed with 1 successful, 2 warnings, and 0 failures """ And the exit status should be 2 @@ -39,10 +39,10 @@ Feature: Verify When I run `recog_verify tests_with_failures.xml` Then it should fail with: """ - tests_with_failures.xml: FAIL (line 3): 'foo test' failed to match "bar" with (?-mix:^foo$)' - tests_with_failures.xml: FAIL (line 8): '' failed to match "This almost matches" with (?-mix:^This matches$)' - tests_with_failures.xml: FAIL (line 13): 'bar test's os.name is a non-zero pos but specifies a value of 'Bar' - tests_with_failures.xml: FAIL (line 13): 'bar test' failed to find expected capture group os.version '5.0'. Result was 1.0 + tests_with_failures.xml:3: FAIL: 'foo test' failed to match "bar" with (?-mix:^foo$)' + tests_with_failures.xml:8: FAIL: '' failed to match "This almost matches" with (?-mix:^This matches$)' + tests_with_failures.xml:13: FAIL: 'bar test's os.name is a non-zero pos but specifies a value of 'Bar' + tests_with_failures.xml:13: FAIL: 'bar test' failed to find expected capture group os.version '5.0'. Result was 1.0 tests_with_failures.xml: SUMMARY: Test completed with 0 successful, 0 warnings, and 4 failures """ And the exit status should be 4 diff --git a/lib/recog/verifier.rb b/lib/recog/verifier.rb index bdb070fa..6034f9a2 100644 --- a/lib/recog/verifier.rb +++ b/lib/recog/verifier.rb @@ -15,9 +15,9 @@ def verify fp.verify_params do |status, message| case status when :warn - reporter.warning "WARN (line #{fp.line}): #{message}" + reporter.warning "WARN: #{message}", fp.line when :fail - reporter.failure "FAIL (line #{fp.line}): #{message}" + reporter.failure "FAIL: #{message}", fp.line when :success reporter.success(message) end @@ -25,9 +25,9 @@ def verify fp.verify_tests do |status, message| case status when :warn - reporter.warning "WARN (line #{fp.line}): #{message}" + reporter.warning "WARN: #{message}", fp.line when :fail - reporter.failure "FAIL (line #{fp.line}): #{message}" + reporter.failure "FAIL: #{message}", fp.line when :success reporter.success(message) end diff --git a/lib/recog/verify_reporter.rb b/lib/recog/verify_reporter.rb index 503f51e8..915829c5 100644 --- a/lib/recog/verify_reporter.rb +++ b/lib/recog/verify_reporter.rb @@ -24,15 +24,15 @@ def success(text) formatter.success_message("#{padding}#{text}") if detail? end - def warning(text) + def warning(text, line=nil) return unless @options.warnings @warning_count += 1 - formatter.warning_message("#{path_label}#{padding}#{text}") + formatter.warning_message("#{path_label(line)}#{padding}#{text}") end - def failure(text) + def failure(text, line=nil) @failure_count += 1 - formatter.failure_message("#{path_label}#{padding}#{text}") + formatter.failure_message("#{path_label(line)}#{padding}#{text}") end def print_name(fingerprint) @@ -65,9 +65,10 @@ def detail? @options.detail end - def path_label + def path_label(line=nil) unless detail? - @path.to_s.empty? ? "" : "#{@path}: " + line_label = line ? line.to_s + ":" : "" + @path.to_s.empty? ? "" : "#{@path}:#{line_label} " end end