mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-11-05 14:57:30 +01:00
updated regex methods. i write buggy code.
git-svn-id: file:///home/svn/framework3/trunk@9885 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
parent
d4e5f17d62
commit
8737c7ddfd
@ -1,12 +1,14 @@
|
||||
class Test::Unit::TestCase
|
||||
|
||||
@case_insensitive = true
|
||||
|
||||
# All tests will scan for start and end lines. This ensures the task
|
||||
# actually completed and didn't hang, and that the start and end lines
|
||||
# are actually at the start and end of the task file.
|
||||
def scan_for_startend(data,thestart,theend)
|
||||
data_lines = data.split("\n")
|
||||
regex_start = Regexp.new(thestart)
|
||||
regex_endline = Regexp.new(theend)
|
||||
regex_start = Regexp.new(thestart, @case_insensitive)
|
||||
regex_endline = Regexp.new(theend, @case_insensitive)
|
||||
|
||||
assert_match regex_start, data_lines.first
|
||||
assert_match regex_endline, data_lines.last
|
||||
@ -15,7 +17,6 @@ class Test::Unit::TestCase
|
||||
# Tests can scan for any number of success lines. In order to pass,
|
||||
# all successes must match.
|
||||
def scan_for_successes(data,regexes)
|
||||
|
||||
data_lines = data.split("\n")
|
||||
if regexes
|
||||
success = false
|
||||
@ -23,10 +24,9 @@ class Test::Unit::TestCase
|
||||
count = 0
|
||||
regexes.each { |condition|
|
||||
matched = false
|
||||
re = Regexp.new(condition)
|
||||
re = Regexp.new(condition, @case_insensitive)
|
||||
data_lines.each {|line|
|
||||
if line =~ re
|
||||
puts re.to_s + " ... matched ... \'" + line + "\'"
|
||||
count += 1
|
||||
matched = true
|
||||
break
|
||||
@ -44,12 +44,12 @@ class Test::Unit::TestCase
|
||||
|
||||
# Tests may scan for failures -- if any failure matches, the test flunks.
|
||||
def scan_for_failures(data,regexes,exceptions)
|
||||
|
||||
data_lines = data.split("\n")
|
||||
if regexes
|
||||
failure = false
|
||||
regexes.each {|condition|
|
||||
re = Regexp.new(condition)
|
||||
## for each failure condition that we've been passed
|
||||
re = Regexp.new(condition, @case_insensitive)
|
||||
## we'll look at the whole doc
|
||||
data_lines.each {|line|
|
||||
if line =~ re
|
||||
## First check the exceptions to make sure that this wasn't among them.
|
||||
@ -57,20 +57,20 @@ class Test::Unit::TestCase
|
||||
## messages but have specific matched strings which we know are harmless.
|
||||
|
||||
## Guilty til proven innocent, assume it's not an exception
|
||||
not_excepted = true
|
||||
|
||||
guilty = true
|
||||
|
||||
## But let's check anyway
|
||||
not_excepted = exceptions.map { |exception|
|
||||
reg_exception = Regexp.new(exception)
|
||||
|
||||
exceptions.map { |exception|
|
||||
reg_exception = Regexp.new(exception, @case_insensitive)
|
||||
## if the exception matches here, we'll spare it
|
||||
if line =~ reg_exception
|
||||
return false
|
||||
if line =~ reg_exception
|
||||
guilty = false
|
||||
break
|
||||
end
|
||||
}
|
||||
|
||||
## If we didn't find an exception, we have to flunk. try again, kid.
|
||||
if not_excepted
|
||||
## If we didn't find an exception, we have to flunk. do not pass go.
|
||||
if guilty
|
||||
flunk "Saw failure condition '#{condition}' in #{line}; regex matched: #{re.inspect}"
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user