Files
metasploit-gs/test/lib/module_test.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.7 KiB
Ruby
Raw Normal View History

module Msf
module ModuleTest
2013-09-30 13:47:53 -05:00
attr_accessor :tests
attr_accessor :failures
2022-04-28 15:06:43 +01:00
2022-09-08 12:42:39 -04:00
class SkipTestError < ::Exception
end
2013-09-30 13:47:53 -05:00
def initialize(info = {})
@tests = 0
@failures = 0
2022-04-28 15:06:43 +01:00
super
end
2012-03-01 16:30:37 -07:00
2013-09-30 13:47:53 -05:00
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 16:30:37 -07:00
2022-09-08 12:42:39 -04:00
def skip(msg = "No reason given")
raise SkipTestError, msg
end
2013-09-30 13:47:53 -05: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
2022-04-28 15:06:43 +01:00
return
end
2022-09-08 12:42:39 -04:00
rescue SkipTestError => e
print_status("SKIPPED: #{msg} (#{e.message})")
2013-09-30 13:47:53 -05:00
rescue ::Exception => e
print_error("FAILED: #{msg}")
2022-09-08 12:42:39 -04:00
print_error("Exception: #{e.class}: #{e}")
2013-09-30 13:47:53 -05:00
dlog("Exception in testing - #{msg}")
dlog("Call stack: #{e.backtrace.join("\n")}")
return
end
2012-03-01 16:30:37 -07:00
2013-09-30 13:47:53 -05:00
print_good("#{msg}")
end
2013-09-30 13:47:53 -05:00
def pending(msg = "", &block)
print_status("PENDING: #{msg}")
2022-04-28 15:06:43 +01:00
end
2013-09-30 13:47:53 -05:00
end
2012-03-01 16:30:37 -07:00
module ModuleTest::PostTest
2013-09-30 13:47:53 -05:00
include ModuleTest
2022-04-28 15:06:43 +01:00
def run
2013-09-30 13:47:53 -05:00
print_status("Running against session #{datastore["SESSION"]}")
print_status("Session type is #{session.type} and platform is #{session.platform}")
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
t = Time.now
@tests = 0; @failures = 0
run_all_tests
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05: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}")
2022-04-28 15:06:43 +01:00
end
2013-09-30 13:47:53 -05:00
end
end
end