unittest-colorizer 0.1.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/unittest-colorizer.rb +67 -0
- data/test/helper.rb +11 -0
- data/test/test_unittest-colorizer.rb +121 -0
- metadata +107 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Scott Noel-Hemming
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= unittest-colorizer
|
2
|
+
|
3
|
+
Colored output for unit tests.
|
4
|
+
I am tired of wanting to do this in every one of my different projects.
|
5
|
+
Plus I'm trying to have it conform to the principle of do one thing well.
|
6
|
+
|
7
|
+
== Note on Patches/Pull Requests
|
8
|
+
|
9
|
+
* Fork the project.
|
10
|
+
* Make your feature addition or bug fix.
|
11
|
+
* Add tests for it. This is important so I don't break it in a
|
12
|
+
future version unintentionally.
|
13
|
+
* Commit, do not mess with rakefile, version, or history.
|
14
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
15
|
+
* Send me a pull request. Bonus points for topic branches.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2010 Scott Noel-Hemming. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "unittest-colorizer"
|
8
|
+
gem.summary = %Q{Colored output in my unit tests.}
|
9
|
+
gem.description = %Q{Colored output for unit tests.}
|
10
|
+
gem.email = "frogstarr78@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/frogstarr78/unittest-colorizer"
|
12
|
+
gem.authors = ["Scott Noel-Hemming"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "mocha", ">= 0"
|
15
|
+
gem.add_dependency "colored", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "unittest-colorizer #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/unit/testresult'
|
3
|
+
require 'colored'
|
4
|
+
|
5
|
+
module Test
|
6
|
+
module Unit
|
7
|
+
class TestResult
|
8
|
+
def to_s
|
9
|
+
"#{run_count.to_s.yellow} tests, #{assertion_count.to_s.cyan} assertions, #{failure_count.to_s.red} failures, #{error_count.to_s.white_on_red} errors"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Error
|
14
|
+
alias_method :plain_single_character_display, :single_character_display
|
15
|
+
def single_character_display
|
16
|
+
plain_single_character_display.white_on_red
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :plain_message, :message
|
20
|
+
def message
|
21
|
+
"#{@exception.class.name.blue}: #{@exception.message.magenta}"
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method :plain_short_display, :short_display
|
25
|
+
def short_display
|
26
|
+
"#{@test_name.green}: #{message.split("\n")[0]}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def plain_short_display
|
30
|
+
"#{@test_name}: #{plain_message.split("\n")[0]}"
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method :plain_long_display, :long_display
|
34
|
+
def long_display
|
35
|
+
backtrace = filter_backtrace(@exception.backtrace).join("\n ")
|
36
|
+
"Error:\n#{@test_name.green}:\n#{message}\n #{backtrace}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def plain_long_display
|
40
|
+
backtrace = filter_backtrace(@exception.backtrace).join("\n ")
|
41
|
+
"Error:\n#@test_name:\n#{plain_message}\n #{backtrace}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Failure
|
46
|
+
alias_method :plain_single_character_display, :single_character_display
|
47
|
+
def single_character_display
|
48
|
+
plain_single_character_display.red
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :plain_short_display, :short_display
|
52
|
+
def short_display
|
53
|
+
"#{@test_name.green}: #{@message.split("\n")[0].magenta}"
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method :plain_long_display, :long_display
|
57
|
+
def long_display
|
58
|
+
location_display = if(location.size == 1)
|
59
|
+
location[0].sub(/\A(.+:\d+).*/, ' [\\1]')
|
60
|
+
else
|
61
|
+
"\n [#{location.join("\n ")}]"
|
62
|
+
end
|
63
|
+
"Failure:\n#{@test_name.green}#{location_display}:\n#@message"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'unittest-colorizer'
|
9
|
+
|
10
|
+
class Test::Unit::TestCase
|
11
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestUnittestColorizer < Test::Unit::TestCase
|
4
|
+
context "Test::Unit::TestResult" do
|
5
|
+
should "color test output" do
|
6
|
+
Test::Unit::TestResult.any_instance.expects(:run_count).returns 5
|
7
|
+
Test::Unit::TestResult.any_instance.expects(:assertion_count).returns 21
|
8
|
+
Test::Unit::TestResult.any_instance.expects(:failure_count).returns 3
|
9
|
+
Test::Unit::TestResult.any_instance.expects(:error_count).returns 2
|
10
|
+
|
11
|
+
result = Test::Unit::TestResult.new
|
12
|
+
assert_equal "\e[33m5\e[0m tests, \e[36m21\e[0m assertions, \e[31m3\e[0m failures, \e[37m\e[41m2\e[0m errors", result.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "Test::Unit::Error" do
|
17
|
+
setup do
|
18
|
+
@exception = Exception.new "I'm not excepted"
|
19
|
+
@error = Test::Unit::Error.new "This is my test name", @exception
|
20
|
+
end
|
21
|
+
|
22
|
+
should "color :single_character_display" do
|
23
|
+
assert_equal "\e[37m\e[41mE\e[0m", @error.single_character_display
|
24
|
+
end
|
25
|
+
|
26
|
+
should "have :plain_single_character_display" do
|
27
|
+
assert_equal "E", @error.plain_single_character_display
|
28
|
+
end
|
29
|
+
|
30
|
+
should "color :message" do
|
31
|
+
assert_equal "\e[34mException\e[0m: \e[35mI'm not excepted\e[0m", @error.message
|
32
|
+
end
|
33
|
+
|
34
|
+
should "have :plain_message" do
|
35
|
+
assert_equal "Exception: I'm not excepted", @error.plain_message
|
36
|
+
end
|
37
|
+
|
38
|
+
should "color :short_display" do
|
39
|
+
assert_equal "\e[32mThis is my test name\e[0m: \e[34mException\e[0m: \e[35mI'm not excepted\e[0m", @error.short_display
|
40
|
+
end
|
41
|
+
|
42
|
+
should "provide :plain_short_display" do
|
43
|
+
assert_equal "This is my test name: Exception: I'm not excepted", @error.plain_short_display
|
44
|
+
end
|
45
|
+
|
46
|
+
should "color :long_display" do
|
47
|
+
Test::Unit::Error.any_instance.expects(:filter_backtrace).returns ["\e[37m\e[40mI would be a backtrace...",""," if I had been called\e[0m"]
|
48
|
+
assert_equal "Error:\n\e[32mThis is my test name\e[0m:\n\e[34mException\e[0m: \e[35mI'm not excepted\e[0m\n \e[37m\e[40mI would be a backtrace...\n \n if I had been called\e[0m", @error.long_display
|
49
|
+
end
|
50
|
+
|
51
|
+
should "have :plain_long_display" do
|
52
|
+
Test::Unit::Error.any_instance.expects(:filter_backtrace).returns ["I would be a backtrace...",""," if I had been called"]
|
53
|
+
assert_equal "Error:\nThis is my test name:\nException: I'm not excepted\n I would be a backtrace...\n \n if I had been called", @error.plain_long_display
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "Test::Unit::Failure" do
|
58
|
+
setup do
|
59
|
+
@failure = Test::Unit::Failure.new "I'm such a failure", ["I happened right here:59 some stuff"], "Do you want me to apologize?\nI'm really not that kind of failure\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
should "color single_character_display" do
|
63
|
+
assert_equal "\e[31mF\e[0m", @failure.single_character_display
|
64
|
+
end
|
65
|
+
|
66
|
+
should "have :plain_single_character_display" do
|
67
|
+
assert_equal "F", @failure.plain_single_character_display
|
68
|
+
end
|
69
|
+
|
70
|
+
should "color :short_display" do
|
71
|
+
assert_equal "\e[32mI'm such a failure\e[0m: \e[35mDo you want me to apologize?\e[0m", @failure.short_display
|
72
|
+
end
|
73
|
+
|
74
|
+
should "have :plain_short_display" do
|
75
|
+
assert_equal "I'm such a failure: Do you want me to apologize?", @failure.plain_short_display
|
76
|
+
end
|
77
|
+
|
78
|
+
context "color :long_display with no real location data" do
|
79
|
+
setup do
|
80
|
+
@failure = Test::Unit::Failure.new "I'm such a failure", ["I happened right here"], "Do you want me to apologize?\nI'm really not that kind of failure\n"
|
81
|
+
end
|
82
|
+
|
83
|
+
should "be colored" do
|
84
|
+
assert_equal "Failure:\n\e[32mI'm such a failure\e[0mI happened right here:\nDo you want me to apologize?\nI'm really not that kind of failure\n", @failure.long_display
|
85
|
+
end
|
86
|
+
|
87
|
+
should "have plain uncolored method" do
|
88
|
+
assert_equal "Failure:\nI'm such a failureI happened right here:\nDo you want me to apologize?\nI'm really not that kind of failure\n", @failure.plain_long_display
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "color :long_display with some location data" do
|
93
|
+
setup do
|
94
|
+
@failure = Test::Unit::Failure.new "I'm such a failure", ["I happened right here:59 some stuff"], "Do you want me to apologize?\nI'm really not that kind of failure\n"
|
95
|
+
end
|
96
|
+
|
97
|
+
should "be colored" do
|
98
|
+
assert_equal "Failure:\n\e[32mI'm such a failure\e[0m [I happened right here:59]:\nDo you want me to apologize?\nI'm really not that kind of failure\n", @failure.long_display
|
99
|
+
end
|
100
|
+
|
101
|
+
should "have plain uncolored method" do
|
102
|
+
assert_equal "Failure:\nI'm such a failure [I happened right here:59]:\nDo you want me to apologize?\nI'm really not that kind of failure\n", @failure.plain_long_display
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "color :long_display with lots of location data" do
|
107
|
+
setup do
|
108
|
+
@failure = Test::Unit::Failure.new "I'm such a failure", ["I happened right here:59","Some more stuff:60"], "Do you want me to apologize?\nI'm really not that kind of failure\n"
|
109
|
+
end
|
110
|
+
|
111
|
+
should "be colored" do
|
112
|
+
assert_equal "Failure:\n\e[32mI'm such a failure\e[0m\n [I happened right here:59\n Some more stuff:60]:\nDo you want me to apologize?\nI'm really not that kind of failure\n", @failure.long_display
|
113
|
+
end
|
114
|
+
|
115
|
+
should "have plain uncolored method" do
|
116
|
+
assert_equal "Failure:\nI'm such a failure\n [I happened right here:59\n Some more stuff:60]:\nDo you want me to apologize?\nI'm really not that kind of failure\n", @failure.plain_long_display
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unittest-colorizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Scott Noel-Hemming
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-05 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: mocha
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: colored
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id003
|
56
|
+
description: Colored output for unit tests.
|
57
|
+
email: frogstarr78@gmail.com
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
63
|
+
- LICENSE
|
64
|
+
- README.rdoc
|
65
|
+
files:
|
66
|
+
- .document
|
67
|
+
- .gitignore
|
68
|
+
- LICENSE
|
69
|
+
- README.rdoc
|
70
|
+
- Rakefile
|
71
|
+
- VERSION
|
72
|
+
- lib/unittest-colorizer.rb
|
73
|
+
- test/helper.rb
|
74
|
+
- test/test_unittest-colorizer.rb
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/frogstarr78/unittest-colorizer
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --charset=UTF-8
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.6
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Colored output in my unit tests.
|
105
|
+
test_files:
|
106
|
+
- test/test_unittest-colorizer.rb
|
107
|
+
- test/helper.rb
|