Land #18110, Add namespaced test module logging

This commit is contained in:
dwelch-r7 2023-06-15 14:30:02 +01:00 committed by GitHub
commit cee72a81e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 2 deletions

View File

@ -35,17 +35,20 @@ module Msf
end
def it(msg = "", &block)
@current_it_msg = msg
@tests += 1
begin
result = block.call
unless result
print_error("FAILED: #{msg}")
print_error("FAILED: #{error}") if error
@failures += 1
print_error("FAILED: #{error}") if error
@current_it_msg = nil
print_error("FAILED: #{msg}")
return
end
rescue SkipTestError => e
@skipped += 1
@current_it_msg = nil
print_status("SKIPPED: #{msg} (#{e.message})")
rescue ::Exception => e
@failures += 1
@ -54,6 +57,8 @@ module Msf
dlog("Exception in testing - #{msg}")
dlog("Call stack: #{e.backtrace.join("\n")}")
return
ensure
@current_it_msg = nil
end
print_good("#{msg}")
@ -67,6 +72,22 @@ module Msf
def passed
@tests - @failures
end
# When printing to console, additionally prepend the current test name
[
:print,
:print_line,
:print_status,
:print_good,
:print_warning,
:print_error,
:print_bad,
].each do |method|
define_method(method) do |msg|
super(@current_it_msg ? "[#{@current_it_msg}] #{msg}" : msg)
end
end
end
module ModuleTest::PostTest