tet 1.3.3 → 1.4.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.
- checksums.yaml +4 -4
- data/lib/tests.rb +36 -97
- data/lib/tet.rb +72 -45
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6df1946431552379933de20912968be739eab224
|
4
|
+
data.tar.gz: c62f656b7d3f666c6d78dc6069ee335b698c7a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 395c666f9638b07ff91517ddd9e70acecf91d5c9a49b8ba49932debfd097f1300fa3cc675a4476962b1fb0585245e322fba10cc61eabd583a25fbffceb362b2e
|
7
|
+
data.tar.gz: f0472526eb13689f3e89e5f44415d8689e124c7f4fc3e56856c8511e3551bfbacabe6f891dd4a22ee250f93a69afadcedaa7d1dfeccc94a963b143545588db89
|
data/lib/tests.rb
CHANGED
@@ -6,83 +6,41 @@
|
|
6
6
|
# (located in root directory of this project) for details.
|
7
7
|
|
8
8
|
require_relative "./tet"
|
9
|
-
|
10
|
-
$missed_fails = 0
|
11
|
-
$missed_errs = 0
|
12
|
-
$expected_fails = 0
|
13
|
-
$expected_errs = 0
|
14
|
-
|
15
|
-
at_exit do
|
16
|
-
puts <<~END
|
17
|
-
\n
|
18
|
-
#{$missed_fails} missed fails
|
19
|
-
#{$missed_errs} missed errs
|
20
|
-
#{total_fails - $expected_fails + $missed_fails} unintended fails
|
21
|
-
#{total_errs - $expected_errs + $missed_errs} unintended errs
|
22
|
-
END
|
23
|
-
end
|
24
|
-
|
25
|
-
def total_fails
|
26
|
-
Tet.fail_count - Tet.err_count
|
27
|
-
end
|
28
|
-
|
29
|
-
def total_errs
|
30
|
-
Tet.err_count
|
31
|
-
end
|
32
|
-
|
33
|
-
# Wraps the block in a group to label it as an example instead of a real test.
|
34
|
-
def should_fail
|
35
|
-
$expected_fails += 1
|
36
|
-
prev_fail_count = total_fails
|
37
|
-
result = false
|
38
|
-
|
39
|
-
group("INTENDED FAILURE") { result = yield }
|
40
|
-
|
41
|
-
$missed_fails += 1 if prev_fail_count == total_fails
|
42
|
-
|
43
|
-
result
|
44
|
-
end
|
45
|
-
|
46
|
-
# Wraps the block in a group to label it as an example instead of a real test.
|
47
|
-
def should_err
|
48
|
-
$expected_errs += 1
|
49
|
-
prev_err_count = total_errs
|
50
|
-
result = false
|
51
|
-
|
52
|
-
group("INTENDED ERROR") { result = yield }
|
53
|
-
|
54
|
-
$missed_errs += 1 if prev_err_count == total_errs
|
55
|
-
|
56
|
-
result
|
57
|
-
end
|
9
|
+
require_relative "./test_helpers"
|
58
10
|
|
59
11
|
group "#assert" do
|
60
12
|
assert("truthy blocks pass") { true }
|
61
13
|
|
62
|
-
|
63
|
-
|
64
|
-
|
14
|
+
result = assert { true }
|
15
|
+
assert("passing returns true") { result.equal?(true) }
|
16
|
+
|
17
|
+
result = should_fail { assert { false } }
|
18
|
+
assert("failing returns false") { result.equal?(false) }
|
65
19
|
|
66
|
-
|
20
|
+
should_fail do
|
21
|
+
assert("falsy blocks fail") { nil }
|
22
|
+
assert("empty assertions fail") { }
|
23
|
+
|
24
|
+
assert("can not nest #assert") { assert("nested") { true }; nil }
|
25
|
+
assert("can not nest #group") { group("nested") { assert { true } }; nil }
|
26
|
+
assert("can not nest #err") { err("nested") { not_a_method }; nil }
|
27
|
+
end
|
67
28
|
|
68
|
-
|
29
|
+
should_err do
|
30
|
+
assert("errors are caught and count as failures") { not_a_method }
|
31
|
+
end
|
69
32
|
end
|
70
33
|
|
71
34
|
group "#group" do
|
72
|
-
|
73
|
-
|
35
|
+
expected = "example output"
|
36
|
+
result = group("EXAMPLE") do
|
74
37
|
assert("EXAMPLE") { true }
|
75
|
-
|
38
|
+
expected
|
76
39
|
end
|
77
|
-
|
78
|
-
result == "example output"
|
79
|
-
end
|
40
|
+
assert("returns output of block") { result == expected }
|
80
41
|
|
81
42
|
return_value = should_err { group { raise "Example Error" } }
|
82
|
-
|
83
|
-
assert "returns nil when the block throws an error" do
|
84
|
-
return_value.nil?
|
85
|
-
end
|
43
|
+
assert("returns nil when the block throws an error") { return_value.nil? }
|
86
44
|
|
87
45
|
group 'fails when empty' do
|
88
46
|
should_fail { group('group without content') { } }
|
@@ -96,43 +54,24 @@ group "#group" do
|
|
96
54
|
end
|
97
55
|
|
98
56
|
group "#err" do
|
99
|
-
|
100
|
-
err { not_a_method }
|
101
|
-
|
102
|
-
assert "and returns true" do
|
103
|
-
err { not_a_method }.equal?(true)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
should_fail { err("empty assertions fail") {} }
|
57
|
+
err("passes when there is an error") { not_a_method }
|
108
58
|
|
109
|
-
|
110
|
-
|
59
|
+
err("specify an exception class", expect: NameError) { not_a_method }
|
60
|
+
err("specify a parent exception class", expect: Exception) { not_a_method }
|
111
61
|
|
112
|
-
|
113
|
-
|
114
|
-
end
|
62
|
+
result = err { not_a_method }
|
63
|
+
assert("passing returns true") { result.equal?(true) }
|
115
64
|
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
end
|
65
|
+
result = should_fail { err { 1 + 1 } }
|
66
|
+
assert("failing returns false") { result.equal?(false) }
|
120
67
|
|
121
|
-
|
122
|
-
|
68
|
+
should_fail do
|
69
|
+
err("no errors fails") { 1 + 1 }
|
70
|
+
err("empty assertions fail") { }
|
71
|
+
err("wrong class fails", expect: ArgumentError) { not_a_method }
|
123
72
|
|
124
|
-
|
125
|
-
|
126
|
-
|
73
|
+
err("can not nest #err") { err("nested") { not_a_method }; 1 + 1 }
|
74
|
+
err("can not nest #assert") { assert("nested") { true }; 1 + 1 }
|
75
|
+
err("can not nest #group") { group("nested") { assert { true } }; 1 + 1 }
|
127
76
|
end
|
128
|
-
|
129
|
-
group "fails given wrong error class" do
|
130
|
-
should_fail { err(expect: ArgumentError) { not_a_method } }
|
131
|
-
|
132
|
-
assert "and returns false" do
|
133
|
-
should_fail { err(expect: ArgumentError) { not_a_method } }.equal?(false)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
should_fail { err("Can have a name") { 1+1 } }
|
138
77
|
end
|
data/lib/tet.rb
CHANGED
@@ -10,30 +10,36 @@ def group name = nil
|
|
10
10
|
before = Tet.test_count
|
11
11
|
|
12
12
|
Tet.in_group(name) do
|
13
|
-
yield.tap
|
13
|
+
yield.tap do
|
14
|
+
if Tet.test_count == before
|
15
|
+
Tet.log_fail("EMPTY GROUP")
|
16
|
+
end
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
21
|
# Declare that a block will return a truthy value.
|
18
22
|
# If it doesn't or if it has an error, the test will be logged as failing.
|
19
23
|
def assert name = nil
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
Tet.in_group(name) do
|
25
|
+
result = false
|
26
|
+
|
27
|
+
Tet.stop_nesting("NESTED IN ASSERT: #{name}") do
|
28
|
+
begin
|
29
|
+
result = yield
|
30
|
+
|
31
|
+
if result
|
32
|
+
Tet.log_pass
|
33
|
+
else
|
34
|
+
Tet.log_fail
|
35
|
+
end
|
36
|
+
rescue StandardError => error_object
|
37
|
+
Tet.log_error(error_object)
|
38
|
+
end
|
30
39
|
end
|
31
|
-
rescue StandardError => error_object
|
32
|
-
Tet.error(error_object)
|
33
|
-
end
|
34
40
|
|
35
|
-
|
36
|
-
|
41
|
+
!!result
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
# Declare that a block will have an error.
|
@@ -42,15 +48,17 @@ def err name = nil, expect: StandardError
|
|
42
48
|
Tet.in_group(name) do
|
43
49
|
result = false
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
Tet.stop_nesting("NESTED IN ERR: #{name}") do
|
52
|
+
begin
|
53
|
+
yield
|
54
|
+
Tet.log_fail
|
55
|
+
rescue StandardError => error_object
|
56
|
+
if expect >= error_object.class
|
57
|
+
result = true
|
58
|
+
Tet.log_pass
|
59
|
+
else
|
60
|
+
Tet.log_wrong_error(expected: expect, got: error_object)
|
61
|
+
end
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
@@ -70,6 +78,7 @@ module Tet
|
|
70
78
|
@test_count = 0
|
71
79
|
@fail_count = 0
|
72
80
|
@err_count = 0
|
81
|
+
@nested_ban = false
|
73
82
|
|
74
83
|
class << self
|
75
84
|
attr_reader :messages, :test_count, :fail_count, :err_count
|
@@ -81,9 +90,13 @@ module Tet
|
|
81
90
|
@current_group << name.to_s if name
|
82
91
|
|
83
92
|
begin
|
84
|
-
|
93
|
+
if @nested_ban
|
94
|
+
log_fail @nested_ban
|
95
|
+
else
|
96
|
+
result = yield
|
97
|
+
end
|
85
98
|
rescue StandardError => error_object
|
86
|
-
|
99
|
+
log_error error_object, "ERROR IN GROUP"
|
87
100
|
end
|
88
101
|
|
89
102
|
@current_group.pop if name
|
@@ -91,45 +104,56 @@ module Tet
|
|
91
104
|
result
|
92
105
|
end
|
93
106
|
|
107
|
+
def stop_nesting message
|
108
|
+
@nested_ban = message
|
109
|
+
yield
|
110
|
+
@nested_ban = false
|
111
|
+
end
|
112
|
+
|
94
113
|
# Log a passing test.
|
95
|
-
def
|
114
|
+
def log_pass
|
96
115
|
print_now PassChar
|
97
116
|
|
98
117
|
@test_count += 1
|
99
118
|
end
|
100
119
|
|
101
120
|
# Log a failing test.
|
102
|
-
def
|
121
|
+
def log_fail *messages, letter: FailChar
|
103
122
|
print_now letter
|
104
123
|
|
105
124
|
@test_count += 1
|
106
125
|
@fail_count += 1
|
107
126
|
|
108
|
-
group
|
109
|
-
|
127
|
+
group = @current_group.dup
|
128
|
+
current_section = @messages
|
110
129
|
|
111
|
-
until
|
130
|
+
# Walk down the tree of messages until either you find the current group's
|
131
|
+
# array of messages OR the last section in common with the current group.
|
132
|
+
until group.empty? || group.first != current_section[-2]
|
112
133
|
group.shift
|
113
|
-
|
134
|
+
current_section = current_section.last
|
114
135
|
end
|
115
136
|
|
137
|
+
# If the messages were missing parts of this group fill out the remaining
|
138
|
+
# group names.
|
116
139
|
until group.empty?
|
117
|
-
|
118
|
-
|
140
|
+
current_section << group.shift << []
|
141
|
+
current_section = current_section.last
|
119
142
|
end
|
120
143
|
|
121
|
-
section.
|
144
|
+
# Append the new messages onto the current section.
|
145
|
+
current_section.concat(messages)
|
122
146
|
end
|
123
147
|
|
124
148
|
# Log an error.
|
125
|
-
def
|
149
|
+
def log_error error_object, *messages
|
126
150
|
@err_count += 1
|
127
|
-
|
151
|
+
log_fail *messages, *format_error(error_object), letter: ErrorChar
|
128
152
|
end
|
129
153
|
|
130
154
|
# Log test which raised the wrong error.
|
131
|
-
def
|
132
|
-
|
155
|
+
def log_wrong_error expected:, got:
|
156
|
+
log_fail "EXPECTED: #{expected}", *format_error(got)
|
133
157
|
end
|
134
158
|
|
135
159
|
# Print stats and messages for all the failing tests.
|
@@ -173,16 +197,19 @@ module Tet
|
|
173
197
|
when String
|
174
198
|
input.gsub(/^/, Indent * amount)
|
175
199
|
when Array
|
176
|
-
input
|
177
|
-
|
178
|
-
|
200
|
+
input
|
201
|
+
.reject(&:empty?)
|
202
|
+
.map { |part| indent(part, amount + 1) }
|
203
|
+
.join("\n")
|
179
204
|
end
|
180
205
|
end
|
181
206
|
|
182
|
-
|
183
|
-
|
207
|
+
# Pluralize the given word.
|
208
|
+
def plural amount, word
|
209
|
+
"#{amount} #{word}#{amount != 1 ? "s" : ""}"
|
184
210
|
end
|
185
211
|
|
212
|
+
# Prevent delays in printing results.
|
186
213
|
def print_now string
|
187
214
|
print string
|
188
215
|
$stdout.flush
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Fulton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A very minimal test framework designed for simple projects. A couple
|
14
14
|
of features, relatively nice looking output, and nothing else. Does the world need
|