updated msf test libraries
git-svn-id: file:///home/svn/framework3/trunk@10827 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
fc3df2303a
commit
54d659493d
|
@ -1,31 +1,29 @@
|
||||||
## This class consists of assert helper methods for regexing logs
|
## This class consists of assert helper methods for regexing logs
|
||||||
##
|
##
|
||||||
## $id$
|
## $Id$
|
||||||
|
|
||||||
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
||||||
|
|
||||||
require 'regexr'
|
require 'regexr'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
class MsfTest < Test::Unit::TestCase
|
class MsfTestCase < Test::Unit::TestCase
|
||||||
|
|
||||||
def setup
|
|
||||||
super
|
|
||||||
@case_insensitive = true
|
|
||||||
@regexr = Regexr.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_complete(data,first,last)
|
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_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
|
assert_not_nil @regexr.verify_end(data,last), "The end string " + data.split("\n").last + " did not match the expected string: " + last
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_all_successes(data, regex_strings)
|
def assert_all_successes(data, regex_strings)
|
||||||
|
@regexr = Regexr.new
|
||||||
regex_strings.each { |regex_string|
|
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."
|
assert_true @regexr.ensure_exists_in_data(data,regex_string), "The string " + regex_string + " was not found in the data."
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_no_failures(data, regex_strings, exception_strings)
|
def assert_no_failures(data, regex_strings, exception_strings)
|
||||||
|
@regexr = Regexr.new
|
||||||
regex_strings.each { |regex_string|
|
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."
|
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."
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,22 @@
|
||||||
##
|
##
|
||||||
## TODO - clean up the style. looks like it was written in the early 90s
|
## TODO - clean up the style. looks like it was written in the early 90s
|
||||||
##
|
##
|
||||||
## $id$
|
## $Id$
|
||||||
|
|
||||||
class Regexr
|
class Regexr
|
||||||
|
|
||||||
def initialize(verbose=false)
|
def initialize(verbose=false, case_insensitive=true)
|
||||||
@verbose = verbose
|
@verbose = verbose
|
||||||
|
@case_insensitive = case_insensitive
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check for the beginning line. Handy when you need to ensure a log has started
|
# Check for the beginning line. Handy when you need to ensure a log has started
|
||||||
def verify_start(data,the_start)
|
def verify_start(data,the_start)
|
||||||
data_lines = data.split("\n")
|
data_lines = data.split("\n")
|
||||||
regex_start = Regexp.new(the_start, @case_insensitive)
|
regex_start = Regexp.new(the_start, @case_insensitive)
|
||||||
|
if @verbose
|
||||||
|
puts "testing: " + the_start + " =~ " + data_lines.first
|
||||||
|
end
|
||||||
return regex_start =~ data_lines.first
|
return regex_start =~ data_lines.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -21,6 +25,9 @@ class Regexr
|
||||||
def verify_end(data,the_end)
|
def verify_end(data,the_end)
|
||||||
data_lines = data.split("\n")
|
data_lines = data.split("\n")
|
||||||
regex_end = Regexp.new(the_end, @case_insensitive)
|
regex_end = Regexp.new(the_end, @case_insensitive)
|
||||||
|
if @verbose
|
||||||
|
puts "testing: " + the_end + " =~ " + data_lines.last
|
||||||
|
end
|
||||||
return regex_end =~ data_lines.last
|
return regex_end =~ data_lines.last
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,12 +35,15 @@ class Regexr
|
||||||
def verify_start_and_end(data,the_start,the_end)
|
def verify_start_and_end(data,the_start,the_end)
|
||||||
data_lines = data.split("\n")
|
data_lines = data.split("\n")
|
||||||
regex_start = Regexp.new(the_start, @case_insensitive)
|
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
|
if regex_start =~ data_lines.first
|
||||||
return regex_endline == data_lines.last
|
return regex_end =~ data_lines.last
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -68,14 +78,12 @@ class Regexr
|
||||||
end
|
end
|
||||||
|
|
||||||
# Scan for a fail line. In order to pass, the string must not exist in the data
|
# 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")
|
data_lines = data.split("\n")
|
||||||
re = Regexp.new(regex_string, @case_insensitive)
|
|
||||||
|
|
||||||
data_lines.each {|line|
|
data_lines.each {|line|
|
||||||
if line =~ re
|
if line =~ Regexp.new(regex_string, @case_insensitive)
|
||||||
exceptions.each { |exception|
|
exceptions.each { |exception|
|
||||||
if line =~ exception
|
if line =~ Regexp.new(exception, @case_insensitive)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
##
|
##
|
||||||
## Tests for the regexr library
|
## Tests for the regexr library
|
||||||
## $id$
|
## $Id$
|
||||||
|
|
||||||
$:.unshift(File.expand_path(File.dirname(__FILE__)) )
|
$:.unshift(File.expand_path(File.dirname(__FILE__)) )
|
||||||
|
|
Loading…
Reference in New Issue