metasploit-framework/test/lib/module_test.rb

63 lines
1.1 KiB
Ruby
Raw Normal View History

2012-03-01 23:30:37 +00:00
module Msf
2012-03-01 23:30:37 +00:00
module ModuleTest
attr_accessor :tests
attr_accessor :failures
def initialize(info={})
@tests = 0
@failures = 0
super
end
def run_all_tests
tests = self.methods.select { |m| m.to_s =~ /^test_/ }
tests.each { |test_method|
self.send(test_method)
}
end
2012-03-01 23:30:37 +00:00
def it(msg="", &block)
@tests += 1
2012-03-01 23:30:37 +00:00
begin
result = block.call
unless result
print_error("FAILED: #{msg}")
print_error("FAILED: #{error}") if error
@failures += 1
2012-03-01 23:30:37 +00:00
return
end
rescue ::Exception => e
print_error("FAILED: #{msg}")
print_error("Exception: #{e.class} : #{e}")
return
end
print_good("#{msg}")
end
end
module ModuleTest::PostTest
include ModuleTest
def run
print_status("Running against session #{datastore["SESSION"]}")
print_status("Session type is #{session.type}")
print_status("Session platform is #{session.platform}")
2012-03-01 23:30:37 +00:00
@tests = 0; @failures = 0
run_all_tests
2012-03-01 23:30:37 +00:00
vprint_status("Testing complete.")
if (@failures > 0)
print_error("Passed: #{@tests - @failures}; Failed: #{@failures}")
else
print_status("Passed: #{@tests - @failures}; Failed: #{@failures}")
end
end
end
end