From 7f9a7f83684abc7e8eaea8d2f73ed4a3d942f132 Mon Sep 17 00:00:00 2001 From: Derek Abdine Date: Sun, 5 Dec 2021 13:51:53 -0800 Subject: [PATCH 1/4] Resolve #389: Add line numbers to recog_verify output --- lib/recog/fingerprint.rb | 7 +++++++ lib/recog/verifier.rb | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/recog/fingerprint.rb b/lib/recog/fingerprint.rb index d6ce4180..af696eb4 100644 --- a/lib/recog/fingerprint.rb +++ b/lib/recog/fingerprint.rb @@ -28,6 +28,12 @@ class Fingerprint # @return (see #parse_examples) attr_reader :tests + # The line number of the XML entity in the source file for this + # fingerprint. + # + # @return [Integer] The line number of this entity. + attr_reader :line + # @param xml [Nokogiri::XML::Element] # @param match_key [String] See Recog::DB # @param protocol [String] Protocol such as ftp, mssql, http, etc. @@ -37,6 +43,7 @@ def initialize(xml, match_key=nil, protocol=nil, filepath=nil) @protocol = protocol @name = parse_description(xml) @regex = create_regexp(xml) + @line = xml.line @params = {} @tests = [] diff --git a/lib/recog/verifier.rb b/lib/recog/verifier.rb index 4cb0606f..bdb070fa 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: #{message}" + reporter.warning "WARN (line #{fp.line}): #{message}" when :fail - reporter.failure "FAIL: #{message}" + reporter.failure "FAIL (line #{fp.line}): #{message}" 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: #{message}" + reporter.warning "WARN (line #{fp.line}): #{message}" when :fail - reporter.failure "FAIL: #{message}" + reporter.failure "FAIL (line #{fp.line}): #{message}" when :success reporter.success(message) end From d390f996299fc49c29e670d91b41b76d8009aa52 Mon Sep 17 00:00:00 2001 From: Derek Abdine Date: Sun, 5 Dec 2021 14:07:33 -0800 Subject: [PATCH 2/4] #389 - also update cucumber scenarios --- features/verify.feature | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/features/verify.feature b/features/verify.feature index 13459103..d221199c 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: 'Pure-FTPd' has no test cases - tests_with_warnings.xml: WARN: 'Pure-FTPd' is missing an example that checks for parameter 'pureftpd.config' which is derived from a capture group + 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: 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: 'foo test' failed to match "bar" with (?-mix:^foo$)' - tests_with_failures.xml: FAIL: '' failed to match "This almost matches" with (?-mix:^This matches$)' - tests_with_failures.xml: FAIL: 'bar test's os.name is a non-zero pos but specifies a value of 'Bar' - tests_with_failures.xml: FAIL: 'bar test' failed to find expected capture group os.version '5.0'. Result was 1.0 + 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: SUMMARY: Test completed with 0 successful, 0 warnings, and 4 failures """ And the exit status should be 4 From b465f05e7ed60a2a9bec1b2eab5ddf853ce18091 Mon Sep 17 00:00:00 2001 From: Derek Abdine Date: Mon, 6 Dec 2021 15:11:05 -0800 Subject: [PATCH 3/4] 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 From 56a253d4693dc492e68f7b3bece1c2d33997088b Mon Sep 17 00:00:00 2001 From: Derek Abdine Date: Thu, 9 Dec 2021 18:25:49 +0000 Subject: [PATCH 4/4] Disable tests under JRuby for now --- Rakefile | 6 +++++- features/verify.feature | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 9508482b..6cbf9569 100644 --- a/Rakefile +++ b/Rakefile @@ -14,8 +14,12 @@ end require 'cucumber' require 'cucumber/rake/task' +def jruby? + defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" +end + Cucumber::Rake::Task.new(:features) do |t| - t.cucumber_opts = "features --format pretty" + t.cucumber_opts = "features --format pretty" + (jruby? ? " --tags 'not @jruby-disabled'" : "") end task :default => [ :tests, :yard ] diff --git a/features/verify.feature b/features/verify.feature index 66c5b79f..77b63a7a 100644 --- a/features/verify.feature +++ b/features/verify.feature @@ -15,7 +15,10 @@ Feature: Verify successful_tests.xml: SUMMARY: Test completed with 4 successful, 0 warnings, and 0 failures """ + # This test is diabled in JRuby because JRuby does not number lines correctly, whereas + # CRuby does. See https://github.com/sparklemotion/nokogiri/issues/2380 @no-clobber + @jruby-disabled Scenario: Tests with warnings, warnings enabled When I run `recog_verify tests_with_warnings.xml` Then it should fail with: @@ -34,7 +37,10 @@ Feature: Verify tests_with_warnings.xml: SUMMARY: Test completed with 1 successful, 0 warnings, and 0 failures """ + # This test is diabled in JRuby because JRuby does not number lines correctly, whereas + # CRuby does. See https://github.com/sparklemotion/nokogiri/issues/2380 @no-clobber + @jruby-disabled Scenario: Tests with failures When I run `recog_verify tests_with_failures.xml` Then it should fail with: