fledgling 1.0.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/LICENSE +202 -0
- data/README +62 -0
- data/lib/fledgling.rb +44 -0
- data/sig/fledgling.rbs +12 -0
- data/test/fledgling_test.rb +292 -0
- metadata +57 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Fledgling
|
|
2
|
+
|
|
3
|
+
Fledgling is a minimal Ruby testing library for testing better testing
|
|
4
|
+
libraries. It doesn't depend on anything beyond the Ruby platform and doesn't
|
|
5
|
+
modify the environment beyond its conventional namespace. The program that
|
|
6
|
+
tests it is written in primitive Ruby, with no other testing library, so it can
|
|
7
|
+
be verified straightforwardly.
|
|
8
|
+
|
|
9
|
+
Here's an example of a test program that uses Fledgling:
|
|
10
|
+
|
|
11
|
+
require "fledgling"
|
|
12
|
+
|
|
13
|
+
exit Fledgling.call STDOUT,
|
|
14
|
+
lambda {
|
|
15
|
+
unless "Hello, World!" == ["He", "", "o, Wor", "d!"].join("l")
|
|
16
|
+
raise "join did not work as expected"
|
|
17
|
+
end
|
|
18
|
+
},
|
|
19
|
+
lambda {
|
|
20
|
+
unless "sample" == "simple".gsub(/i/, "a")
|
|
21
|
+
raise "gsub did not work as expected"
|
|
22
|
+
end
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Fledgling.call runs a sequence of tests and reports information about any that
|
|
26
|
+
fail. It returns false if there were failures, true otherwise.
|
|
27
|
+
|
|
28
|
+
Fledgling.call expects two things from a test object: that it executes the test
|
|
29
|
+
when sent a call message and that it returns a description when sent a to_s
|
|
30
|
+
message. (Procs work well as test objects because they execute when sent a call
|
|
31
|
+
message and return a description string when sent a to_s message. The
|
|
32
|
+
description string typically includes the file path and line number where the
|
|
33
|
+
proc was defined.) A test can signal failure by raising a StandardError.
|
|
34
|
+
|
|
35
|
+
Fledgling.call uses the output stream (its first parameter) like this: when it
|
|
36
|
+
encounters a failure, Fledgling.call sends a puts message to the output stream
|
|
37
|
+
with five positional arguments: (1) "FAILED TEST:", (2) the test's description,
|
|
38
|
+
(3) "...ERROR:", (4) a description of the exception raised, and (5) an empty
|
|
39
|
+
string. It ignores the object returned. If you, for example, ran Fledgling.call
|
|
40
|
+
with the standard output stream (STDOUT or the initial value of $stdout) and a
|
|
41
|
+
lambda that ran a failing test, the output would resemble this:
|
|
42
|
+
|
|
43
|
+
FAILED TEST:
|
|
44
|
+
#<Proc:0x0000000fe2e010@test.rb:4 (lambda)>
|
|
45
|
+
...ERROR:
|
|
46
|
+
RuntimeError: join did not work as expected
|
|
47
|
+
test.rb:6:in `block in <main>'
|
|
48
|
+
[more backtrace lines]
|
|
49
|
+
[blank line]
|
|
50
|
+
|
|
51
|
+
If a test raises a non-StandardError exception, Fledgling.call interprets it as
|
|
52
|
+
a system-level event or fundamental problem: it immediately raises the
|
|
53
|
+
exception and doesn't run any more tests.
|
|
54
|
+
|
|
55
|
+
Fledgling's test program loads the Fledgling module if necessary, but does not
|
|
56
|
+
significantly change the runtime environment beyond that. Your test program can
|
|
57
|
+
set up the environment it wants to test (plus any test helpers) and execute
|
|
58
|
+
Fledgling's test program (with Kernel#load, for example) to check if Fledgling
|
|
59
|
+
works in that environment. If it detects a problem, it will raise an exception.
|
|
60
|
+
Otherwise, your program can use Fledgling to run tests -- now with more
|
|
61
|
+
evidence that it works as expected and with no significant changes to the
|
|
62
|
+
runtime environment.
|
data/lib/fledgling.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
##
|
|
2
|
+
# This module provides a minimal testing library for testing better testing
|
|
3
|
+
# libraries.
|
|
4
|
+
|
|
5
|
+
module Fledgling
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Runs tests, writes any failure information to the output stream, and
|
|
9
|
+
# returns a boolean indicating whether there were no failures.
|
|
10
|
+
#
|
|
11
|
+
# This method sends, in order, a call message with no arguments and no block
|
|
12
|
+
# to each object in tests. If sending a call message raises an exception
|
|
13
|
+
# whose class is neither StandardError nor a descendant of StandardError,
|
|
14
|
+
# this method immediately raises that exception. If sending a call message
|
|
15
|
+
# raises a StandardError, this method interprets it as a failure. It sends a
|
|
16
|
+
# puts message to ostream with no block and these arguments (positional, in
|
|
17
|
+
# order): a string "FAILED TEST:"; the string returned when a to_s message is
|
|
18
|
+
# sent to the test; a string "...ERROR:"; a string combining the class,
|
|
19
|
+
# string representation (via to_s), and backtrace of the exception; and an
|
|
20
|
+
# empty string. It ignores the object returned by the output stream and
|
|
21
|
+
# continues running tests. If sending a call message does not result in a
|
|
22
|
+
# raised exception, this method interprets it as a successful test. It
|
|
23
|
+
# ignores the object returned by the test and continues running tests. After
|
|
24
|
+
# it has run all the tests and handled any failures, this method returns
|
|
25
|
+
# false if there were failures, true otherwise. This method immediately
|
|
26
|
+
# raises any exception raised outside of a test.
|
|
27
|
+
|
|
28
|
+
def self.call ostream, *tests
|
|
29
|
+
no_failures = true
|
|
30
|
+
tests.each do |tst|
|
|
31
|
+
begin
|
|
32
|
+
tst.call
|
|
33
|
+
rescue ::StandardError => e
|
|
34
|
+
no_failures = false
|
|
35
|
+
# Like IO#puts, separate lines with \n rather than $\.
|
|
36
|
+
estr = ["#{e.class}: #{e}"].concat(e.backtrace || []).join "\n"
|
|
37
|
+
ostream.puts "FAILED TEST:", tst.to_s, "...ERROR:", estr, ""
|
|
38
|
+
end
|
|
39
|
+
nil
|
|
40
|
+
end
|
|
41
|
+
no_failures
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
data/sig/fledgling.rbs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# To abort and signal failure, this program raises an exception by running
|
|
2
|
+
# 0::FAIL. Why not raise an exception in the usual way, by sending a raise
|
|
3
|
+
# message? Because it's less reliable: the environment could be changed so that
|
|
4
|
+
# that doesn't raise an exception. Other fundamental expectations could still
|
|
5
|
+
# be subverted: #equal? could be redefined for all objects, error output could
|
|
6
|
+
# be suppressed, and so forth. But since conditionals (such as if, unless, and
|
|
7
|
+
# begin/rescue/else) and this raising idiom are reliable, the program can
|
|
8
|
+
# always conditionally raise an exception based on what the environment reports
|
|
9
|
+
# to it.
|
|
10
|
+
|
|
11
|
+
# Sections that create local variables are in class definitions so that later
|
|
12
|
+
# sections cannot accidentally reference those local variables.
|
|
13
|
+
|
|
14
|
+
# Constant references in blocks are fully qualified because this program must
|
|
15
|
+
# run correctly on a wide range of Ruby versions, including those in the 1.9.1
|
|
16
|
+
# and 1.9.2 branches. Ruby 1.9.1 and 1.9.2 used constant-lookup rules in
|
|
17
|
+
# certain situations that differed from those of earlier and later branches of
|
|
18
|
+
# Ruby.
|
|
19
|
+
|
|
20
|
+
require "fledgling"
|
|
21
|
+
|
|
22
|
+
# Fledgling should be a module.
|
|
23
|
+
0::FAIL unless Module.equal? Fledgling.class
|
|
24
|
+
|
|
25
|
+
# Fledgling should say it responds to call.
|
|
26
|
+
0::FAIL unless Fledgling.respond_to? :call
|
|
27
|
+
|
|
28
|
+
# Fledgling.call should raise an exception if called with no arguments.
|
|
29
|
+
begin
|
|
30
|
+
Fledgling.call
|
|
31
|
+
rescue ArgumentError
|
|
32
|
+
else
|
|
33
|
+
0::FAIL
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# If called with at least one argument, Fledgling.call should send one call
|
|
37
|
+
# message with no arguments and no block to each test -- all but the first
|
|
38
|
+
# argument -- assuming a previous test didn't raise a non-StandardError
|
|
39
|
+
# exception. Fledgling.call should take an arbitrary number of tests, up to
|
|
40
|
+
# some system limit.
|
|
41
|
+
class ::Object
|
|
42
|
+
Fledgling.call Object.new
|
|
43
|
+
|
|
44
|
+
test1 = Object.new
|
|
45
|
+
test1.instance_variable_set :@calls1, []
|
|
46
|
+
# Using singleton methods implicitly checks that Fledgling.call isn't binding
|
|
47
|
+
# the method to a different object. Ruby raises an exception in such cases.
|
|
48
|
+
def test1.call &b
|
|
49
|
+
@calls1 << b
|
|
50
|
+
end
|
|
51
|
+
Fledgling.call Object.new, test1
|
|
52
|
+
0::FAIL unless [nil] == test1.instance_variable_get(:@calls1)
|
|
53
|
+
|
|
54
|
+
test1.instance_variable_set :@calls1, []
|
|
55
|
+
test2 = Object.new
|
|
56
|
+
test2.instance_variable_set :@calls2, []
|
|
57
|
+
def test2.call &b
|
|
58
|
+
@calls2 << b
|
|
59
|
+
end
|
|
60
|
+
# Check that Fledgling.call doesn't ignore repeated tests.
|
|
61
|
+
Fledgling.call Object.new, test1, test2, test1, test2
|
|
62
|
+
0::FAIL unless [nil, nil] == test1.instance_variable_get(:@calls1)
|
|
63
|
+
0::FAIL unless [nil, nil] == test2.instance_variable_get(:@calls2)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Fledgling.call should call the tests in order.
|
|
67
|
+
class ::Object
|
|
68
|
+
calls = []
|
|
69
|
+
Fledgling.call Object.new, lambda { calls << 1 }, lambda { calls << 2 },
|
|
70
|
+
lambda { calls << 3 }
|
|
71
|
+
0::FAIL unless [1, 2, 3] == calls
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# If Fledgling.call calls a test that raises a non-StandardError exception, it
|
|
75
|
+
# should raise that exception immediately: it should call no additional tests,
|
|
76
|
+
# should not send any to_s messages to the test, and should not send any
|
|
77
|
+
# additional puts messages to the output stream.
|
|
78
|
+
class ::Object
|
|
79
|
+
ostream = Object.new
|
|
80
|
+
def ostream.puts(*)
|
|
81
|
+
0::FAIL
|
|
82
|
+
end
|
|
83
|
+
ex_class = Class.new Exception
|
|
84
|
+
calls = []
|
|
85
|
+
raising = lambda { ::Kernel.raise ex_class }
|
|
86
|
+
def raising.to_s
|
|
87
|
+
0::FAIL
|
|
88
|
+
end
|
|
89
|
+
begin
|
|
90
|
+
Fledgling.call ostream, lambda { calls << 1 }, raising,
|
|
91
|
+
lambda { calls << 3 }
|
|
92
|
+
rescue ex_class
|
|
93
|
+
else
|
|
94
|
+
0::FAIL
|
|
95
|
+
end
|
|
96
|
+
0::FAIL unless [1] == calls
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Fledgling.call should send a puts message to the output stream for each
|
|
100
|
+
# StandardError raised by the tests.
|
|
101
|
+
class ::Object
|
|
102
|
+
ostream = Object.new
|
|
103
|
+
ostream.instance_variable_set :@count, 0
|
|
104
|
+
def ostream.puts(*)
|
|
105
|
+
@count += 1
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
Fledgling.call ostream
|
|
109
|
+
0::FAIL unless 0 == ostream.instance_variable_get(:@count)
|
|
110
|
+
|
|
111
|
+
Fledgling.call ostream, lambda {}, lambda {}
|
|
112
|
+
0::FAIL unless 0 == ostream.instance_variable_get(:@count)
|
|
113
|
+
|
|
114
|
+
Fledgling.call ostream, lambda { ::Kernel.raise ::RuntimeError }, lambda {},
|
|
115
|
+
lambda { ::Kernel.raise ::StandardError }
|
|
116
|
+
0::FAIL unless 2 == ostream.instance_variable_get(:@count)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Fledgling.call should send a test description (obtained by sending to_s to
|
|
120
|
+
# the test), error details, and cosmetic strings to the output stream as puts
|
|
121
|
+
# arguments when a test raises a StandardError.
|
|
122
|
+
class ::Object
|
|
123
|
+
# A test shouldn't receive a to_s message if it didn't raise a StandardError.
|
|
124
|
+
tst = lambda {}
|
|
125
|
+
def tst.to_s
|
|
126
|
+
0::FAIL
|
|
127
|
+
end
|
|
128
|
+
Fledgling.call Object.new, tst, tst
|
|
129
|
+
|
|
130
|
+
# Freeze some objects to test if the method naively attempts to mutate them.
|
|
131
|
+
ex_class = Class.new StandardError
|
|
132
|
+
def ex_class.to_s
|
|
133
|
+
"TestError".freeze
|
|
134
|
+
end
|
|
135
|
+
ex_nil_bt = ex_class.new "a".freeze
|
|
136
|
+
def ex_nil_bt.backtrace
|
|
137
|
+
nil
|
|
138
|
+
end
|
|
139
|
+
ex_nonnil_bt = ex_class.new "b".freeze
|
|
140
|
+
def ex_nonnil_bt.backtrace
|
|
141
|
+
["X".freeze, "Y".freeze].freeze
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
ostream = Object.new
|
|
145
|
+
ostream.instance_variable_set :@calls, []
|
|
146
|
+
# Using singleton methods implicitly checks that Fledgling.call isn't binding
|
|
147
|
+
# the method to a different object. Ruby raises an exception in such cases.
|
|
148
|
+
def ostream.puts *args, &b
|
|
149
|
+
@calls << [args, b]
|
|
150
|
+
end
|
|
151
|
+
a = lambda { ::Kernel.raise ex_nil_bt }
|
|
152
|
+
b = lambda { ::Kernel.raise ex_nonnil_bt }
|
|
153
|
+
def a.to_s
|
|
154
|
+
"A"
|
|
155
|
+
end
|
|
156
|
+
def b.to_s
|
|
157
|
+
"B"
|
|
158
|
+
end
|
|
159
|
+
Fledgling.call ostream, a, lambda {}, b
|
|
160
|
+
0::FAIL unless [[["FAILED TEST:", "A", "...ERROR:", "TestError: a", ""],
|
|
161
|
+
nil], [["FAILED TEST:", "B", "...ERROR:", "TestError: b\nX\nY", ""], nil]
|
|
162
|
+
] == ostream.instance_variable_get(:@calls)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Fledgling.call should return false if it returns at all and any of the tests
|
|
166
|
+
# raised a StandardError. It should ignore the return values when sending puts
|
|
167
|
+
# messages to the output stream and when sending call messages to the tests.
|
|
168
|
+
class ::Object
|
|
169
|
+
ostream1 = Object.new
|
|
170
|
+
def ostream1.puts(*)
|
|
171
|
+
"string"
|
|
172
|
+
end
|
|
173
|
+
ostream2 = Object.new
|
|
174
|
+
def ostream2.puts(*)
|
|
175
|
+
nil
|
|
176
|
+
end
|
|
177
|
+
ret = Fledgling.call ostream1, lambda { ::Kernel.raise ::StandardError },
|
|
178
|
+
lambda { "string" }
|
|
179
|
+
0::FAIL unless false.equal? ret
|
|
180
|
+
ret = Fledgling.call ostream2, lambda { ::Kernel.raise ::StandardError },
|
|
181
|
+
lambda { nil }
|
|
182
|
+
0::FAIL unless false.equal? ret
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Fledgling.call should return true if it returns at all and none of the tests
|
|
186
|
+
# raised a StandardError. It should ignore the return values when sending call
|
|
187
|
+
# messages to the tests.
|
|
188
|
+
class ::Object
|
|
189
|
+
0::FAIL unless true.equal? Fledgling.call(Object.new)
|
|
190
|
+
ret = Fledgling.call Object.new, lambda { "string" }, lambda { nil }
|
|
191
|
+
0::FAIL unless true.equal? ret
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# When sending a puts message to the output stream raises an exception,
|
|
195
|
+
# Fledgling.call should immediately raise that exception.
|
|
196
|
+
class ::Object
|
|
197
|
+
ostream = Object.new
|
|
198
|
+
ostream.instance_variable_set :@ex, ex = StandardError.new
|
|
199
|
+
def ostream.puts(*)
|
|
200
|
+
::Kernel.raise @ex
|
|
201
|
+
end
|
|
202
|
+
calls = []
|
|
203
|
+
begin
|
|
204
|
+
Fledgling.call ostream, lambda { ::Kernel.raise ::StandardError },
|
|
205
|
+
lambda { calls << nil }
|
|
206
|
+
rescue StandardError => rescued
|
|
207
|
+
0::FAIL unless ex.equal? rescued
|
|
208
|
+
else
|
|
209
|
+
0::FAIL
|
|
210
|
+
end
|
|
211
|
+
0::FAIL unless [] == calls
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# When the output stream doesn't respond to puts and a test raises a
|
|
215
|
+
# StandardError, Fledgling.call should immediately raise an exception when
|
|
216
|
+
# sending a puts message.
|
|
217
|
+
class ::Object
|
|
218
|
+
calls = []
|
|
219
|
+
begin
|
|
220
|
+
Fledgling.call Object.new, lambda { ::Kernel.raise ::StandardError },
|
|
221
|
+
lambda { calls << nil }
|
|
222
|
+
rescue NoMethodError
|
|
223
|
+
else
|
|
224
|
+
0::FAIL
|
|
225
|
+
end
|
|
226
|
+
0::FAIL unless [] == calls
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
# When a test does not respond to call, Fledgling.call should treat it as a
|
|
230
|
+
# test failure.
|
|
231
|
+
class ::Object
|
|
232
|
+
ostream = Object.new
|
|
233
|
+
ostream.instance_variable_set :@error_strings, []
|
|
234
|
+
def ostream.puts *args
|
|
235
|
+
@error_strings << args.fetch(3)
|
|
236
|
+
end
|
|
237
|
+
Fledgling.call ostream, Object.new, Object.new
|
|
238
|
+
error_strings = ostream.instance_variable_get :@error_strings
|
|
239
|
+
0::FAIL unless 2 == error_strings.length
|
|
240
|
+
0::FAIL unless /\ANoMethodError: / =~ error_strings.fetch(0)
|
|
241
|
+
0::FAIL unless /\ANoMethodError: / =~ error_strings.fetch(1)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# When a test raises a StandardError that raises an exception when queried,
|
|
245
|
+
# Fledgling.call should immediately raise the exception triggered by the query.
|
|
246
|
+
class ::Object
|
|
247
|
+
call_ex = StandardError.new
|
|
248
|
+
call_ex.instance_variable_set :@to_s_ex, to_s_ex = StandardError.new
|
|
249
|
+
def call_ex.to_s
|
|
250
|
+
::Kernel.raise @to_s_ex
|
|
251
|
+
end
|
|
252
|
+
calls = []
|
|
253
|
+
begin
|
|
254
|
+
Fledgling.call Object.new, lambda { ::Kernel.raise call_ex },
|
|
255
|
+
lambda { calls << nil }
|
|
256
|
+
rescue StandardError => rescued
|
|
257
|
+
0::FAIL unless to_s_ex.equal? rescued
|
|
258
|
+
else
|
|
259
|
+
0::FAIL
|
|
260
|
+
end
|
|
261
|
+
0::FAIL unless [] == calls
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
# When a test raises a StandardError when called and also raises an exception
|
|
265
|
+
# when converting to a string, Fledgling.call should immediately raise the
|
|
266
|
+
# exception triggered by the attempted conversion to a string.
|
|
267
|
+
class ::Object
|
|
268
|
+
call_ex = StandardError.new
|
|
269
|
+
tst = lambda { ::Kernel.raise call_ex }
|
|
270
|
+
tst.instance_variable_set :@to_s_ex, to_s_ex = StandardError.new
|
|
271
|
+
def tst.to_s
|
|
272
|
+
::Kernel.raise @to_s_ex
|
|
273
|
+
end
|
|
274
|
+
calls = []
|
|
275
|
+
begin
|
|
276
|
+
Fledgling.call Object.new, tst, lambda { calls << nil }
|
|
277
|
+
rescue StandardError => rescued
|
|
278
|
+
0::FAIL unless to_s_ex.equal? rescued
|
|
279
|
+
else
|
|
280
|
+
0::FAIL
|
|
281
|
+
end
|
|
282
|
+
0::FAIL unless [] == calls
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# Fledgling.call should not attempt to mutate the output stream or tests.
|
|
286
|
+
class ::Object
|
|
287
|
+
ostream = Object.new
|
|
288
|
+
def ostream.puts(*)
|
|
289
|
+
end
|
|
290
|
+
ostream.freeze
|
|
291
|
+
Fledgling.call ostream, lambda {}.freeze, lambda { ::Kernel.raise }.freeze
|
|
292
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fledgling
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Aaron Beckerman
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2026-05-31 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
email:
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- LICENSE
|
|
26
|
+
- README
|
|
27
|
+
- lib/fledgling.rb
|
|
28
|
+
- sig/fledgling.rbs
|
|
29
|
+
- test/fledgling_test.rb
|
|
30
|
+
has_rdoc: true
|
|
31
|
+
homepage:
|
|
32
|
+
licenses:
|
|
33
|
+
- Apache-2.0
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 1.8.7
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: "0"
|
|
49
|
+
requirements: []
|
|
50
|
+
|
|
51
|
+
rubyforge_project:
|
|
52
|
+
rubygems_version: 1.6.2
|
|
53
|
+
signing_key:
|
|
54
|
+
specification_version: 3
|
|
55
|
+
summary: A minimal testing library for testing better testing libraries
|
|
56
|
+
test_files: []
|
|
57
|
+
|