tuxml 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/test/unit/error_xml.rb +15 -0
- data/lib/test/unit/failure_xml.rb +15 -0
- data/lib/test/unit/testcase_xml.rb +56 -0
- data/lib/test/unit/testsuite_xml.rb +56 -0
- data/lib/test/unit/ui/xml/testrunner.rb +35 -0
- data/lib/tuxml.rb +10 -0
- metadata +72 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'test/unit/error'
|
|
2
|
+
require 'rexml/document'
|
|
3
|
+
|
|
4
|
+
module Test
|
|
5
|
+
module Unit
|
|
6
|
+
class Error
|
|
7
|
+
def xml_element
|
|
8
|
+
element = REXML::Element.new('error')
|
|
9
|
+
element.add_attributes('type' => exception.class.name, 'message' => exception.message)
|
|
10
|
+
element.text = exception.backtrace.join("\n")
|
|
11
|
+
element
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'test/unit/failure'
|
|
2
|
+
require 'rexml/document'
|
|
3
|
+
|
|
4
|
+
module Test
|
|
5
|
+
module Unit
|
|
6
|
+
class Failure
|
|
7
|
+
def xml_element
|
|
8
|
+
element = REXML::Element.new('failure')
|
|
9
|
+
element.add_attributes('type' => 'Test::Unit::AssertionFailedError', 'message' => self.message)
|
|
10
|
+
element.text = self.location.join("\n")
|
|
11
|
+
element
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'test/unit/testcase'
|
|
2
|
+
require 'rexml/document'
|
|
3
|
+
|
|
4
|
+
module Test
|
|
5
|
+
module Unit
|
|
6
|
+
class TestCase
|
|
7
|
+
def fault
|
|
8
|
+
@_fault
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def xml_element
|
|
12
|
+
return if @method_name.to_s == "default_test"
|
|
13
|
+
|
|
14
|
+
testcase = REXML::Element.new("testcase")
|
|
15
|
+
testcase.add_attributes('classname' => self.class.name, 'name' => @method_name, 'time' => @_elapsed_time.to_s)
|
|
16
|
+
if fault
|
|
17
|
+
testcase.elements << fault.xml_element
|
|
18
|
+
end
|
|
19
|
+
testcase
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def run_with_timing(result, &block)
|
|
23
|
+
before_time = Time.now.to_f
|
|
24
|
+
run_without_timing(result, &block)
|
|
25
|
+
ensure
|
|
26
|
+
after_time = Time.now.to_f
|
|
27
|
+
@_elapsed_time = after_time - before_time
|
|
28
|
+
end
|
|
29
|
+
alias_method :run_without_timing, :run
|
|
30
|
+
alias_method :run, :run_with_timing
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
# overridden from test/unit to store failures and errors inside the test_case
|
|
34
|
+
def add_failure(message, all_locations=caller())
|
|
35
|
+
@test_passed = false
|
|
36
|
+
@_fault = Failure.new(name, filter_backtrace(all_locations), message)
|
|
37
|
+
@_result.add_failure(@_fault)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_error(exception)
|
|
41
|
+
@test_passed = false
|
|
42
|
+
@_fault = Error.new(name, exception)
|
|
43
|
+
@_result.add_error(@_fault)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if defined?(ActiveSupport::TestCase)
|
|
50
|
+
module ActiveSupport
|
|
51
|
+
class TestCase
|
|
52
|
+
alias_method :run_without_timing, :run
|
|
53
|
+
alias_method :run, :run_with_timing
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'test/unit/testsuite'
|
|
2
|
+
require 'rexml/document'
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Test
|
|
6
|
+
module Unit
|
|
7
|
+
class TestSuite
|
|
8
|
+
def run_with_timing(result, &block)
|
|
9
|
+
@before_time = Time.now
|
|
10
|
+
run_without_timing(result, &block)
|
|
11
|
+
ensure
|
|
12
|
+
after_time = Time.now.to_f
|
|
13
|
+
@elapsed_time = after_time - @before_time.to_f
|
|
14
|
+
end
|
|
15
|
+
alias_method :run_without_timing, :run
|
|
16
|
+
alias_method :run, :run_with_timing
|
|
17
|
+
|
|
18
|
+
def xml_element
|
|
19
|
+
node = if @tests.first.is_a?(TestSuite)
|
|
20
|
+
REXML::Element.new("testsuites")
|
|
21
|
+
else
|
|
22
|
+
testsuite = REXML::Element.new("testsuite")
|
|
23
|
+
testsuite.add_attributes(
|
|
24
|
+
'name' => @name,
|
|
25
|
+
'tests' => test_count.to_s,
|
|
26
|
+
'failures' => failure_count.to_s,
|
|
27
|
+
'errors' => error_count.to_s,
|
|
28
|
+
'time' => @elapsed_time.to_s,
|
|
29
|
+
'timestamp' => @before_time.xmlschema
|
|
30
|
+
)
|
|
31
|
+
testsuite
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@tests.each do |test|
|
|
35
|
+
xml_element = test.xml_element
|
|
36
|
+
node.elements << xml_element if xml_element
|
|
37
|
+
end
|
|
38
|
+
return nil if node.elements.empty?
|
|
39
|
+
node
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
def test_count
|
|
44
|
+
@tests.size
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def failure_count
|
|
48
|
+
@tests.select { |test| test.fault.is_a?(Failure) }.size
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def error_count
|
|
52
|
+
@tests.select { |test| test.fault.is_a?(Error) }.size
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'test/unit/ui/console/testrunner'
|
|
2
|
+
|
|
3
|
+
require 'rexml/document'
|
|
4
|
+
|
|
5
|
+
module Test
|
|
6
|
+
module Unit
|
|
7
|
+
module UI
|
|
8
|
+
module Xml
|
|
9
|
+
class TestRunner < Test::Unit::UI::Console::TestRunner
|
|
10
|
+
def finished(elapsed_time)
|
|
11
|
+
super(elapsed_time)
|
|
12
|
+
|
|
13
|
+
xml_path = ENV["TUXML_OUTPUT_FILE"] || "tests.xml"
|
|
14
|
+
|
|
15
|
+
nl
|
|
16
|
+
File.open(xml_path,'w') {|file| file.write(to_xml) }
|
|
17
|
+
output("XML output saved: #{xml_path}")
|
|
18
|
+
nl
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
def to_xml
|
|
23
|
+
xml = REXML::Document.new
|
|
24
|
+
xml.elements << @suite.xml_element
|
|
25
|
+
xml.to_s
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
if __FILE__ == $0
|
|
34
|
+
Test::Unit::UI::Xml::TestRunner.start_command_line_test
|
|
35
|
+
end
|
data/lib/tuxml.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
Test::Unit::AutoRunner::RUNNERS[:xml] = proc do |r|
|
|
4
|
+
require File.dirname(__FILE__) + '/test/unit/ui/xml/testrunner'
|
|
5
|
+
require File.dirname(__FILE__) + '/test/unit/testsuite_xml'
|
|
6
|
+
require File.dirname(__FILE__) + '/test/unit/testcase_xml'
|
|
7
|
+
require File.dirname(__FILE__) + '/test/unit/error_xml'
|
|
8
|
+
require File.dirname(__FILE__) + '/test/unit/failure_xml'
|
|
9
|
+
Test::Unit::UI::Xml::TestRunner
|
|
10
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tuxml
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Thomas Kadauke
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-10-31 00:00:00 +02:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description:
|
|
23
|
+
email: tkadauke@imedo.de
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files: []
|
|
29
|
+
|
|
30
|
+
files:
|
|
31
|
+
- lib/test/unit/error_xml.rb
|
|
32
|
+
- lib/test/unit/failure_xml.rb
|
|
33
|
+
- lib/test/unit/testcase_xml.rb
|
|
34
|
+
- lib/test/unit/testsuite_xml.rb
|
|
35
|
+
- lib/test/unit/ui/xml/testrunner.rb
|
|
36
|
+
- lib/tuxml.rb
|
|
37
|
+
has_rdoc: true
|
|
38
|
+
homepage: http://github.com/tkadauke/tuxml
|
|
39
|
+
licenses: []
|
|
40
|
+
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
none: false
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
hash: 3
|
|
52
|
+
segments:
|
|
53
|
+
- 0
|
|
54
|
+
version: "0"
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
none: false
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
hash: 3
|
|
61
|
+
segments:
|
|
62
|
+
- 0
|
|
63
|
+
version: "0"
|
|
64
|
+
requirements: []
|
|
65
|
+
|
|
66
|
+
rubyforge_project:
|
|
67
|
+
rubygems_version: 1.3.7
|
|
68
|
+
signing_key:
|
|
69
|
+
specification_version: 3
|
|
70
|
+
summary: JUnit XML compatible output for Ruby's Test::Unit framework
|
|
71
|
+
test_files: []
|
|
72
|
+
|