metasploit-framework/test/lib/module_test.rb

69 lines
1.4 KiB
Ruby
Raw Permalink 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
begin
result = block.call
unless result
print_error("FAILED: #{msg}")
print_error("FAILED: #{error}") if error
@failures += 1
return
end
rescue ::Exception => e
print_error("FAILED: #{msg}")
print_error("Exception: #{e.class} : #{e}")
dlog("Exception in testing - #{msg}")
dlog("Call stack: #{e.backtrace.join("\n")}")
return
end
2012-03-01 23:30:37 +00:00
print_good("#{msg}")
end
def pending(msg="", &block)
print_status("PENDING: #{msg}")
end
2012-03-01 23:30:37 +00:00
end
module ModuleTest::PostTest
include ModuleTest
def run
print_status("Running against session #{datastore["SESSION"]}")
print_status("Session type is #{session.type} and platform is #{session.platform}")
2012-03-01 23:30:37 +00:00
t = Time.now
@tests = 0; @failures = 0
run_all_tests
2012-03-01 23:30:37 +00:00
vprint_status("Testing complete in #{Time.now - t}")
if (@failures > 0)
print_error("Passed: #{@tests - @failures}; Failed: #{@failures}")
else
print_status("Passed: #{@tests - @failures}; Failed: #{@failures}")
end
end
end
end