2010-07-16 22:36:42 +00:00
|
|
|
class Test::Unit::TestCase
|
|
|
|
|
2010-07-20 06:38:29 +00:00
|
|
|
@case_insensitive = true
|
|
|
|
|
2010-07-16 22:36:42 +00:00
|
|
|
# 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.
|
2010-07-20 04:40:16 +00:00
|
|
|
def scan_for_startend(data,thestart,theend)
|
2010-07-16 22:36:42 +00:00
|
|
|
data_lines = data.split("\n")
|
2010-07-20 06:38:29 +00:00
|
|
|
regex_start = Regexp.new(thestart, @case_insensitive)
|
|
|
|
regex_endline = Regexp.new(theend, @case_insensitive)
|
2010-07-20 04:40:16 +00:00
|
|
|
|
2010-07-16 22:36:42 +00:00
|
|
|
assert_match regex_start, data_lines.first
|
|
|
|
assert_match regex_endline, data_lines.last
|
|
|
|
end
|
|
|
|
|
|
|
|
# Tests can scan for any number of success lines. In order to pass,
|
|
|
|
# all successes must match.
|
2010-07-20 04:40:16 +00:00
|
|
|
def scan_for_successes(data,regexes)
|
2010-07-16 22:36:42 +00:00
|
|
|
data_lines = data.split("\n")
|
2010-07-20 04:40:16 +00:00
|
|
|
if regexes
|
2010-07-16 22:36:42 +00:00
|
|
|
success = false
|
2010-07-20 04:40:16 +00:00
|
|
|
target_successes = regexes.size
|
2010-07-16 22:36:42 +00:00
|
|
|
count = 0
|
2010-07-20 04:40:16 +00:00
|
|
|
regexes.each { |condition|
|
2010-07-16 22:36:42 +00:00
|
|
|
matched = false
|
2010-07-20 06:38:29 +00:00
|
|
|
re = Regexp.new(condition, @case_insensitive)
|
2010-07-16 22:36:42 +00:00
|
|
|
data_lines.each {|line|
|
|
|
|
if line =~ re
|
|
|
|
count += 1
|
2010-07-20 04:40:16 +00:00
|
|
|
matched = true
|
2010-07-16 22:36:42 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
}
|
|
|
|
# A way to tell if a match was never found.
|
2010-07-20 04:40:16 +00:00
|
|
|
assert matched, "Didn't see success condition '#{condition}'"
|
|
|
|
|
2010-07-16 22:36:42 +00:00
|
|
|
}
|
|
|
|
assert_equal target_successes, count, "Didn't get enough successes, somehow.\n"
|
|
|
|
else
|
|
|
|
assert true # No successes are defined, so count this as a pass.
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Tests may scan for failures -- if any failure matches, the test flunks.
|
2010-07-20 04:40:16 +00:00
|
|
|
def scan_for_failures(data,regexes,exceptions)
|
2010-07-16 22:36:42 +00:00
|
|
|
data_lines = data.split("\n")
|
2010-07-20 04:40:16 +00:00
|
|
|
if regexes
|
|
|
|
regexes.each {|condition|
|
2010-07-20 06:38:29 +00:00
|
|
|
## for each failure condition that we've been passed
|
|
|
|
re = Regexp.new(condition, @case_insensitive)
|
|
|
|
## we'll look at the whole doc
|
2010-07-16 22:36:42 +00:00
|
|
|
data_lines.each {|line|
|
|
|
|
if line =~ re
|
2010-07-19 17:12:36 +00:00
|
|
|
## First check the exceptions to make sure that this wasn't among them.
|
|
|
|
## The reason for exceptions is that we may want to check for generic error
|
|
|
|
## messages but have specific matched strings which we know are harmless.
|
|
|
|
|
|
|
|
## Guilty til proven innocent, assume it's not an exception
|
2010-07-20 06:38:29 +00:00
|
|
|
guilty = true
|
|
|
|
|
2010-07-19 17:12:36 +00:00
|
|
|
## But let's check anyway
|
2010-07-20 06:38:29 +00:00
|
|
|
exceptions.map { |exception|
|
|
|
|
reg_exception = Regexp.new(exception, @case_insensitive)
|
2010-07-19 17:12:36 +00:00
|
|
|
## if the exception matches here, we'll spare it
|
2010-07-20 06:38:29 +00:00
|
|
|
if line =~ reg_exception
|
|
|
|
guilty = false
|
|
|
|
break
|
2010-07-19 17:12:36 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2010-07-20 06:38:29 +00:00
|
|
|
## If we didn't find an exception, we have to flunk. do not pass go.
|
|
|
|
if guilty
|
2010-07-20 04:40:16 +00:00
|
|
|
flunk "Saw failure condition '#{condition}' in #{line}; regex matched: #{re.inspect}"
|
2010-07-19 17:12:36 +00:00
|
|
|
end
|
2010-07-16 22:36:42 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-07-20 04:40:16 +00:00
|
|
|
assert true # No failures, so count this as a pass.
|
2010-07-16 22:36:42 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-19 17:12:36 +00:00
|
|
|
|
2010-07-16 22:36:42 +00:00
|
|
|
end
|