|
| 1 | +require "stringio" |
| 2 | +require 'rexml/document' |
| 3 | +require "test/unit" |
| 4 | +require "test/unit/ui/junitxml/testrunner" |
| 5 | +require_relative "check" |
| 6 | + |
| 7 | +class TestXmlWithoutOutputCapture < Test::Unit::TestCase |
| 8 | + include Check |
| 9 | + |
| 10 | + setup do |
| 11 | + test_case = Class.new(Test::Unit::TestCase) do |
| 12 | + include Test::Unit::Util::Output |
| 13 | + |
| 14 | + test "success" do |
| 15 | + assert_equal(1, 1) |
| 16 | + puts("out 1") |
| 17 | + end |
| 18 | + |
| 19 | + def test_failure |
| 20 | + assert_equal(1, 1) |
| 21 | + warn("warn 1") |
| 22 | + assert_equal(1, 2) |
| 23 | + end |
| 24 | + |
| 25 | + def test_error |
| 26 | + warn("warn 2") |
| 27 | + puts("out 2") |
| 28 | + assert_equal(1, 1) |
| 29 | + assert_equal(1, 1) |
| 30 | + assert_equal(1, 1) |
| 31 | + raise "hello" |
| 32 | + end |
| 33 | + |
| 34 | + def test_omission |
| 35 | + puts("out 3") |
| 36 | + omit("omission 1") |
| 37 | + end |
| 38 | + |
| 39 | + def test_pending |
| 40 | + warn("warn 3") |
| 41 | + pend("pending 1") |
| 42 | + end |
| 43 | + |
| 44 | + def test_with_capture_output |
| 45 | + out, err = capture_output do |
| 46 | + puts("out 4") |
| 47 | + warn("warn 4") |
| 48 | + end |
| 49 | + assert_equal("out 4\n", out) |
| 50 | + assert_equal("warn 4\n", err) |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + output = StringIO.new |
| 55 | + runner = Test::Unit::UI::JUnitXml::TestRunner.new( |
| 56 | + test_case.suite, |
| 57 | + :output => output, |
| 58 | + :junitxml_disable_output_capture => true) |
| 59 | + runner.start |
| 60 | + |
| 61 | + output.rewind |
| 62 | + @doc = REXML::Document.new(output) |
| 63 | + end |
| 64 | + |
| 65 | + test "testsuites" do |
| 66 | + testsuites_array = @doc.get_elements("/testsuites") |
| 67 | + assert_equal(1, testsuites_array.size) |
| 68 | + end |
| 69 | + |
| 70 | + test "testsuite" do |
| 71 | + testsuite_array = @doc.get_elements("/testsuites/testsuite") |
| 72 | + assert_equal(1, testsuite_array.size) |
| 73 | + check_testsuite(testsuite_array.first, "", 6, 1, 1, 2) |
| 74 | + end |
| 75 | + |
| 76 | + test "testcase success" do |
| 77 | + testcase_array = @doc.get_elements( |
| 78 | + "/testsuites/testsuite/testcase[@name='success']") |
| 79 | + assert_equal(1, testcase_array.size) |
| 80 | + check_testcase_success(testcase_array.first, "", 1) |
| 81 | + end |
| 82 | + |
| 83 | + test "testcase failure" do |
| 84 | + testcase_array = @doc.get_elements( |
| 85 | + "/testsuites/testsuite/testcase[@name='test_failure()']") |
| 86 | + assert_equal(1, testcase_array.size) |
| 87 | + check_testcase_failure(testcase_array.first, "", 2, /.+/) |
| 88 | + end |
| 89 | + |
| 90 | + test "testcase error" do |
| 91 | + testcase_array = @doc.get_elements( |
| 92 | + "/testsuites/testsuite/testcase[@name='test_error()']") |
| 93 | + assert_equal(1, testcase_array.size) |
| 94 | + check_testcase_error(testcase_array.first, "", 3, "hello") |
| 95 | + end |
| 96 | + |
| 97 | + test "testcase omission" do |
| 98 | + testcase_array = @doc.get_elements( |
| 99 | + "/testsuites/testsuite/testcase[@name='test_omission()']") |
| 100 | + assert_equal(1, testcase_array.size) |
| 101 | + check_testcase_skipped(testcase_array.first, "", 0, "omission 1") |
| 102 | + end |
| 103 | + |
| 104 | + test "testcase pending" do |
| 105 | + testcase_array = @doc.get_elements( |
| 106 | + "/testsuites/testsuite/testcase[@name='test_pending()']") |
| 107 | + assert_equal(1, testcase_array.size) |
| 108 | + check_testcase_skipped(testcase_array.first, "", 0, "pending 1") |
| 109 | + end |
| 110 | + |
| 111 | + test "testcase test_with_capture_output" do |
| 112 | + testcase_array = @doc.get_elements( |
| 113 | + "/testsuites/testsuite/testcase[@name='test_with_capture_output()']") |
| 114 | + assert_equal(1, testcase_array.size) |
| 115 | + check_testcase_success(testcase_array.first, "", 2) |
| 116 | + end |
| 117 | +end |
0 commit comments