dohtest 0.1.7 → 0.1.8
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/doh/test/assertions.rb +1 -1
- data/lib/doh/test/configure.rb +1 -1
- data/lib/doh/test/stream_output.rb +54 -28
- metadata +15 -4
data/lib/doh/test/assertions.rb
CHANGED
@@ -29,7 +29,7 @@ class TestGroup
|
|
29
29
|
if expected.any? { |elem| elem.instance_of?(Module) ? actual_excpt.kind_of?(elem) : elem == actual_class }
|
30
30
|
@runner.assertion_passed
|
31
31
|
else
|
32
|
-
raise DohTest::Failure.new(msg, :raises, expected,
|
32
|
+
raise DohTest::Failure.new(msg, :raises, expected, actual_excpt)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
raise DohTest::Failure.new(msg, :raises, expected, nil) if no_exception
|
data/lib/doh/test/configure.rb
CHANGED
@@ -8,6 +8,7 @@ end
|
|
8
8
|
|
9
9
|
def self.load_configuration_files(start_path)
|
10
10
|
start_directory = File.dirname(start_path)
|
11
|
+
root_directory = Doh::find_root(start_directory)
|
11
12
|
|
12
13
|
local_filename = Doh::findup(start_directory, 'configure_dohtest.rb')
|
13
14
|
if local_filename && File.exist?(local_filename)
|
@@ -15,7 +16,6 @@ def self.load_configuration_files(start_path)
|
|
15
16
|
return
|
16
17
|
end
|
17
18
|
|
18
|
-
root_directory = Doh::find_root(start_directory)
|
19
19
|
if root_directory
|
20
20
|
root_filename = File.join(root_directory, 'config', 'dohtest.rb')
|
21
21
|
require(root_filename) if File.exist?(root_filename)
|
@@ -1,15 +1,19 @@
|
|
1
1
|
require 'doh/test/backtrace_parser'
|
2
2
|
require 'set'
|
3
|
+
require 'term/ansicolor'
|
3
4
|
|
4
5
|
module DohTest
|
5
6
|
|
6
7
|
class StreamOutput
|
8
|
+
DEFAULT_COLORS = {:failure => :red, :error => :magenta, :info => :blue, :success => :green}.freeze
|
9
|
+
|
7
10
|
def initialize
|
8
11
|
@error_count = @groups_ran = @groups_skipped = @tests_ran = @tests_skipped = @assertions_failed = @assertions_passed = 0
|
9
12
|
@badness = Set.new
|
10
13
|
end
|
11
14
|
|
12
15
|
def run_begin(config)
|
16
|
+
@config = config
|
13
17
|
puts "running tests with config: #{config}"
|
14
18
|
end
|
15
19
|
|
@@ -24,29 +28,43 @@ class StreamOutput
|
|
24
28
|
puts "\n\ncompleted in #{duration.round(2)}s"
|
25
29
|
end
|
26
30
|
|
31
|
+
if @error_count == 0
|
32
|
+
error_str = "0 errors"
|
33
|
+
else
|
34
|
+
error_str = colorize(:error, "#@error_count errors")
|
35
|
+
end
|
36
|
+
|
27
37
|
if @groups_skipped == 0
|
28
|
-
|
38
|
+
group_str = "#@groups_ran groups"
|
29
39
|
else
|
30
40
|
total_groups = @groups_ran + @groups_skipped
|
31
|
-
|
41
|
+
group_str = "#{total_groups} groups: #@groups_ran ran, #@groups_skipped skipped"
|
32
42
|
end
|
33
43
|
|
34
44
|
if @tests_skipped == 0
|
35
|
-
|
45
|
+
test_str = "#@tests_ran tests"
|
36
46
|
else
|
37
47
|
total_tests = @tests_ran + @tests_skipped
|
38
|
-
|
48
|
+
test_str = "#{total_tests} tests: #@tests_ran ran, #@tests_skipped skipped"
|
39
49
|
end
|
40
50
|
|
41
|
-
if
|
42
|
-
|
51
|
+
if total_assertions == 0
|
52
|
+
assertion_str = colorize(:info, "no assertions run")
|
53
|
+
elsif @assertions_failed == 0
|
54
|
+
assertion_str = "all #{total_assertions} assertions passed"
|
43
55
|
else
|
44
|
-
|
56
|
+
failed_str = colorize(:failure, "#@assertions_failed failed")
|
57
|
+
assertion_str = "#{total_assertions} assertions: #@assertions_passed passed, #{failed_str}"
|
45
58
|
end
|
46
|
-
|
59
|
+
|
60
|
+
success = (total_assertions > 0) && (@error_count == 0) && (@assertions_failed == 0)
|
61
|
+
|
62
|
+
msg = "#{error_str}; #{group_str}; #{test_str}; #{assertion_str}"
|
63
|
+
msg = colorize(:success, msg) if success
|
64
|
+
puts msg
|
47
65
|
|
48
66
|
# this is to generate an exit code; true translates to 0, false to 1
|
49
|
-
|
67
|
+
success
|
50
68
|
end
|
51
69
|
|
52
70
|
def group_begin(group_name)
|
@@ -55,7 +73,11 @@ class StreamOutput
|
|
55
73
|
def group_end(group_name, tests_ran, tests_skipped, assertions_passed, assertions_failed)
|
56
74
|
@tests_skipped += tests_skipped
|
57
75
|
if tests_ran == 0
|
58
|
-
|
76
|
+
if tests_skipped > 0
|
77
|
+
@groups_skipped += 1
|
78
|
+
else
|
79
|
+
puts colorize(:info, "no tests defined in #{group_name}")
|
80
|
+
end
|
59
81
|
return
|
60
82
|
end
|
61
83
|
@groups_ran += 1
|
@@ -89,59 +111,63 @@ class StreamOutput
|
|
89
111
|
end
|
90
112
|
|
91
113
|
private
|
114
|
+
def colorize(type, msg)
|
115
|
+
color = @config["#{type}_color".to_sym] || DEFAULT_COLORS[type]
|
116
|
+
"#{Term::ANSIColor.send(color)}#{Term::ANSIColor.bold}#{msg}#{Term::ANSIColor.clear}"
|
117
|
+
end
|
118
|
+
|
92
119
|
def display_badness(group_name, test_name, excpt)
|
93
120
|
badness_type = if excpt.is_a?(DohTest::Failure) then :failure else :error end
|
94
121
|
parser = DohTest::BacktraceParser.new(excpt.backtrace)
|
95
|
-
warn "#{badness_type} in #{group_name}.#{test_name}"
|
122
|
+
warn colorize(badness_type, "#{badness_type} in #{group_name}.#{test_name} at:")
|
123
|
+
parser.relevant_stack.each do |path, line|
|
124
|
+
warn "#{path}:#{line}"
|
125
|
+
end
|
96
126
|
if badness_type == :error
|
97
|
-
warn "#{excpt.class}: #{excpt}"
|
127
|
+
warn colorize(:info, "#{excpt.class}: #{excpt.message}")
|
98
128
|
else
|
99
129
|
display_failure_message(excpt)
|
100
130
|
end
|
101
|
-
parser.relevant_stack.each do |path, line|
|
102
|
-
warn "#{path}:#{line}"
|
103
|
-
end
|
104
131
|
end
|
105
132
|
|
106
133
|
def display_failure_message(failure)
|
107
134
|
if failure.message.empty?
|
108
|
-
|
135
|
+
send("display_#{failure.assert}_failure", failure)
|
109
136
|
else
|
110
|
-
warn failure.message
|
137
|
+
warn colorize(:info, failure.message)
|
111
138
|
end
|
112
139
|
end
|
113
140
|
|
114
141
|
def display_boolean_failure(failure)
|
115
|
-
"assertion failed"
|
142
|
+
warn colorize(:info, "assertion failed")
|
116
143
|
end
|
117
144
|
|
118
145
|
def display_equal_failure(failure)
|
119
|
-
|
120
|
-
"expected: #{failure.expected}; actual: #{failure.actual}"
|
121
|
-
else
|
122
|
-
"\nexpected: #{failure.expected}\n actual: #{failure.actual}"
|
123
|
-
end
|
146
|
+
warn colorize(:info, "expected: #{failure.expected}\n actual: #{failure.actual}")
|
124
147
|
end
|
125
148
|
|
126
149
|
def display_raises_failure(failure)
|
127
150
|
if failure.actual
|
128
151
|
expected_str = if (failure.expected.size == 1) then failure.expected.first else "one of #{failure.expected.join(',')}" end
|
129
|
-
"expected: #{expected_str}; actual: #{failure.actual.class}: #{failure.actual.message}"
|
152
|
+
warn colorize(:info, "expected: #{expected_str}; actual: #{failure.actual.class}: #{failure.actual.message}")
|
153
|
+
DohTest::BacktraceParser.new(failure.actual.backtrace).relevant_stack.each do |path, line|
|
154
|
+
warn "#{path}:#{line}"
|
155
|
+
end
|
130
156
|
else
|
131
|
-
"expected: #{failure.expected}, but no exception was raised"
|
157
|
+
warn colorize(:info, "expected: #{failure.expected}, but no exception was raised")
|
132
158
|
end
|
133
159
|
end
|
134
160
|
|
135
161
|
def display_instance_of_failure(failure)
|
136
|
-
"expected class: #{failure.expected}; actual: #{failure.actual}"
|
162
|
+
warn colorize(:info, "expected class: #{failure.expected}; actual: #{failure.actual}")
|
137
163
|
end
|
138
164
|
|
139
165
|
def display_match_failure(failure)
|
140
|
-
"expected regex #{failure.expected} to match str: #{failure.actual}"
|
166
|
+
warn colorize(:info, "expected regex #{failure.expected} to match str: #{failure.actual}")
|
141
167
|
end
|
142
168
|
|
143
169
|
def display_not_equal_failure(failure)
|
144
|
-
"expected unequal values; both are: #{failure.expected}"
|
170
|
+
warn colorize(:info, "expected unequal values; both are: #{failure.expected}")
|
145
171
|
end
|
146
172
|
|
147
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dohtest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-30 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dohroot
|
17
|
-
requirement: &
|
17
|
+
requirement: &70097974424660 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,18 @@ dependencies:
|
|
22
22
|
version: 0.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70097974424660
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: term-ansicolor
|
28
|
+
requirement: &70097974424000 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70097974424000
|
26
37
|
description: Minimalist unit test framework, easy to understand and extend.
|
27
38
|
email:
|
28
39
|
- devinfo@atpsoft.com
|