add 'skip_test'

This commit is contained in:
Johan Holmberg 2016-10-31 00:32:33 +01:00
parent 02c45f4ac9
commit 12f905a31b
7 changed files with 74 additions and 6 deletions

View File

@ -62,6 +62,10 @@ module Cmdtest
process_item [:assert_success] process_item [:assert_success]
end end
def test_skipped(str)
process_item [:test_skipped, str]
end
def assert_failure(str) def assert_failure(str)
process_item [:assert_failure, str] process_item [:assert_failure, str]
end end
@ -103,6 +107,8 @@ module Cmdtest
case cmd case cmd
when :assert_success when :assert_success
# nothing # nothing
when :test_skipped
_distribute("test_skipped", rest)
when :assert_failure when :assert_failure
_distribute("assert_failure", rest) _distribute("assert_failure", rest)
when :assert_error when :assert_error
@ -185,6 +191,10 @@ module Cmdtest
clog.assert_success clog.assert_success
runner.method_filter.success(method_id) runner.method_filter.success(method_id)
ok = true ok = true
rescue Cmdtest::TestSkipped => e
obj.teardown
clog.test_skipped(e.message)
runner.method_filter.failure(method_id)
rescue Cmdtest::AssertFailed => e rescue Cmdtest::AssertFailed => e
obj.teardown obj.teardown
clog.assert_failure(e.message) clog.assert_failure(e.message)
@ -418,6 +428,7 @@ module Cmdtest
"classes" => error_logger.n_classes, "classes" => error_logger.n_classes,
"methods" => error_logger.n_methods, "methods" => error_logger.n_methods,
"commands" => error_logger.n_commands, "commands" => error_logger.n_commands,
"skipped" => error_logger.n_skipped,
"failures" => error_logger.n_failures, "failures" => error_logger.n_failures,
"errors" => error_logger.n_errors, "errors" => error_logger.n_errors,
} }
@ -462,6 +473,7 @@ module Cmdtest
"classes" => error_logger.n_classes, "classes" => error_logger.n_classes,
"methods" => error_logger.n_methods, "methods" => error_logger.n_methods,
"commands" => error_logger.n_commands, "commands" => error_logger.n_commands,
"skipped" => error_logger.n_skipped,
"failures" => error_logger.n_failures, "failures" => error_logger.n_failures,
"errors" => error_logger.n_errors, "errors" => error_logger.n_errors,
} }
@ -487,11 +499,12 @@ module Cmdtest
puts "###" puts "###"
puts "### Finished: %s, Elapsed: %02d:%02d:%02d" % [Time.now.strftime("%F %T"), h,m,s] puts "### Finished: %s, Elapsed: %02d:%02d:%02d" % [Time.now.strftime("%F %T"), h,m,s]
puts puts
puts "%s %d test classes, %d test methods, %d commands, %d errors, %d fatals." % [ puts "%s %d test classes, %d test methods, %d commands, %d skipped, %d errors, %d fatals." % [
summary["failures"] == 0 && summary["errors"] == 0 ? "###" : "---", summary["failures"] == 0 && summary["errors"] == 0 ? "###" : "---",
summary["classes"], summary["classes"],
summary["methods"], summary["methods"],
summary["commands"], summary["commands"],
summary["skipped"],
summary["failures"], summary["failures"],
summary["errors"], summary["errors"],
] ]

View File

@ -56,6 +56,9 @@ module Cmdtest
def cmdline(method, comment) def cmdline(method, comment)
end end
def test_skipped(str)
end
def assert_failure(str) def assert_failure(str)
end end
@ -69,6 +72,7 @@ module Cmdtest
attr_reader :n_suites, :n_files, :n_classes attr_reader :n_suites, :n_files, :n_classes
attr_reader :n_methods, :n_commands, :n_failures, :n_errors attr_reader :n_methods, :n_commands, :n_failures, :n_errors
attr_reader :n_skipped
def initialize(opts) def initialize(opts)
super super
@ -78,6 +82,7 @@ module Cmdtest
@n_classes = 0 @n_classes = 0
@n_methods = 0 @n_methods = 0
@n_commands = 0 @n_commands = 0
@n_skipped = 0
@n_failures = 0 @n_failures = 0
@n_errors = 0 @n_errors = 0
end end
@ -102,6 +107,10 @@ module Cmdtest
@n_commands += 1 @n_commands += 1
end end
def test_skipped(msg)
@n_skipped += 1
end
def assert_failure(msg) def assert_failure(msg)
@n_failures += 1 @n_failures += 1
end end

View File

@ -51,6 +51,10 @@ module Cmdtest
end end
end end
def test_skipped(str)
puts str.gsub(/^/, "--- ")
end
def assert_failure(str) def assert_failure(str)
puts str.gsub(/^/, "--- ") puts str.gsub(/^/, "--- ")
end end

View File

@ -70,7 +70,7 @@ module Cmdtest
#---------- #----------
class ErrTestcase < Testcase class ProblemTestcase < Testcase
def initialize(classname, name, message, type, text) def initialize(classname, name, message, type, text)
@classname = classname @classname = classname
@ -85,10 +85,12 @@ module Cmdtest
@classname, @classname,
@name, @name,
] ]
f.put ' <failure message="%s" type="%s">%s</failure>', [ f.put ' <%s message="%s" type="%s">%s</%s>', [
xml_tag,
@message, @message,
@type, @type,
@text, @text,
xml_tag,
] ]
f.put ' </testcase>' f.put ' </testcase>'
end end
@ -96,6 +98,20 @@ module Cmdtest
#---------- #----------
class ErrTestcase < ProblemTestcase
def xml_tag
"failure"
end
end
class SkipTestcase < ProblemTestcase
def xml_tag
"skipped"
end
end
#----------
class Testsuite class Testsuite
def initialize(package, name) def initialize(package, name)
@ -116,10 +132,17 @@ module Cmdtest
testcase testcase
end end
def skip_testcase(classname, name, message, type, text)
testcase = SkipTestcase.new(classname, name, message, type, text)
@testcases << testcase
testcase
end
def write(f) def write(f)
f.put ' <testsuite errors="%d" failures="%d" name="%s" tests="%d" package="%s">', [ f.put ' <testsuite errors="%d" failures="%d" skipped="%d" name="%s" tests="%d" package="%s">', [
0, 0,
@testcases.grep(ErrTestcase).size, @testcases.grep(ErrTestcase).size,
@testcases.grep(SkipTestcase).size,
@name, @name,
@testcases.size, @testcases.size,
@package, @package,

View File

@ -41,10 +41,16 @@ module Cmdtest
def testmethod_begin(method) def testmethod_begin(method)
@err_assertions = [] @err_assertions = []
@err_skip = nil
end end
def testmethod_end(method) def testmethod_end(method)
if @err_assertions.size > 0 if @err_skip != nil
message = @err_skip.split(/\n/)[0]
type = "skip"
text = @err_skip
@ts.skip_testcase(_xml_class, method, message, type, text)
elsif @err_assertions.size > 0
message = @err_assertions[0].split(/\n/)[0] message = @err_assertions[0].split(/\n/)[0]
type = "assert" type = "assert"
text = @err_assertions.join text = @err_assertions.join
@ -58,6 +64,10 @@ module Cmdtest
"CMDTEST." + @testcase_class_name "CMDTEST." + @testcase_class_name
end end
def test_skipped(str)
@err_skip = str
end
def assert_failure(str) def assert_failure(str)
@err_assertions << str @err_assertions << str
end end

View File

@ -28,6 +28,7 @@ require "cmdtest/lcs"
module Cmdtest module Cmdtest
class AssertFailed < RuntimeError ; end class AssertFailed < RuntimeError ; end
class TestSkipped < RuntimeError ; end
class UsageError < RuntimeError ; end class UsageError < RuntimeError ; end
# Base class for testcases. # Base class for testcases.
@ -357,6 +358,14 @@ module Cmdtest
#------------------------------ #------------------------------
def skip_test(reason)
_process_after do
raise TestSkipped, "SKIP: " + reason
end
end
#------------------------------
def exit_zero def exit_zero
_process_after do _process_after do
@_checked_status = true @_checked_status = true

View File

@ -39,7 +39,7 @@ class CMDTEST_options < Cmdtest::Testcase
stdout_equal /.===== CMDTEST_foo.rb/ stdout_equal /.===== CMDTEST_foo.rb/
stdout_equal /.----- CMDTEST_foo1$/ stdout_equal /.----- CMDTEST_foo1$/
stdout_equal /.\.\.\.\.\. test_foo1$/ stdout_equal /.\.\.\.\.\. test_foo1$/
stdout_equal /test methods, \d+ commands, \d+ errors,/ stdout_equal /test methods, \d+ commands, \d+ skipped, \d+ errors,/
end end
end end