fledgling 2.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 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,65 @@
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 seven positional arguments: (1) "FAILED TEST:", (2) the test converted to
38
+ a string, (3) "...ERROR:", (4) the exception's class converted to a string, (5)
39
+ the exception converted to a string, (6) the exception's backtrace array or an
40
+ empty array if it has no backtrace, and (7) an empty string. It ignores the
41
+ object returned. If you, for example, ran Fledgling.call with the standard
42
+ output stream (STDOUT or the initial value of $stdout) and a lambda that ran a
43
+ failing test, the output would resemble this:
44
+
45
+ FAILED TEST:
46
+ #<Proc:0x0000000fe2e010@test.rb:4 (lambda)>
47
+ ...ERROR:
48
+ RuntimeError
49
+ join did not work as expected
50
+ test.rb:6:in `block in <main>'
51
+ [more backtrace lines]
52
+ [blank line]
53
+
54
+ If a test raises a non-StandardError exception, Fledgling.call interprets it as
55
+ a system-level event or fundamental problem: it immediately raises the
56
+ exception and doesn't run any more tests.
57
+
58
+ Fledgling's test program loads the Fledgling module if necessary, but does not
59
+ significantly change the runtime environment beyond that. Your test program can
60
+ set up the environment it wants to test (plus any test helpers) and execute
61
+ Fledgling's test program (with Kernel#load, for example) to check if Fledgling
62
+ works in that environment. If it detects a problem, it will raise an exception.
63
+ Otherwise, your program can use Fledgling to run tests -- now with more
64
+ evidence that it works as expected and with no significant changes to the
65
+ runtime environment.
data/lib/fledgling.rb ADDED
@@ -0,0 +1,47 @@
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 test converted to a string via to_s, a
18
+ # string "...ERROR:", the exception's class converted to a string via to_s,
19
+ # the exception converted to a string via to_s, the exception's backtrace or
20
+ # an empty array if the exception signals that it has no backtrace, and an
21
+ # empty string. It ignores the object returned by the output stream and
22
+ # continues running tests. If sending a call message does not result in a
23
+ # raised exception, this method interprets it as a successful test. It
24
+ # ignores the object returned by the test and continues running tests. After
25
+ # it has run all the tests and handled any failures, this method returns
26
+ # false if there were failures, true otherwise. This method immediately
27
+ # raises any exception raised outside of a test.
28
+
29
+ def self.call ostream, *tests
30
+ no_failures = true
31
+ tests.each do |tst|
32
+ begin
33
+ tst.call
34
+ rescue ::StandardError => e
35
+ no_failures = false
36
+ ostream.puts "FAILED TEST:", tst.to_s, "...ERROR:", e.class.to_s,
37
+ e.to_s, e.backtrace || [], ""
38
+ end
39
+ # Always return nil so that an each that's been modified to be sensitive
40
+ # to the block's return value can't behave differently based on the
41
+ # objects returned by the tests and the output stream.
42
+ nil
43
+ end
44
+ no_failures
45
+ end
46
+
47
+ end
data/sig/fledgling.rbs ADDED
@@ -0,0 +1,13 @@
1
+ module Fledgling
2
+ interface _OutputStream
3
+ def puts: (::String, ::String, ::String, ::String, ::String,
4
+ ::Array[::String], ::String) -> void
5
+ end
6
+
7
+ interface _Test
8
+ def call: () -> void
9
+ def to_s: () -> ::String
10
+ end
11
+
12
+ def self.call: (_OutputStream, *_Test) -> bool
13
+ end
@@ -0,0 +1,347 @@
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
+ # When this program supplies an exception to check how Fledgling handles it, it
21
+ # gives the exception a frozen message string. This makes the exception behave
22
+ # more consistently across Ruby versions.
23
+
24
+ require "fledgling"
25
+
26
+ # Fledgling should be a module.
27
+ 0::FAIL unless Module.equal? Fledgling.class
28
+
29
+ # Fledgling should say it responds to call.
30
+ 0::FAIL unless Fledgling.respond_to? :call
31
+
32
+ # Fledgling.call should raise an exception if called with no arguments.
33
+ begin
34
+ Fledgling.call
35
+ rescue ArgumentError
36
+ else
37
+ 0::FAIL
38
+ end
39
+
40
+ # If called with at least one argument, Fledgling.call should send one call
41
+ # message with no arguments and no block to each test -- all but the first
42
+ # argument -- assuming a previous test didn't raise a non-StandardError
43
+ # exception. Fledgling.call should take an arbitrary number of tests, up to
44
+ # some system limit.
45
+ class ::Object
46
+ Fledgling.call Object.new
47
+
48
+ test1 = Object.new
49
+ test1.instance_variable_set :@calls1, []
50
+ # Using singleton methods implicitly checks that Fledgling.call isn't binding
51
+ # the method to a different object. Ruby raises an exception in such cases.
52
+ def test1.call &b
53
+ @calls1 << b
54
+ end
55
+ Fledgling.call Object.new, test1
56
+ 0::FAIL unless [nil] == test1.instance_variable_get(:@calls1)
57
+
58
+ test1.instance_variable_set :@calls1, []
59
+ test2 = Object.new
60
+ test2.instance_variable_set :@calls2, []
61
+ def test2.call &b
62
+ @calls2 << b
63
+ end
64
+ # Check that Fledgling.call doesn't ignore repeated tests.
65
+ Fledgling.call Object.new, test1, test2, test1, test2
66
+ 0::FAIL unless [nil, nil] == test1.instance_variable_get(:@calls1)
67
+ 0::FAIL unless [nil, nil] == test2.instance_variable_get(:@calls2)
68
+ end
69
+
70
+ # Fledgling.call should call the tests in order.
71
+ class ::Object
72
+ calls = []
73
+ Fledgling.call Object.new, lambda { calls << 1 }, lambda { calls << 2 },
74
+ lambda { calls << 3 }
75
+ 0::FAIL unless [1, 2, 3] == calls
76
+ end
77
+
78
+ # If Fledgling.call calls a test that raises a non-StandardError exception, it
79
+ # should raise that exception immediately: it should call no additional tests,
80
+ # should not send any to_s messages to the test, and should not send any
81
+ # additional puts messages to the output stream.
82
+ class ::Object
83
+ ostream = Object.new
84
+ def ostream.puts(*)
85
+ 0::FAIL
86
+ end
87
+ ex_class = Class.new Exception
88
+ calls = []
89
+ raising = lambda { ::Kernel.raise ex_class, "m".freeze }
90
+ def raising.to_s
91
+ 0::FAIL
92
+ end
93
+ begin
94
+ Fledgling.call ostream, lambda { calls << 1 }, raising,
95
+ lambda { calls << 3 }
96
+ rescue ex_class
97
+ else
98
+ 0::FAIL
99
+ end
100
+ 0::FAIL unless [1] == calls
101
+ end
102
+
103
+ # Fledgling.call should send a puts message to the output stream for each
104
+ # StandardError raised by the tests.
105
+ class ::Object
106
+ ostream = Object.new
107
+ ostream.instance_variable_set :@count, 0
108
+ def ostream.puts(*)
109
+ @count += 1
110
+ end
111
+
112
+ Fledgling.call ostream
113
+ 0::FAIL unless 0 == ostream.instance_variable_get(:@count)
114
+
115
+ Fledgling.call ostream, lambda {}, lambda {}
116
+ 0::FAIL unless 0 == ostream.instance_variable_get(:@count)
117
+
118
+ Fledgling.call ostream, lambda { ::Kernel.raise ::RuntimeError, "m".freeze },
119
+ lambda {}, lambda { ::Kernel.raise ::StandardError, "m".freeze }
120
+ 0::FAIL unless 2 == ostream.instance_variable_get(:@count)
121
+ end
122
+
123
+ # Fledgling.call should send a test description (obtained by sending to_s to
124
+ # the test), error details, and cosmetic strings to the output stream as puts
125
+ # arguments when a test raises a StandardError.
126
+ class ::Object
127
+ # A test shouldn't receive a to_s message if it didn't raise a StandardError.
128
+ tst = lambda {}
129
+ def tst.to_s
130
+ 0::FAIL
131
+ end
132
+ 0::FAIL unless true.equal? Fledgling.call(Object.new, tst, tst)
133
+
134
+ # Freeze some objects to test if the method naively attempts to mutate them.
135
+ ex_class = Class.new StandardError
136
+ ex_class.instance_variable_set :@str, ex_class_name = "TestError".freeze
137
+ def ex_class.to_s
138
+ @str
139
+ end
140
+
141
+ ex_nil_bt = ex_class.new "m".freeze
142
+ ex_nil_bt.instance_variable_set :@str, ex_nil_bt_s = "a".freeze
143
+ def ex_nil_bt.to_s
144
+ @str
145
+ end
146
+ def ex_nil_bt.message
147
+ # We'll verify that a to_s message is sent, not a message message.
148
+ "?!" + @str
149
+ end
150
+ def ex_nil_bt.backtrace
151
+ nil
152
+ end
153
+
154
+ ex_nonnil_bt = ex_class.new "m".freeze
155
+ ex_nonnil_bt.instance_variable_set :@str, ex_nonnil_bt_s = "b".freeze
156
+ def ex_nonnil_bt.to_s
157
+ @str
158
+ end
159
+ def ex_nonnil_bt.message
160
+ # We'll verify that a to_s message is sent, not a message message.
161
+ "?!" + @str
162
+ end
163
+ ex_nonnil_bt.instance_variable_set :@backtrace,
164
+ backtrace_b = ["X".freeze, "Y".freeze].freeze
165
+ def ex_nonnil_bt.backtrace
166
+ @backtrace
167
+ end
168
+
169
+ ostream = Object.new
170
+ ostream.instance_variable_set :@calls, []
171
+ # Using singleton methods implicitly checks that Fledgling.call isn't binding
172
+ # the method to a different object. Ruby raises an exception in such cases.
173
+ def ostream.puts *args, &b
174
+ @calls << [args, b]
175
+ end
176
+ a = lambda { ::Kernel.raise ex_nil_bt }
177
+ a.instance_variable_set :@str, a_s = "A".freeze
178
+ def a.to_s
179
+ @str
180
+ end
181
+ b = lambda { ::Kernel.raise ex_nonnil_bt }
182
+ b.instance_variable_set :@str, b_s = "B".freeze
183
+ def b.to_s
184
+ @str
185
+ end
186
+ Fledgling.call ostream, a, lambda {}, b
187
+
188
+ calls = ostream.instance_variable_get :@calls
189
+ 0::FAIL unless 2 == calls.length
190
+
191
+ 0::FAIL unless 7 == calls[0][0].length
192
+ 0::FAIL unless "FAILED TEST:" == calls[0][0][0]
193
+ 0::FAIL unless a_s.equal? calls[0][0][1]
194
+ 0::FAIL unless "...ERROR:" == calls[0][0][2]
195
+ 0::FAIL unless ex_class_name.equal? calls[0][0][3]
196
+ 0::FAIL unless ex_nil_bt_s.equal? calls[0][0][4]
197
+ 0::FAIL unless [] == calls[0][0][5]
198
+ 0::FAIL unless "" == calls[0][0][6]
199
+ 0::FAIL unless nil.equal? calls[0][1]
200
+
201
+ 0::FAIL unless 7 == calls[1][0].length
202
+ 0::FAIL unless "FAILED TEST:" == calls[1][0][0]
203
+ 0::FAIL unless b_s.equal? calls[1][0][1]
204
+ 0::FAIL unless "...ERROR:" == calls[1][0][2]
205
+ 0::FAIL unless ex_class_name.equal? calls[1][0][3]
206
+ 0::FAIL unless ex_nonnil_bt_s.equal? calls[1][0][4]
207
+ 0::FAIL unless backtrace_b.equal? calls[1][0][5]
208
+ 0::FAIL unless "" == calls[1][0][6]
209
+ 0::FAIL unless nil.equal? calls[1][1]
210
+ end
211
+
212
+ # Fledgling.call should return false if it returns at all and any of the tests
213
+ # raised a StandardError. It should ignore the return values when sending puts
214
+ # messages to the output stream and when sending call messages to the tests.
215
+ class ::Object
216
+ ostream1 = Object.new
217
+ def ostream1.puts(*)
218
+ "string"
219
+ end
220
+ ostream2 = Object.new
221
+ def ostream2.puts(*)
222
+ nil
223
+ end
224
+ ret = Fledgling.call ostream1, lambda { ::Kernel.raise ::StandardError,
225
+ "m".freeze }, lambda { "string" }
226
+ 0::FAIL unless false.equal? ret
227
+ ret = Fledgling.call ostream2, lambda { ::Kernel.raise ::StandardError,
228
+ "m".freeze }, lambda { nil }
229
+ 0::FAIL unless false.equal? ret
230
+ end
231
+
232
+ # Fledgling.call should return true if it returns at all and none of the tests
233
+ # raised a StandardError. It should ignore the return values when sending call
234
+ # messages to the tests.
235
+ class ::Object
236
+ 0::FAIL unless true.equal? Fledgling.call(Object.new)
237
+ ret = Fledgling.call Object.new, lambda { "string" }, lambda { nil }
238
+ 0::FAIL unless true.equal? ret
239
+ end
240
+
241
+ # When sending a puts message to the output stream raises an exception,
242
+ # Fledgling.call should immediately raise that exception.
243
+ class ::Object
244
+ ostream = Object.new
245
+ ostream.instance_variable_set :@ex, ex = StandardError.new("m".freeze)
246
+ def ostream.puts(*)
247
+ ::Kernel.raise @ex
248
+ end
249
+ calls = []
250
+ begin
251
+ Fledgling.call ostream, lambda { ::Kernel.raise ::StandardError, "m".freeze
252
+ }, lambda { calls << nil }
253
+ rescue StandardError => rescued
254
+ 0::FAIL unless ex.equal? rescued
255
+ else
256
+ 0::FAIL
257
+ end
258
+ 0::FAIL unless [] == calls
259
+ end
260
+
261
+ # When the output stream doesn't respond to puts and a test raises a
262
+ # StandardError, Fledgling.call should immediately raise an exception when
263
+ # sending a puts message.
264
+ class ::Object
265
+ calls = []
266
+ begin
267
+ Fledgling.call Object.new, lambda { ::Kernel.raise ::StandardError,
268
+ "m".freeze }, lambda { calls << nil }
269
+ rescue NoMethodError
270
+ else
271
+ 0::FAIL
272
+ end
273
+ 0::FAIL unless [] == calls
274
+ end
275
+
276
+ # When a test does not respond to call, Fledgling.call should treat it as a
277
+ # test failure.
278
+ class ::Object
279
+ ostream = Object.new
280
+ ostream.instance_variable_set :@error_strings, []
281
+ def ostream.puts *args
282
+ @error_strings << args.fetch(3)
283
+ end
284
+ Fledgling.call ostream, Object.new, Object.new
285
+ error_strings = ostream.instance_variable_get :@error_strings
286
+ 0::FAIL unless 2 == error_strings.length
287
+ 0::FAIL unless "NoMethodError" == error_strings.fetch(0)
288
+ 0::FAIL unless "NoMethodError" == error_strings.fetch(1)
289
+ end
290
+
291
+ # When a test raises a StandardError that raises an exception when queried,
292
+ # Fledgling.call should immediately raise the exception triggered by the query.
293
+ #
294
+ # It's impractical to portably test an exception that raises when it receives a
295
+ # backtrace message. An exception that raises when it receives a to_s message
296
+ # stands in for this entire class of situations.
297
+ class ::Object
298
+ call_ex = StandardError.new "m".freeze
299
+ call_ex.instance_variable_set :@to_s_ex,
300
+ to_s_ex = StandardError.new("m".freeze)
301
+ def call_ex.to_s
302
+ ::Kernel.raise @to_s_ex
303
+ end
304
+ calls = []
305
+ begin
306
+ Fledgling.call Object.new, lambda { ::Kernel.raise call_ex },
307
+ lambda { calls << nil }
308
+ rescue StandardError => rescued
309
+ 0::FAIL unless to_s_ex.equal? rescued
310
+ else
311
+ 0::FAIL
312
+ end
313
+ 0::FAIL unless [] == calls
314
+ end
315
+
316
+ # When a test raises a StandardError when called and also raises an exception
317
+ # when converting to a string, Fledgling.call should immediately raise the
318
+ # exception triggered by the attempted conversion to a string.
319
+ class ::Object
320
+ call_ex = StandardError.new "m".freeze
321
+ tst = lambda { ::Kernel.raise call_ex }
322
+ tst.instance_variable_set :@to_s_ex, to_s_ex = StandardError.new("m".freeze)
323
+ def tst.to_s
324
+ ::Kernel.raise @to_s_ex
325
+ end
326
+ calls = []
327
+ begin
328
+ Fledgling.call Object.new, tst, lambda { calls << nil }
329
+ rescue StandardError => rescued
330
+ 0::FAIL unless to_s_ex.equal? rescued
331
+ else
332
+ 0::FAIL
333
+ end
334
+ 0::FAIL unless [] == calls
335
+ end
336
+
337
+ # Fledgling.call should not attempt to mutate the output stream or tests.
338
+ class ::Object
339
+ ostream = Object.new
340
+ def ostream.puts(*)
341
+ end
342
+ ostream.freeze
343
+ 0::FAIL unless true.equal? Fledgling.call(ostream, lambda {}.freeze)
344
+ 0::FAIL unless false.equal?(
345
+ Fledgling.call(ostream, lambda { ::Kernel.raise ::StandardError, "m".freeze
346
+ }.freeze))
347
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fledgling
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Beckerman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2026-06-12 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
+