Skip to content

Commit

Permalink
Update logging format (suggested by @mkienow-r7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dabdine committed Dec 6, 2021
1 parent d390f99 commit b465f05
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions features/verify.feature
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions lib/recog/verifier.rb
Expand Up @@ -15,19 +15,19 @@ 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
end
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
Expand Down
13 changes: 7 additions & 6 deletions lib/recog/verify_reporter.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit b465f05

Please sign in to comment.