add 'skip_test'
This commit is contained in:
parent
02c45f4ac9
commit
12f905a31b
@ -62,6 +62,10 @@ module Cmdtest
|
||||
process_item [:assert_success]
|
||||
end
|
||||
|
||||
def test_skipped(str)
|
||||
process_item [:test_skipped, str]
|
||||
end
|
||||
|
||||
def assert_failure(str)
|
||||
process_item [:assert_failure, str]
|
||||
end
|
||||
@ -103,6 +107,8 @@ module Cmdtest
|
||||
case cmd
|
||||
when :assert_success
|
||||
# nothing
|
||||
when :test_skipped
|
||||
_distribute("test_skipped", rest)
|
||||
when :assert_failure
|
||||
_distribute("assert_failure", rest)
|
||||
when :assert_error
|
||||
@ -185,6 +191,10 @@ module Cmdtest
|
||||
clog.assert_success
|
||||
runner.method_filter.success(method_id)
|
||||
ok = true
|
||||
rescue Cmdtest::TestSkipped => e
|
||||
obj.teardown
|
||||
clog.test_skipped(e.message)
|
||||
runner.method_filter.failure(method_id)
|
||||
rescue Cmdtest::AssertFailed => e
|
||||
obj.teardown
|
||||
clog.assert_failure(e.message)
|
||||
@ -418,6 +428,7 @@ module Cmdtest
|
||||
"classes" => error_logger.n_classes,
|
||||
"methods" => error_logger.n_methods,
|
||||
"commands" => error_logger.n_commands,
|
||||
"skipped" => error_logger.n_skipped,
|
||||
"failures" => error_logger.n_failures,
|
||||
"errors" => error_logger.n_errors,
|
||||
}
|
||||
@ -462,6 +473,7 @@ module Cmdtest
|
||||
"classes" => error_logger.n_classes,
|
||||
"methods" => error_logger.n_methods,
|
||||
"commands" => error_logger.n_commands,
|
||||
"skipped" => error_logger.n_skipped,
|
||||
"failures" => error_logger.n_failures,
|
||||
"errors" => error_logger.n_errors,
|
||||
}
|
||||
@ -487,11 +499,12 @@ module Cmdtest
|
||||
puts "###"
|
||||
puts "### Finished: %s, Elapsed: %02d:%02d:%02d" % [Time.now.strftime("%F %T"), h,m,s]
|
||||
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["classes"],
|
||||
summary["methods"],
|
||||
summary["commands"],
|
||||
summary["skipped"],
|
||||
summary["failures"],
|
||||
summary["errors"],
|
||||
]
|
||||
|
@ -56,6 +56,9 @@ module Cmdtest
|
||||
def cmdline(method, comment)
|
||||
end
|
||||
|
||||
def test_skipped(str)
|
||||
end
|
||||
|
||||
def assert_failure(str)
|
||||
end
|
||||
|
||||
@ -69,6 +72,7 @@ module Cmdtest
|
||||
|
||||
attr_reader :n_suites, :n_files, :n_classes
|
||||
attr_reader :n_methods, :n_commands, :n_failures, :n_errors
|
||||
attr_reader :n_skipped
|
||||
|
||||
def initialize(opts)
|
||||
super
|
||||
@ -78,6 +82,7 @@ module Cmdtest
|
||||
@n_classes = 0
|
||||
@n_methods = 0
|
||||
@n_commands = 0
|
||||
@n_skipped = 0
|
||||
@n_failures = 0
|
||||
@n_errors = 0
|
||||
end
|
||||
@ -102,6 +107,10 @@ module Cmdtest
|
||||
@n_commands += 1
|
||||
end
|
||||
|
||||
def test_skipped(msg)
|
||||
@n_skipped += 1
|
||||
end
|
||||
|
||||
def assert_failure(msg)
|
||||
@n_failures += 1
|
||||
end
|
||||
|
@ -51,6 +51,10 @@ module Cmdtest
|
||||
end
|
||||
end
|
||||
|
||||
def test_skipped(str)
|
||||
puts str.gsub(/^/, "--- ")
|
||||
end
|
||||
|
||||
def assert_failure(str)
|
||||
puts str.gsub(/^/, "--- ")
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ module Cmdtest
|
||||
|
||||
#----------
|
||||
|
||||
class ErrTestcase < Testcase
|
||||
class ProblemTestcase < Testcase
|
||||
|
||||
def initialize(classname, name, message, type, text)
|
||||
@classname = classname
|
||||
@ -85,10 +85,12 @@ module Cmdtest
|
||||
@classname,
|
||||
@name,
|
||||
]
|
||||
f.put ' <failure message="%s" type="%s">%s</failure>', [
|
||||
f.put ' <%s message="%s" type="%s">%s</%s>', [
|
||||
xml_tag,
|
||||
@message,
|
||||
@type,
|
||||
@text,
|
||||
xml_tag,
|
||||
]
|
||||
f.put ' </testcase>'
|
||||
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
|
||||
|
||||
def initialize(package, name)
|
||||
@ -116,10 +132,17 @@ module Cmdtest
|
||||
testcase
|
||||
end
|
||||
|
||||
def skip_testcase(classname, name, message, type, text)
|
||||
testcase = SkipTestcase.new(classname, name, message, type, text)
|
||||
@testcases << testcase
|
||||
testcase
|
||||
end
|
||||
|
||||
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,
|
||||
@testcases.grep(ErrTestcase).size,
|
||||
@testcases.grep(SkipTestcase).size,
|
||||
@name,
|
||||
@testcases.size,
|
||||
@package,
|
||||
|
@ -41,10 +41,16 @@ module Cmdtest
|
||||
|
||||
def testmethod_begin(method)
|
||||
@err_assertions = []
|
||||
@err_skip = nil
|
||||
end
|
||||
|
||||
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]
|
||||
type = "assert"
|
||||
text = @err_assertions.join
|
||||
@ -58,6 +64,10 @@ module Cmdtest
|
||||
"CMDTEST." + @testcase_class_name
|
||||
end
|
||||
|
||||
def test_skipped(str)
|
||||
@err_skip = str
|
||||
end
|
||||
|
||||
def assert_failure(str)
|
||||
@err_assertions << str
|
||||
end
|
||||
|
@ -28,6 +28,7 @@ require "cmdtest/lcs"
|
||||
module Cmdtest
|
||||
|
||||
class AssertFailed < RuntimeError ; end
|
||||
class TestSkipped < RuntimeError ; end
|
||||
class UsageError < RuntimeError ; end
|
||||
|
||||
# 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
|
||||
_process_after do
|
||||
@_checked_status = true
|
||||
|
@ -39,7 +39,7 @@ class CMDTEST_options < Cmdtest::Testcase
|
||||
stdout_equal /.===== CMDTEST_foo.rb/
|
||||
stdout_equal /.----- CMDTEST_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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user