blackstart 0.5.0 → 0.9.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.
@@ -2,8 +2,9 @@ Blackstart
2
2
 
3
3
  Blackstart is a small, subdued library for automated testing in Ruby. It
4
4
  doesn't depend on anything beyond the Ruby platform and doesn't modify the
5
- environment beyond its conventional namespace. It's tested with a primitive
6
- program, not via an automated-testing library.
5
+ environment beyond its conventional namespace. The program that tests it is
6
+ written in primitive Ruby, with no other testing library, so it can be verified
7
+ straightforwardly.
7
8
 
8
9
  The blackstart is a small, subdued bird that eats bugs. A black start is when
9
10
  an inactive power plant restarts by means of an independent power source rather
@@ -14,13 +15,13 @@ Here's an example of a test program that uses Blackstart:
14
15
  require "blackstart"
15
16
 
16
17
  exit Blackstart.run [
17
- proc {
18
+ lambda {
18
19
  unless "Hello, World!" == ["He", "", "o, Wor", "d!"].join("l")
19
20
  raise "join did not work as expected"
20
21
  end
21
22
  },
22
23
 
23
- proc {
24
+ lambda {
24
25
  unless "sample" == "simple".gsub(/i/, "a")
25
26
  raise "gsub did not work as expected"
26
27
  end
@@ -41,14 +42,29 @@ calling it in the context of a new instance of Blackstart::Scratchpad; if and
41
42
  only if this raises an error (any exception that's a kind of StandardError),
42
43
  Blackstart.run interprets it as a failed test.
43
44
 
44
- After each test failure, Blackstart.run sends a puts message with failure
45
- information to its second parameter, which is $stdout by default. The failure
46
- information includes a description of the test (the test object converted to a
47
- string) and a description of the error raised (its class, message, and
48
- backtrace).
45
+ After each test failure, Blackstart.run sends a puts message to the output
46
+ stream -- its second parameter, which is $stdout by default -- with seven
47
+ positional arguments: (1) "FAILED TEST:", (2) the test object converted to a
48
+ string, (3) "...ERROR:", (4) the error's class converted to a string, (5) the
49
+ error converted to a string, (6) the error's backtrace array or an empty array
50
+ if it has no backtrace, and (7) an empty string. With the standard output
51
+ stream, a failure produces output resembling this:
49
52
 
50
- The library provides little beyond this, but it's easy to do sophisticated
51
- things with it. Some examples follow.
53
+ FAILED TEST:
54
+ #<Proc:0x0000000fe2e010@test.rb:4 (lambda)>
55
+ ...ERROR:
56
+ RuntimeError
57
+ join did not work as expected
58
+ test.rb:6:in `block in <main>'
59
+ [more backtrace lines]
60
+ [blank line]
61
+
62
+ If a test raises a non-StandardError exception, Blackstart.run interprets it as
63
+ a system-level event or fundamental problem: it immediately raises the
64
+ exception and doesn't run any more tests.
65
+
66
+ The library provides little beyond this, but it supports more sophisticated
67
+ uses. Some examples follow.
52
68
 
53
69
 
54
70
  - Exiting with the appropriate status
@@ -104,8 +120,8 @@ Blackstart::Scratchpad#instance_exec. For example:
104
120
  end
105
121
  end
106
122
 
107
- Use this hack with care because the test proc could send instance_exec messages
108
- to self.
123
+ Use this technique with care because the test proc could send instance_exec
124
+ messages to self.
109
125
 
110
126
 
111
127
  - Building a test collection in stages
@@ -118,7 +134,7 @@ can be done straightforwardly:
118
134
  TESTS = []
119
135
 
120
136
  TESTS.concat [
121
- proc {
137
+ lambda {
122
138
  unless "Hello, World!" == ["He", "", "o, Wor", "d!"].join("l")
123
139
  raise "join did not work as expected"
124
140
  end
@@ -126,7 +142,7 @@ can be done straightforwardly:
126
142
  ]
127
143
 
128
144
  TESTS.concat [
129
- proc {
145
+ lambda {
130
146
  unless "sample" == "simple".gsub(/i/, "a")
131
147
  raise "gsub did not work as expected"
132
148
  end
@@ -174,3 +190,13 @@ stream is $stdout, so the default behavior is to print unadorned failure
174
190
  information to standard output. But you can specify any object as the output
175
191
  stream -- even if it's not really a stream -- allowing you to handle failure
176
192
  information however you want.
193
+
194
+
195
+ - Running multiple tests at the same time
196
+
197
+ Although Blackstart.run is written in a sequential style, it can run multiple
198
+ tests at the same time. Blackstart.run sends an each message with a block to
199
+ your test collection, expecting the block to be executed once for each test;
200
+ your test collection can execute the block in multiple threads concurrently.
201
+ For your program to work well in this mode, your tests and the output stream
202
+ must work correctly when used from multiple threads.
data/lib/blackstart.rb CHANGED
@@ -3,28 +3,6 @@
3
3
 
4
4
  module Blackstart
5
5
 
6
- ##
7
- # Yields to the block and returns a string describing the error raised, if
8
- # any.
9
- #
10
- # In detail: This method yields to the block with no arguments. If that
11
- # raises an error -- meaning an exception whose class is StandardError or a
12
- # descendant of StandardError -- this method attempts to make and return a
13
- # string describing that error; the description consists of the error's
14
- # class, message, and backtrace (if any). If an exception is raised while
15
- # making an error description, this method raises that exception. If
16
- # yielding to the block raises a non-error exception, this method raises that
17
- # exception. If yielding to the block does not raise an exception, this
18
- # method returns nil.
19
-
20
- def self.vet
21
- yield
22
- nil
23
- rescue ::StandardError
24
- # Like IO#puts, separate lines with a line feed character rather than $\.
25
- ["#{$!.class}: #{$!.message}"].concat($!.backtrace || []).join "\n"
26
- end
27
-
28
6
  ##
29
7
  # A class for tests' disposable helper objects.
30
8
 
@@ -40,36 +18,49 @@ module Blackstart
40
18
  # test object in the sequence with that test object as the first argument.
41
19
  # Each test involves creating a new scratchpad -- an instance of
42
20
  # Blackstart::Scratchpad -- and sending an instance_exec message to it with
43
- # the test object as a block argument, which converts the test object to a
44
- # proc via to_proc if it's not already a proc. The resulting proc is called
45
- # with no arguments; the self object is set to the scratchpad. A failure is
46
- # when the test (which includes any initial conversion to a proc) raises an
47
- # error: an exception whose class is StandardError or a descendant of
21
+ # the test object as the block, which converts the test object to a proc via
22
+ # to_proc if it's not already a proc. The resulting proc is called with no
23
+ # arguments and no block; the self object is set to the scratchpad. A failure
24
+ # is when the test (which includes any initial conversion to a proc) raises
25
+ # an error: an exception whose class is StandardError or a descendant of
48
26
  # StandardError. After a failure, this method sends a puts message to the
49
- # output stream, ostream, with these arguments (positional, in order): a
50
- # string "FAILED TEST:"; the test object converted to a string via to_s; a
51
- # string "...ERROR:"; a string combining the class, message, and backtrace of
52
- # the error; and an empty string. If a test raises a non-error exception,
53
- # this method immediately raises that exception. After it has run all the
54
- # tests and handled any failures, this method returns false if there were
55
- # failures, true otherwise. This method immediately raises any exception
56
- # raised outside of a test.
27
+ # output stream, ostream, with no block and these arguments (positional, in
28
+ # order): a string "FAILED TEST:"; the test object converted to a string via
29
+ # to_s; a string "...ERROR:"; the error's class converted to a string via
30
+ # to_s; the error converted to a string via to_s; the error's backtrace or an
31
+ # empty array if the error signals that it has no backtrace; and an empty
32
+ # string. It ignores the object returned by the output stream and continues
33
+ # running tests. If a test raises a non-error exception, this method
34
+ # immediately raises that exception. If a test does not raise an exception,
35
+ # this method interprets it as a successful test; it ignores the object
36
+ # returned by the test and continues running tests. Whether the test fails
37
+ # or succeeds, the block sent with the each message returns nil. After it
38
+ # has run all the tests and handled any failures, this method returns false
39
+ # if there were failures, true otherwise. This method immediately raises any
40
+ # exception raised outside of a test.
57
41
  #
58
42
  # By default, ostream is $stdout.
59
43
 
60
44
  def self.run source, ostream = $stdout
61
- success = true
45
+ no_failures = true
62
46
  source.each do |tst|
63
- # Create the scratchpad outside the vet block so that this method will
47
+ # Create the scratchpad outside the begin block so that this method will
64
48
  # raise any exception that results instead of potentially treating it as
65
49
  # a test failure.
66
- scratchpad = Scratchpad.new
67
- if err_desc = vet { scratchpad.instance_exec(&tst) }
68
- success = false
69
- ostream.puts "FAILED TEST:", tst.to_s, "...ERROR:", err_desc.to_s, ""
50
+ scratchpad = ::Blackstart::Scratchpad.new
51
+ begin
52
+ scratchpad.instance_exec(&tst)
53
+ rescue ::StandardError => e
54
+ no_failures = false
55
+ ostream.puts "FAILED TEST:", tst.to_s, "...ERROR:", e.class.to_s,
56
+ e.to_s, e.backtrace || [], ""
70
57
  end
58
+ # Always return nil so that an each that's been modified to be sensitive
59
+ # to the block's return value can't behave differently based on the
60
+ # objects returned by the tests and the output stream.
61
+ nil
71
62
  end
72
- success
63
+ no_failures
73
64
  end
74
65
 
75
66
  end
@@ -0,0 +1,17 @@
1
+ module Blackstart
2
+ class Scratchpad
3
+ end
4
+
5
+ type test_proc = ^() [self: Scratchpad] -> void
6
+ interface _ConvertsToTestProc
7
+ def to_proc: () -> test_proc
8
+ end
9
+ type test = (test_proc | _ConvertsToTestProc) & ::_ToS
10
+
11
+ interface _OutputStream
12
+ def puts: (::String, ::String, ::String, ::String, ::String,
13
+ ::Array[::String], ::String) -> void
14
+ end
15
+
16
+ def self.run: (::_Each[test], ?_OutputStream) -> bool
17
+ end
@@ -1,104 +1,30 @@
1
1
  # Sections that create local variables are in class definitions so that later
2
2
  # sections cannot accidentally reference those local variables.
3
3
 
4
+ # Kernel#fail is an alias of Kernel#raise, so they do the same thing. However,
5
+ # they are used differently in this file: Kernel#fail is used only for
6
+ # assertions and Kernel#raise is used otherwise. Assertions always pass a
7
+ # string argument so that a new RuntimeError is raised. Kernel#fail with no
8
+ # arguments re-raises the current exception ($!) or, if there is none, raises a
9
+ # new RuntimeError. This would be fine (that is, it would raise a new
10
+ # RuntimeError) sometimes, but not always (not in a rescue clause, for
11
+ # example). Always using Kernel#fail with a string argument makes assertions
12
+ # consistent and avoids this subtle error.
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
+
4
20
  require "blackstart"
5
21
 
6
22
  # Blackstart should be a module.
7
23
  fail "" unless Module.equal? Blackstart.class
8
24
 
9
- # Blackstart should say it responds to vet and run.
10
- fail "" unless Blackstart.respond_to? :vet
25
+ # Blackstart should say it responds to run.
11
26
  fail "" unless Blackstart.respond_to? :run
12
27
 
13
- # Test Blackstart.vet:
14
-
15
- # Blackstart.vet should raise an exception if any non-block arguments are sent.
16
- begin
17
- Blackstart.vet nil
18
- rescue ArgumentError
19
- else
20
- fail ""
21
- end
22
- begin
23
- Blackstart.vet(nil) {}
24
- rescue ArgumentError
25
- else
26
- fail ""
27
- end
28
-
29
- # If yielding to the block raises an error, Blackstart.vet should return a
30
- # string describing that error.
31
- class ::Object
32
- # Should return an error description when no block is given.
33
- fail "" unless String.equal? Blackstart.vet.class
34
-
35
- # Use frozen strings and backtrace arrays so that an exception will be raised
36
- # if they're modified.
37
-
38
- e_class = Class.new StandardError
39
- def e_class.to_s
40
- "FakeError".freeze
41
- end
42
-
43
- e_nil = e_class.new "a".freeze
44
- def e_nil.backtrace
45
- nil
46
- end
47
- error = Blackstart.vet { ::Kernel.raise e_nil }
48
- fail "" unless String.equal? error.class
49
- fail "" unless "FakeError: a" == error
50
-
51
- e_empty = e_class.new "b".freeze
52
- def e_empty.backtrace
53
- [].freeze
54
- end
55
- error = Blackstart.vet { ::Kernel.raise e_empty }
56
- fail "" unless String.equal? error.class
57
- fail "" unless "FakeError: b" == error
58
-
59
- e_full = e_class.new "c".freeze
60
- def e_full.backtrace
61
- ["d".freeze, "e".freeze].freeze
62
- end
63
- error = Blackstart.vet { ::Kernel.raise e_full }
64
- fail "" unless String.equal? error.class
65
- fail "" unless "FakeError: c\nd\ne" == error
66
- end
67
-
68
- # If yielding to the block raises an error and that error raises an exception
69
- # when queried, Blackstart.vet should raise that second exception.
70
- class ::Object
71
- e1 = StandardError.new
72
- e2_class = Class.new StandardError
73
- e1.instance_variable_set :@next_exception_class, e2_class
74
- def e1.message
75
- ::Kernel.raise @next_exception_class
76
- end
77
- begin
78
- Blackstart.vet { ::Kernel.raise e1 }
79
- rescue e2_class
80
- else
81
- fail ""
82
- end
83
- end
84
-
85
- # If yielding to the block raises a non-StandardError exception, Blackstart.vet
86
- # should raise it.
87
- class ::Object
88
- non_standard_error = Class.new Exception
89
- begin
90
- Blackstart.vet { ::Kernel.raise non_standard_error }
91
- rescue non_standard_error
92
- else
93
- fail ""
94
- end
95
- end
96
-
97
- # If yielding to the block does not raise an exception, Blackstart.vet should
98
- # return nil. The object returned shouldn't matter.
99
- fail "" unless nil.equal? Blackstart.vet { nil }
100
- fail "" unless nil.equal? Blackstart.vet { true }
101
-
102
28
  # Test Blackstart::Scratchpad:
103
29
 
104
30
  # Blackstart::Scratchpad.new should return an instance of
@@ -106,6 +32,9 @@ fail "" unless nil.equal? Blackstart.vet { true }
106
32
  # class.
107
33
  fail "" unless Blackstart::Scratchpad.equal? Blackstart::Scratchpad.new.class
108
34
 
35
+ # Blackstart::Scratchpad should not be frozen.
36
+ fail "" if Blackstart::Scratchpad.frozen?
37
+
109
38
  # A new scratchpad should have no instance variables.
110
39
  fail "" unless 0 == Blackstart::Scratchpad.new.instance_variables.length
111
40
 
@@ -141,7 +70,7 @@ class ::Object
141
70
  # When there are tests but none raise exceptions, Blackstart.run should not
142
71
  # notify the output stream of any failures. The objects returned by the
143
72
  # test procs shouldn't affect Blackstart.run's behavior.
144
- source = [proc {}, proc { 42 }]
73
+ source = [lambda {}, lambda { 42 }]
145
74
  fail "" unless true.equal? Blackstart.run(source, invalid_ostream)
146
75
  fail "" unless true.equal? Blackstart.run(source, spy_stdout)
147
76
  fail "" unless true.equal? Blackstart.run(source)
@@ -158,17 +87,19 @@ class ::Object
158
87
  def e_class.to_s
159
88
  "FakeError".freeze
160
89
  end
161
- fail_prc1 = proc { ::Kernel.raise e_class, "fake message 1".freeze }
90
+ fail_prc1 = lambda { ::Kernel.raise e_class, "fake message 1".freeze }
162
91
  def fail_prc1.to_s
163
92
  "to_s 1".freeze
164
93
  end
165
94
  fail_prc1.freeze
166
- pass_prc = proc {}.freeze
95
+ pass_prc = lambda {}.freeze
167
96
  fail_prc2 = Object.new # Not a Proc instance, but converts to one.
168
97
  fail_prc2.instance_variable_set :@_test_e_class, e_class
169
98
  def fail_prc2.to_proc
170
99
  e_class = @_test_e_class
171
- ::Proc.new { ::Kernel.raise e_class, "fake message 2".freeze }.freeze
100
+ ::Kernel.lambda do
101
+ ::Kernel.raise e_class, "fake message 2".freeze
102
+ end.freeze
172
103
  end
173
104
  def fail_prc2.to_s
174
105
  "to_s 2".freeze
@@ -211,69 +142,67 @@ class ::Object
211
142
  fail "" unless false.equal? Blackstart.run(source, spy_ostream)
212
143
  fail "" unless 0 == stdout_calls.length
213
144
  fail "" unless 4 == calls.length
214
- fail "" unless 5 == calls[0].length
215
- fail "" unless calls[0].all? { |o| ::String.equal? o.class }
145
+ fail "" unless 7 == calls[0].length
216
146
  fail "" unless "FAILED TEST:" == calls[0][0]
217
147
  fail "" unless "to_s 1" == calls[0][1]
218
148
  fail "" unless "...ERROR:" == calls[0][2]
219
- fail "" unless "FakeError: fake message 1\nline1\nline2" == calls[0][3]
220
- fail "" unless "" == calls[0][4]
221
- fail "" unless 5 == calls[1].length
222
- fail "" unless calls[1].all? { |o| ::String.equal? o.class }
149
+ fail "" unless "FakeError" == calls[0][3]
150
+ fail "" unless "fake message 1" == calls[0][4]
151
+ fail "" unless ["line1", "line2"] == calls[0][5]
152
+ fail "" unless "" == calls[0][6]
153
+ fail "" unless 7 == calls[1].length
223
154
  fail "" unless "FAILED TEST:" == calls[1][0]
224
155
  fail "" unless "to_s 2" == calls[1][1]
225
156
  fail "" unless "...ERROR:" == calls[1][2]
226
- fail "" unless "FakeError: fake message 2\nline1\nline2" == calls[1][3]
227
- fail "" unless "" == calls[1][4]
228
- fail "" unless 5 == calls[2].length
229
- fail "" unless calls[2].all? { |o| ::String.equal? o.class }
157
+ fail "" unless "FakeError" == calls[1][3]
158
+ fail "" unless "fake message 2" == calls[1][4]
159
+ fail "" unless ["line1", "line2"] == calls[1][5]
160
+ fail "" unless "" == calls[1][6]
161
+ fail "" unless 7 == calls[2].length
230
162
  fail "" unless "FAILED TEST:" == calls[2][0]
231
163
  fail "" unless "to_s 3" == calls[2][1]
232
164
  fail "" unless "...ERROR:" == calls[2][2]
233
- # (No need to check the error description.)
234
- fail "" unless "" == calls[2][4]
235
- fail "" unless 5 == calls[3].length
236
- fail "" unless calls[3].all? { |o| ::String.equal? o.class }
165
+ # (No need to check the error details.)
166
+ fail "" unless "" == calls[2][6]
167
+ fail "" unless 7 == calls[3].length
237
168
  fail "" unless "FAILED TEST:" == calls[3][0]
238
169
  fail "" unless "to_s 4" == calls[3][1]
239
170
  fail "" unless "...ERROR:" == calls[3][2]
240
- # (No need to check the error description.)
241
- fail "" unless "" == calls[3][4]
171
+ # (No need to check the error details.)
172
+ fail "" unless "" == calls[3][6]
242
173
 
243
174
  # The faked standard output stream.
244
175
  stdout_calls.clear
245
176
  fail "" unless false.equal? Blackstart.run(source)
246
177
  fail "" unless 4 == stdout_calls.length
247
- fail "" unless 5 == stdout_calls[0].length
248
- fail "" unless stdout_calls[0].all? { |o| ::String.equal? o.class }
178
+ fail "" unless 7 == stdout_calls[0].length
249
179
  fail "" unless "FAILED TEST:" == stdout_calls[0][0]
250
180
  fail "" unless "to_s 1" == stdout_calls[0][1]
251
181
  fail "" unless "...ERROR:" == stdout_calls[0][2]
252
- fail "" unless "FakeError: fake message 1\nline1\nline2" ==
253
- stdout_calls[0][3]
254
- fail "" unless "" == stdout_calls[0][4]
255
- fail "" unless 5 == stdout_calls[1].length
256
- fail "" unless stdout_calls[1].all? { |o| ::String.equal? o.class }
182
+ fail "" unless "FakeError" == stdout_calls[0][3]
183
+ fail "" unless "fake message 1" == stdout_calls[0][4]
184
+ fail "" unless ["line1", "line2"] == stdout_calls[0][5]
185
+ fail "" unless "" == stdout_calls[0][6]
186
+ fail "" unless 7 == stdout_calls[1].length
257
187
  fail "" unless "FAILED TEST:" == stdout_calls[1][0]
258
188
  fail "" unless "to_s 2" == stdout_calls[1][1]
259
189
  fail "" unless "...ERROR:" == stdout_calls[1][2]
260
- fail "" unless "FakeError: fake message 2\nline1\nline2" ==
261
- stdout_calls[1][3]
262
- fail "" unless "" == stdout_calls[1][4]
263
- fail "" unless 5 == stdout_calls[2].length
264
- fail "" unless stdout_calls[2].all? { |o| ::String.equal? o.class }
190
+ fail "" unless "FakeError" == stdout_calls[1][3]
191
+ fail "" unless "fake message 2" == stdout_calls[1][4]
192
+ fail "" unless ["line1", "line2"] == stdout_calls[1][5]
193
+ fail "" unless "" == stdout_calls[1][6]
194
+ fail "" unless 7 == stdout_calls[2].length
265
195
  fail "" unless "FAILED TEST:" == stdout_calls[2][0]
266
196
  fail "" unless "to_s 3" == stdout_calls[2][1]
267
197
  fail "" unless "...ERROR:" == stdout_calls[2][2]
268
- # (No need to check the error description.)
269
- fail "" unless "" == stdout_calls[2][4]
270
- fail "" unless 5 == stdout_calls[3].length
271
- fail "" unless stdout_calls[3].all? { |o| ::String.equal? o.class }
198
+ # (No need to check the error details.)
199
+ fail "" unless "" == stdout_calls[2][6]
200
+ fail "" unless 7 == stdout_calls[3].length
272
201
  fail "" unless "FAILED TEST:" == stdout_calls[3][0]
273
202
  fail "" unless "to_s 4" == stdout_calls[3][1]
274
203
  fail "" unless "...ERROR:" == stdout_calls[3][2]
275
- # (No need to check the error description.)
276
- fail "" unless "" == stdout_calls[3][4]
204
+ # (No need to check the error details.)
205
+ fail "" unless "" == stdout_calls[3][6]
277
206
  stdout_calls.clear
278
207
 
279
208
  # An output stream that raises an exception when notified of a failure
@@ -281,7 +210,7 @@ class ::Object
281
210
  # tests. (In general, the only exceptions Blackstart.run should rescue are
282
211
  # StandardError exceptions raised by tests.)
283
212
  second_test_run = false
284
- source = [proc { ::Kernel.raise "" }, proc { second_test_run = true }]
213
+ source = [lambda { ::Kernel.raise "" }, lambda { second_test_run = true }]
285
214
  begin
286
215
  Blackstart.run source, invalid_ostream
287
216
  rescue NoMethodError
@@ -297,8 +226,8 @@ class ::Object
297
226
  # raised by tests.)
298
227
  second_test_run = false
299
228
  non_standard_error = Class.new Exception
300
- source = [proc { ::Kernel.raise non_standard_error },
301
- proc { second_test_run = true }]
229
+ source = [lambda { ::Kernel.raise non_standard_error },
230
+ lambda { second_test_run = true }]
302
231
  begin
303
232
  Blackstart.run source, spy_stdout
304
233
  rescue non_standard_error
@@ -329,11 +258,11 @@ class ::Object
329
258
  # tests. (In general, the only exceptions Blackstart.run should rescue are
330
259
  # StandardError exceptions raised by tests.)
331
260
  second_test_run = false
332
- no_desc = proc { ::Kernel.raise "" }
261
+ no_desc = lambda { ::Kernel.raise "" }
333
262
  def no_desc.to_s
334
263
  ::Kernel.raise ::NoMethodError
335
264
  end
336
- source = [no_desc, proc { second_test_run = true }]
265
+ source = [no_desc, lambda { second_test_run = true }]
337
266
  begin
338
267
  Blackstart.run source, spy_stdout
339
268
  rescue NoMethodError
@@ -347,10 +276,64 @@ class ::Object
347
276
  end
348
277
  end
349
278
 
279
+ # When a test fails with an error whose backtrace message returns nil,
280
+ # Blackstart.run should send an empty array to the output stream in place of
281
+ # the backtrace.
282
+ class ::Object
283
+ e_class = Class.new StandardError
284
+ def e_class.to_s
285
+ "FakeError".freeze
286
+ end
287
+ e_no_bt = e_class.new "no backtrace".freeze
288
+ def e_no_bt.backtrace
289
+ nil
290
+ end
291
+
292
+ ostream = Object.new
293
+ ostream.instance_variable_set :@_test_calls, calls = []
294
+ def ostream.puts *args
295
+ @_test_calls << args
296
+ nil
297
+ end
298
+
299
+ result = Blackstart.run [lambda { ::Kernel.raise e_no_bt }], ostream
300
+ fail "" unless false.equal? result
301
+ fail "" unless 1 == calls.length
302
+ fail "" unless 7 == calls[0].length
303
+ fail "" unless "FAILED TEST:" == calls[0][0]
304
+ fail "" unless "...ERROR:" == calls[0][2]
305
+ fail "" unless "FakeError" == calls[0][3]
306
+ fail "" unless "no backtrace" == calls[0][4]
307
+ fail "" unless [] == calls[0][5]
308
+ fail "" unless "" == calls[0][6]
309
+ end
310
+
311
+ # When a test fails with an error that raises an exception when queried,
312
+ # Blackstart.run should raise that exception and stop processing tests. (In
313
+ # general, the only exceptions Blackstart.run should rescue are StandardError
314
+ # exceptions raised by tests.)
315
+ class ::Object
316
+ second_test_run = false
317
+ e2_class = Class.new StandardError
318
+ e1 = StandardError.new
319
+ e1.instance_variable_set :@next_exception_class, e2_class
320
+ def e1.to_s
321
+ ::Kernel.raise @next_exception_class
322
+ end
323
+ source = [lambda { ::Kernel.raise e1 }, lambda { second_test_run = true }]
324
+ begin
325
+ Blackstart.run source, nil
326
+ rescue e2_class
327
+ else
328
+ fail ""
329
+ end
330
+ fail "" if second_test_run
331
+ end
332
+
350
333
  # Blackstart.run should run tests in order.
351
334
  class ::Object
352
335
  data = []
353
- Blackstart.run [proc { data << 1 }, proc { data << 2 }], nil
336
+ Blackstart.run [lambda { data << 1 }, lambda { data << 2 }], nil
354
337
  fail "" unless [1, 2] == data
355
338
  end
356
339
 
@@ -371,7 +354,7 @@ class ::Object
371
354
  source = Object.new
372
355
  def source.each
373
356
  ran = false
374
- yield proc { ran = true }
357
+ yield lambda { ran = true }
375
358
  @ran = ran
376
359
  self
377
360
  end
@@ -380,7 +363,7 @@ class ::Object
380
363
 
381
364
  source = Object.new
382
365
  def source.each
383
- yield proc {}
366
+ yield lambda {}
384
367
  nil
385
368
  end
386
369
  fail "" unless true.equal? Blackstart.run(source, nil)
@@ -398,11 +381,30 @@ class ::Object
398
381
  fail "" unless 1 == source.instance_variable_get(:@count)
399
382
  end
400
383
 
384
+ # The block that Blackstart.run sends with the each message should return nil
385
+ # whether the test fails or succeeds, regardless of the objects returned by the
386
+ # test and the output stream.
387
+ class ::Object
388
+ ostream = Object.new
389
+ def ostream.puts(*)
390
+ ::Object.new
391
+ end
392
+ source = Object.new
393
+ def source.each
394
+ pass_result = yield lambda { 42 }
395
+ fail_result = yield lambda { ::Kernel.raise "" }
396
+ @results = [pass_result, fail_result]
397
+ self
398
+ end
399
+ fail "" unless false.equal? Blackstart.run(source, ostream)
400
+ fail "" unless [nil, nil] == source.instance_variable_get(:@results)
401
+ end
402
+
401
403
  # When Blackstart.run calls a test proc, the self object should be a unique
402
404
  # instance of Blackstart::Scratchpad.
403
405
  class ::Object
404
406
  sp1 = sp2 = nil
405
- Blackstart.run [proc { sp1 = self }, proc { sp2 = self }], nil
407
+ Blackstart.run [lambda { sp1 = self }, lambda { sp2 = self }], nil
406
408
  fail "" unless Blackstart::Scratchpad.equal? sp1.class
407
409
  fail "" unless Blackstart::Scratchpad.equal? sp2.class
408
410
  fail "" if sp1.equal? sp2
@@ -411,7 +413,7 @@ end
411
413
  # When Blackstart.run runs a test, the scratchpad should not be frozen.
412
414
  class ::Object
413
415
  frozen = true
414
- Blackstart.run [proc { frozen = frozen? }], nil
416
+ Blackstart.run [lambda { frozen = frozen? }], nil
415
417
  fail "" if frozen
416
418
  end
417
419
 
@@ -433,7 +435,7 @@ class ::Object
433
435
  end
434
436
  end
435
437
 
436
- # The following section modifies the state of the library, so it must be run
438
+ # The following sections modify the state of the library, so they must be run
437
439
  # after all the ordinary tests.
438
440
 
439
441
  # Blackstart.run should run each test by sending instance_exec to a scratchpad.
@@ -449,9 +451,34 @@ class Blackstart::Scratchpad
449
451
  end
450
452
  class ::Object
451
453
  result = nil
452
- Blackstart.run [proc { result = [@ivar, foo()] }], nil
454
+ Blackstart.run [lambda { result = [@ivar, foo()] }], nil
453
455
  fail "" unless [1, 2] == result
454
456
  end
455
457
 
458
+ # When creating a scratchpad raises an exception, Blackstart.run should raise
459
+ # that exception and stop processing tests instead of treating it as a test
460
+ # failure, even when the exception is a StandardError. (In general, the only
461
+ # exceptions Blackstart.run should rescue are StandardError exceptions raised
462
+ # by tests; this one is raised outside of a test.) This section makes creating
463
+ # a scratchpad always raise an exception, so it must be the last section that
464
+ # runs tests.
465
+ class ::Object
466
+ second_test_run = false
467
+ e_class = Class.new StandardError
468
+ scratchpad_class = Blackstart::Scratchpad
469
+ scratchpad_class.instance_variable_set :@_test_e_class, e_class
470
+ def scratchpad_class.new(*)
471
+ ::Kernel.raise @_test_e_class
472
+ end
473
+ source = [lambda {}, lambda { second_test_run = true }]
474
+ begin
475
+ Blackstart.run source, nil
476
+ rescue e_class
477
+ else
478
+ fail ""
479
+ end
480
+ fail "" if second_test_run
481
+ end
482
+
456
483
  # If this message doesn't get written, there was a problem.
457
484
  puts "Test finished: #{__FILE__}"
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackstart
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
4
+ version: 0.9.0
11
5
  platform: ruby
12
6
  authors:
13
7
  - Aaron Beckerman
@@ -15,7 +9,7 @@ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
11
 
18
- date: 2024-12-21 00:00:00 -08:00
12
+ date: 2026-07-02 00:00:00 -07:00
19
13
  default_executable:
20
14
  dependencies: []
21
15
 
@@ -28,39 +22,29 @@ extensions: []
28
22
  extra_rdoc_files: []
29
23
 
30
24
  files:
31
- - LICENSE.txt
32
- - README.txt
33
- - blackstart.gemspec
25
+ - LICENSE
26
+ - README
34
27
  - lib/blackstart.rb
28
+ - sig/blackstart.rbs
35
29
  - test/blackstart_test.rb
36
30
  has_rdoc: true
37
31
  homepage:
38
32
  licenses:
39
- - MIT
33
+ - Apache-2.0
40
34
  post_install_message:
41
35
  rdoc_options: []
42
36
 
43
37
  require_paths:
44
38
  - lib
45
39
  required_ruby_version: !ruby/object:Gem::Requirement
46
- none: false
47
40
  requirements:
48
41
  - - ">="
49
42
  - !ruby/object:Gem::Version
50
- hash: 57
51
- segments:
52
- - 1
53
- - 8
54
- - 7
55
43
  version: 1.8.7
56
44
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
45
  requirements:
59
46
  - - ">="
60
47
  - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
48
  version: "0"
65
49
  requirements: []
66
50
 
@@ -68,6 +52,6 @@ rubyforge_project:
68
52
  rubygems_version: 1.6.2
69
53
  signing_key:
70
54
  specification_version: 3
71
- summary: A small, subdued library for automated testing.
72
- test_files:
73
- - test/blackstart_test.rb
55
+ summary: A small, subdued library for automated testing
56
+ test_files: []
57
+
data/LICENSE.txt DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2024 Aaron Beckerman
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
8
- so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- SOFTWARE.
data/blackstart.gemspec DELETED
@@ -1,11 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "blackstart"
3
- s.version = "0.5.0"
4
- s.authors = ["Aaron Beckerman"]
5
- s.summary = "A small, subdued library for automated testing."
6
- s.licenses = ["MIT"]
7
- s.required_ruby_version = ">= 1.8.7"
8
- s.files = ["LICENSE.txt", "README.txt", "blackstart.gemspec",
9
- "lib/blackstart.rb", "test/blackstart_test.rb"]
10
- s.test_files = ["test/blackstart_test.rb"]
11
- end