diff --git a/test/lib/msf_matchers.rb b/test/lib/msf_matchers.rb index ef4fcde5bd..4afd99b5f9 100644 --- a/test/lib/msf_matchers.rb +++ b/test/lib/msf_matchers.rb @@ -12,12 +12,13 @@ module MsfMatchers def matches?(data) @data = data - @actual = @r.find_strings_that_dont_exist_in_data(@data,@successes) - return true if !@actual + @string = @r.find_strings_that_dont_exist_in_data(@data,@successes) + return true if !@string + nil end def failure_message - "expected all successes, but didn't find '#{@actual}'" + "expected all successes, but didn't find '#{@string}'" end def negative_failure_message @@ -41,12 +42,13 @@ module MsfMatchers def matches?(data) @data = data - @actual = @r.find_strings_that_exist_in_data_except(@data,@failures,@exceptions) - return false if @actual + @string = @r.find_strings_that_exist_in_data_except(@data,@failures,@exceptions) + return true if !@string + nil end def failure_message - "expected no failure to be found, but found this: '#{@actual}'" + "expected no failure to be found, but found this: '#{@string}'" end def negative_falure_message diff --git a/test/lib/regexr.rb b/test/lib/regexr.rb index 2dce4312d4..aebc53ab6b 100644 --- a/test/lib/regexr.rb +++ b/test/lib/regexr.rb @@ -15,10 +15,6 @@ class Regexr def verify_start(data,the_start) data_lines = data.split("\n") regex_start = Regexp.new(the_start, @case_insensitive) - if @verbose - puts "Testing: " + the_start + " =~ " + data_lines.first - end - return regex_start =~ data_lines.first end @@ -26,9 +22,6 @@ class Regexr def verify_end(data,the_end) data_lines = data.split("\n") regex_end = Regexp.new(the_end, @case_insensitive) - if @verbose - puts "Testing: " + the_end + " =~ " + data_lines.last - end return regex_end =~ data_lines.last end @@ -37,12 +30,6 @@ class Regexr data_lines = data.split("\n") regex_start = Regexp.new(the_start, @case_insensitive) regex_end = Regexp.new(the_end, @case_insensitive) - - if @verbose - puts "Testing: " + the_start + " =~ " + data_lines.first - puts "Testing: " + the_end + " =~ " + data_lines.last - end - if regex_start =~ data_lines.first return regex_end =~ data_lines.last end @@ -53,16 +40,16 @@ class Regexr # Scan for any number of success lines. In order to pass, all successes must match. def find_strings_that_dont_exist_in_data(data,regexes=[]) data_lines = data.split("\n") + + return nil unless regexes ## count as a pass + if regexes target_successes = regexes.size success_count = 0 regexes.each { |condition| - if @verbose - puts "DEBUG: testing regex for existence: #{condition}" - end ## assume we haven't got it - matched = false + found = false re = Regexp.new(condition, @case_insensitive) @@ -71,26 +58,15 @@ class Regexr ## if it's a match if line =~ re - - if @verbose - puts "DEBUG: matched regex #{re.to_s}: with #{line}" - end - - ## and set matched properly - matched = true - - break ## greedy success! + found = true + break ## success! end } - if !matched + if !found return condition ## return this string, it wasn't found. end - - } - else - nil # No successes are defined, so count this as a pass (nil). end nil ## got all successes, woot! @@ -99,56 +75,37 @@ class Regexr # Scan for failures -- if any single failure matches, the test returns true. def find_strings_that_exist_in_data_except(data,regexes=[],exceptions=[]) data_lines = data.split("\n") - if regexes - regexes.each { |condition| - if @verbose - puts "DEBUG: testing regex for existence: #{condition}" - end + + return nil unless regexes ## count as a pass - ## for each failure condition that we've been passed - re = Regexp.new(condition, @case_insensitive) + regexes.each { |condition| - ## assume we're okay - match = false + ## for each failure condition that we've been passed + re = Regexp.new(condition, @case_insensitive) - data_lines.each { |line| + ## assume we're okay + found = false - if re =~ line + data_lines.each { |line| + if re =~ line + found = true # oh, we found a match - if @verbose - puts "DEBUG: matched #{re.to_s} in #{line}" - end - - match = true # oh, we found a match - - # but let's check the exceptions - exceptions.map { |exception| - reg_exception = Regexp.new(exception, @case_insensitive) + # but let's check the exceptions + exceptions.map { |exception| + reg_exception = Regexp.new(exception, @case_insensitive) - # If the exception matches here, we'll spare it - if reg_exception =~ line - if @verbose - puts "DEBUG: but #{line} is an exception, we can ignore it." - end - match = false - break - end - } - - # If we didn't find an exception, we have to fail it. do not pass go. - if match - if @verbose - puts "DEBUG: Saw failure condition '#{condition}' in #{line}; regex matched: #{re.inspect}. no exceptions found." - end - - return condition ## fail early + # If the exception matches here, we'll spare it + if reg_exception =~ line + found = false + break end - end - } + } + + # If we didn't find an exception, we have to fail it. do not pass go. + return condition if found + end } - else - nil # we gots no failures, so count this as a pass. - end + } nil ## no failures found! end