updated msf test libraries

git-svn-id: file:///home/svn/framework3/trunk@10827 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Jonathan Cran 2010-10-26 06:05:24 +00:00
parent fc3df2303a
commit 54d659493d
3 changed files with 25 additions and 19 deletions

View File

@ -1,31 +1,29 @@
## This class consists of assert helper methods for regexing logs
##
## $id$
## $Id$
$:.unshift(File.expand_path(File.dirname(__FILE__)))
require 'regexr'
require 'test/unit'
class MsfTest < Test::Unit::TestCase
def setup
super
@case_insensitive = true
@regexr = Regexr.new
end
class MsfTestCase < Test::Unit::TestCase
def assert_complete(data,first,last)
@regexr = Regexr.new
assert_not_nil @regexr.verify_start(data,first), "The start string " + data.split("\n").first + " did not match the expected string: " + first
assert_not_nil @regexr.verify_end(data,last), "The end string " + data.split("\n").last + " did not match the expected string: " + last
end
def assert_all_successes(data, regex_strings)
@regexr = Regexr.new
regex_strings.each { |regex_string|
assert_true @regexr.ensure_exists_in_data(data,regex_string), "The string " + regex_string + " was not found in the data."
}
end
def assert_no_failures(data, regex_strings, exception_strings)
@regexr = Regexr.new
regex_strings.each { |regex_string|
assert_true @regexr.ensure_doesnt_exist_in_data_unless(data,regex_string,exception_strings), "The string " + regex_string + " was found in the the data, and no exception was found."
}

View File

@ -2,18 +2,22 @@
##
## TODO - clean up the style. looks like it was written in the early 90s
##
## $id$
## $Id$
class Regexr
def initialize(verbose=false)
def initialize(verbose=false, case_insensitive=true)
@verbose = verbose
@case_insensitive = case_insensitive
end
# Check for the beginning line. Handy when you need to ensure a log has started
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
@ -21,6 +25,9 @@ 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
@ -28,12 +35,15 @@ class Regexr
def verify_start_and_end(data,the_start,the_end)
data_lines = data.split("\n")
regex_start = Regexp.new(the_start, @case_insensitive)
regex_endline = Regexp.new(the_end, @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
## yuck, refactor this - TODO
if regex_start =~ data_lines.first
return regex_endline == data_lines.last
return regex_end =~ data_lines.last
end
return false
@ -68,14 +78,12 @@ class Regexr
end
# Scan for a fail line. In order to pass, the string must not exist in the data
def ensure_doesnt_exist_in_data_unless(data,regex_string, exceptions)
def ensure_doesnt_exist_in_data_unless(data, regex_string, exceptions)
data_lines = data.split("\n")
re = Regexp.new(regex_string, @case_insensitive)
data_lines.each {|line|
if line =~ re
if line =~ Regexp.new(regex_string, @case_insensitive)
exceptions.each { |exception|
if line =~ exception
if line =~ Regexp.new(exception, @case_insensitive)
return true
end
}

View File

@ -1,6 +1,6 @@
##
## Tests for the regexr library
## $id$
## $Id$
$:.unshift(File.expand_path(File.dirname(__FILE__)) )