test-unit-ext 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.en +6 -0
- data/NEWS.ja +6 -0
- data/html/news.html +9 -1
- data/html/news.html.en +9 -1
- data/html/news.html.ja +9 -1
- data/lib/test-unit-ext.rb +2 -0
- data/lib/test-unit-ext/assertions.rb +30 -0
- data/lib/test-unit-ext/diff.rb +375 -83
- data/lib/test-unit-ext/priority.rb +2 -2
- data/lib/test-unit-ext/version.rb +1 -1
- data/lib/test-unit-ext/xml-report.rb +226 -0
- data/test/test_diff.rb +275 -34
- data/test/test_metadata.rb +14 -5
- data/test/test_xml_report.rb +163 -0
- metadata +6 -2
data/test/test_metadata.rb
CHANGED
@@ -65,7 +65,7 @@ class TestMetadata < Test::Unit::TestCase
|
|
65
65
|
def test_show_metadata
|
66
66
|
assert_stack_size_line = search_line('assert_equal(0, @stack.size)')
|
67
67
|
assert_peek_line = search_line('assert_equal(2, @stack.peek)')
|
68
|
-
first_arg_end_line = search_line("\"
|
68
|
+
first_arg_end_line = search_line("\"+ 11\"],")
|
69
69
|
method_name = "test_show_metadata"
|
70
70
|
assert_result(["Failure:\n" \
|
71
71
|
"test_peek(TestMetadata::TestStack)\n" \
|
@@ -73,28 +73,37 @@ class TestMetadata < Test::Unit::TestCase
|
|
73
73
|
"#{__FILE__}:#{assert_peek_line}:in `test_peek'\n" \
|
74
74
|
"#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
|
75
75
|
"<2> expected but was\n" \
|
76
|
-
"<1
|
76
|
+
"<1>.\n" \
|
77
|
+
"diff:\n" \
|
78
|
+
"- 2\n" \
|
79
|
+
"+ 1",
|
77
80
|
"Failure:\n" \
|
78
81
|
"test_bug_1234(TestMetadata::TestStack)\n" \
|
79
82
|
" bug: 1234\n" \
|
80
83
|
"#{__FILE__}:#{assert_stack_size_line}:in `test_bug_1234'\n" \
|
81
84
|
"#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
|
82
85
|
"<0> expected but was\n" \
|
83
|
-
"<11
|
86
|
+
"<11>.\n" \
|
87
|
+
"diff:\n" \
|
88
|
+
"- 0\n" \
|
89
|
+
"+ 11"],
|
84
90
|
[],
|
85
91
|
["test_peek", "test_bug_1234"])
|
86
92
|
end
|
87
93
|
|
88
94
|
def test_not_show_metadata
|
89
95
|
assert_line = search_line('assert_equal(1, @stack.size')
|
90
|
-
first_arg_end_line = search_line("\"
|
96
|
+
first_arg_end_line = search_line("\"+ 12\"],")
|
91
97
|
method_name = "test_not_show_metadata"
|
92
98
|
assert_result(["Failure:\n" \
|
93
99
|
"test_no_metadata(TestMetadata::TestStack)\n" \
|
94
100
|
"#{__FILE__}:#{assert_line}:in `test_no_metadata'\n" \
|
95
101
|
"#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
|
96
102
|
"<1> expected but was\n" \
|
97
|
-
"<12
|
103
|
+
"<12>.\n" \
|
104
|
+
"diff:\n" \
|
105
|
+
"- 1\n" \
|
106
|
+
"+ 12"],
|
98
107
|
[],
|
99
108
|
["test_no_metadata"])
|
100
109
|
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'test-unit-ext'
|
2
|
+
|
3
|
+
class TestXMLReport < Test::Unit::TestCase
|
4
|
+
class TestCase < Test::Unit::TestCase
|
5
|
+
def default_test
|
6
|
+
end
|
7
|
+
|
8
|
+
def _test_success
|
9
|
+
assert(true)
|
10
|
+
end
|
11
|
+
|
12
|
+
TEST_FAILURE_LINE = __LINE__ + 3
|
13
|
+
bug 1234
|
14
|
+
def _test_failure
|
15
|
+
assert(false)
|
16
|
+
end
|
17
|
+
|
18
|
+
TEST_ERROR_LINE = __LINE__ + 2
|
19
|
+
def _test_error
|
20
|
+
non_existence_method()
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
"TEST-CASE"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
include ERB::Util
|
29
|
+
|
30
|
+
def test_empty_test
|
31
|
+
assert_xml("<test_logs/>", suite)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_success_result
|
35
|
+
elapsed = "0.001"
|
36
|
+
assert_xml(<<-XML, suite([TestCase.new("_test_success")]), elapsed)
|
37
|
+
<test_logs>
|
38
|
+
<test_log>
|
39
|
+
<test_case>
|
40
|
+
<name>TestXMLReport::TestCase</name>
|
41
|
+
<description/>
|
42
|
+
</test_case>
|
43
|
+
<name>_test_success</name>
|
44
|
+
<description/>
|
45
|
+
<result>
|
46
|
+
<status>success</status>
|
47
|
+
<detail></detail>
|
48
|
+
<elapsed>#{elapsed}</elapsed>
|
49
|
+
</result>
|
50
|
+
</test_log>
|
51
|
+
</test_logs>
|
52
|
+
XML
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_failure_result
|
56
|
+
elapsed = "0.001"
|
57
|
+
backtrace_line = __LINE__ + 1
|
58
|
+
assert_xml(<<-XML, suite([TestCase.new("_test_failure")]), elapsed)
|
59
|
+
<test_logs>
|
60
|
+
<test_log>
|
61
|
+
<test_case>
|
62
|
+
<name>TestXMLReport::TestCase</name>
|
63
|
+
<description/>
|
64
|
+
</test_case>
|
65
|
+
<name>_test_failure</name>
|
66
|
+
<description/>
|
67
|
+
<metadata>
|
68
|
+
<item>
|
69
|
+
<name>bug</name>
|
70
|
+
<value>1234</value>
|
71
|
+
</item>
|
72
|
+
</metadata>
|
73
|
+
<result>
|
74
|
+
<status>failure</status>
|
75
|
+
<detail><false> is not true.</detail>
|
76
|
+
<elapsed>#{elapsed}</elapsed>
|
77
|
+
</result>
|
78
|
+
<backtrace>
|
79
|
+
<entry>
|
80
|
+
<file>#{__FILE__}</file>
|
81
|
+
<line>#{TestCase::TEST_FAILURE_LINE}</line>
|
82
|
+
<info>in `_test_failure'</info>
|
83
|
+
</entry>
|
84
|
+
<entry>
|
85
|
+
<file>#{__FILE__}</file>
|
86
|
+
<line>#{TEST_RUN_LINE}</line>
|
87
|
+
<info>in `assert_xml'</info>
|
88
|
+
</entry>
|
89
|
+
<entry>
|
90
|
+
<file>#{__FILE__}</file>
|
91
|
+
<line>#{backtrace_line}</line>
|
92
|
+
<info>in `test_failure_result'</info>
|
93
|
+
</entry>
|
94
|
+
</backtrace>
|
95
|
+
</test_log>
|
96
|
+
</test_logs>
|
97
|
+
XML
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_error_result
|
101
|
+
test = TestCase.new("_test_error")
|
102
|
+
detail = "NoMethodError: undefined method `non_existence_method' " +
|
103
|
+
"for TEST-CASE:#{test.class.name}"
|
104
|
+
elapsed = "0.001"
|
105
|
+
backtrace_line = __LINE__ + 1
|
106
|
+
assert_xml(<<-XML, suite([test]), elapsed)
|
107
|
+
<test_logs>
|
108
|
+
<test_log>
|
109
|
+
<test_case>
|
110
|
+
<name>TestXMLReport::TestCase</name>
|
111
|
+
<description/>
|
112
|
+
</test_case>
|
113
|
+
<name>_test_error</name>
|
114
|
+
<description/>
|
115
|
+
<result>
|
116
|
+
<status>error</status>
|
117
|
+
<detail>#{h(detail)}</detail>
|
118
|
+
<elapsed>#{elapsed}</elapsed>
|
119
|
+
</result>
|
120
|
+
<backtrace>
|
121
|
+
<entry>
|
122
|
+
<file>#{__FILE__}</file>
|
123
|
+
<line>#{TestCase::TEST_ERROR_LINE}</line>
|
124
|
+
<info>in `_test_error'</info>
|
125
|
+
</entry>
|
126
|
+
<entry>
|
127
|
+
<file>#{__FILE__}</file>
|
128
|
+
<line>#{TEST_RUN_LINE}</line>
|
129
|
+
<info>in `assert_xml'</info>
|
130
|
+
</entry>
|
131
|
+
<entry>
|
132
|
+
<file>#{__FILE__}</file>
|
133
|
+
<line>#{backtrace_line}</line>
|
134
|
+
<info>in `test_error_result'</info>
|
135
|
+
</entry>
|
136
|
+
</backtrace>
|
137
|
+
</test_log>
|
138
|
+
</test_logs>
|
139
|
+
XML
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
def suite(tests=[], name="Unnamed TestSuite")
|
144
|
+
test_suite = Test::Unit::TestSuite.new(name)
|
145
|
+
tests.each do |test|
|
146
|
+
test_suite << test
|
147
|
+
end
|
148
|
+
test_suite
|
149
|
+
end
|
150
|
+
|
151
|
+
TEST_RUN_LINE = __LINE__ + 2
|
152
|
+
def assert_xml(expected, suite, normalized_elapsed=nil)
|
153
|
+
result = Test::Unit::UI::Console::TestRunner.run(suite,
|
154
|
+
Test::Unit::UI::SILENT)
|
155
|
+
xml = result.to_xml
|
156
|
+
if xml and normalized_elapsed
|
157
|
+
xml = xml.gsub(/<elapsed>[\d.]+<\/elapsed>/) do
|
158
|
+
"<elapsed>#{normalized_elapsed}</elapsed>"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
assert_equal(expected, xml)
|
162
|
+
end
|
163
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-unit-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-03-03 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- html/readme.html.ja
|
38
38
|
- lib/test-unit-ext.rb
|
39
39
|
- lib/test-unit-ext/always-show-result.rb
|
40
|
+
- lib/test-unit-ext/assertions.rb
|
40
41
|
- lib/test-unit-ext/backtrace-filter.rb
|
41
42
|
- lib/test-unit-ext/color.rb
|
42
43
|
- lib/test-unit-ext/colorized-runner.rb
|
@@ -45,11 +46,13 @@ files:
|
|
45
46
|
- lib/test-unit-ext/metadata.rb
|
46
47
|
- lib/test-unit-ext/priority.rb
|
47
48
|
- lib/test-unit-ext/version.rb
|
49
|
+
- lib/test-unit-ext/xml-report.rb
|
48
50
|
- misc/rd2html.rb
|
49
51
|
- test/run-test.rb
|
50
52
|
- test/test_color.rb
|
51
53
|
- test/test_diff.rb
|
52
54
|
- test/test_metadata.rb
|
55
|
+
- test/test_xml_report.rb
|
53
56
|
has_rdoc: true
|
54
57
|
homepage: http://test-unit-ext.rubyforge.org/
|
55
58
|
post_install_message:
|
@@ -81,3 +84,4 @@ test_files:
|
|
81
84
|
- test/test_diff.rb
|
82
85
|
- test/test_metadata.rb
|
83
86
|
- test/test_color.rb
|
87
|
+
- test/test_xml_report.rb
|