doctrine 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b983e2eeac94c8f16da2e757a17425fd17d313c4dda398ebc1e6a367b6957e4
4
+ data.tar.gz: 8488a7b47cbdb9a36cdcba77fdf9d416f149fc417128fa1cc5acb6e4f9158e6d
5
+ SHA512:
6
+ metadata.gz: 3558e0daca652192ed8e0238cdc0d75e9e71f8fd695ac10635574222d6d829e39ed8740450e3a96ae93577b581b17d5ca61cce347b795c944f30e1a92c2b0cfe
7
+ data.tar.gz: 3363f8b1e7adc5c435dbfedeee7350782a82f8e2f2d026ee5d7ac22850d483b2848512c4d443bbf62988c1d2e243ec3068836c570393e62699f70807496f0f33
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## v0.0.0
2
+
3
+ *unreleased*
4
+
5
+ * `add` [#1](https://github.com/metabahn/doctrine/pull/1) Initial implementation ([bryanp](https://github.com/bryanp))
6
+
7
+
data/LICENSE ADDED
@@ -0,0 +1,353 @@
1
+ Mozilla Public License, version 2.0
2
+
3
+ 1. Definitions
4
+
5
+ 1.1. “Contributor”
6
+
7
+ means each individual or legal entity that creates, contributes to the
8
+ creation of, or owns Covered Software.
9
+
10
+ 1.2. “Contributor Version”
11
+
12
+ means the combination of the Contributions of others (if any) used by a
13
+ Contributor and that particular Contributor’s Contribution.
14
+
15
+ 1.3. “Contribution”
16
+
17
+ means Covered Software of a particular Contributor.
18
+
19
+ 1.4. “Covered Software”
20
+
21
+ means Source Code Form to which the initial Contributor has attached the
22
+ notice in Exhibit A, the Executable Form of such Source Code Form, and
23
+ Modifications of such Source Code Form, in each case including portions
24
+ thereof.
25
+
26
+ 1.5. “Incompatible With Secondary Licenses”
27
+ means
28
+
29
+ a. that the initial Contributor has attached the notice described in
30
+ Exhibit B to the Covered Software; or
31
+
32
+ b. that the Covered Software was made available under the terms of version
33
+ 1.1 or earlier of the License, but not also under the terms of a
34
+ Secondary License.
35
+
36
+ 1.6. “Executable Form”
37
+
38
+ means any form of the work other than Source Code Form.
39
+
40
+ 1.7. “Larger Work”
41
+
42
+ means a work that combines Covered Software with other material, in a separate
43
+ file or files, that is not Covered Software.
44
+
45
+ 1.8. “License”
46
+
47
+ means this document.
48
+
49
+ 1.9. “Licensable”
50
+
51
+ means having the right to grant, to the maximum extent possible, whether at the
52
+ time of the initial grant or subsequently, any and all of the rights conveyed by
53
+ this License.
54
+
55
+ 1.10. “Modifications”
56
+
57
+ means any of the following:
58
+
59
+ a. any file in Source Code Form that results from an addition to, deletion
60
+ from, or modification of the contents of Covered Software; or
61
+
62
+ b. any new file in Source Code Form that contains any Covered Software.
63
+
64
+ 1.11. “Patent Claims” of a Contributor
65
+
66
+ means any patent claim(s), including without limitation, method, process,
67
+ and apparatus claims, in any patent Licensable by such Contributor that
68
+ would be infringed, but for the grant of the License, by the making,
69
+ using, selling, offering for sale, having made, import, or transfer of
70
+ either its Contributions or its Contributor Version.
71
+
72
+ 1.12. “Secondary License”
73
+
74
+ means either the GNU General Public License, Version 2.0, the GNU Lesser
75
+ General Public License, Version 2.1, the GNU Affero General Public
76
+ License, Version 3.0, or any later versions of those licenses.
77
+
78
+ 1.13. “Source Code Form”
79
+
80
+ means the form of the work preferred for making modifications.
81
+
82
+ 1.14. “You” (or “Your”)
83
+
84
+ means an individual or a legal entity exercising rights under this
85
+ License. For legal entities, “You” includes any entity that controls, is
86
+ controlled by, or is under common control with You. For purposes of this
87
+ definition, “control” means (a) the power, direct or indirect, to cause
88
+ the direction or management of such entity, whether by contract or
89
+ otherwise, or (b) ownership of more than fifty percent (50%) of the
90
+ outstanding shares or beneficial ownership of such entity.
91
+
92
+
93
+ 2. License Grants and Conditions
94
+
95
+ 2.1. Grants
96
+
97
+ Each Contributor hereby grants You a world-wide, royalty-free,
98
+ non-exclusive license:
99
+
100
+ a. under intellectual property rights (other than patent or trademark)
101
+ Licensable by such Contributor to use, reproduce, make available,
102
+ modify, display, perform, distribute, and otherwise exploit its
103
+ Contributions, either on an unmodified basis, with Modifications, or as
104
+ part of a Larger Work; and
105
+
106
+ b. under Patent Claims of such Contributor to make, use, sell, offer for
107
+ sale, have made, import, and otherwise transfer either its Contributions
108
+ or its Contributor Version.
109
+
110
+ 2.2. Effective Date
111
+
112
+ The licenses granted in Section 2.1 with respect to any Contribution become
113
+ effective for each Contribution on the date the Contributor first distributes
114
+ such Contribution.
115
+
116
+ 2.3. Limitations on Grant Scope
117
+
118
+ The licenses granted in this Section 2 are the only rights granted under this
119
+ License. No additional rights or licenses will be implied from the distribution
120
+ or licensing of Covered Software under this License. Notwithstanding Section
121
+ 2.1(b) above, no patent license is granted by a Contributor:
122
+
123
+ a. for any code that a Contributor has removed from Covered Software; or
124
+
125
+ b. for infringements caused by: (i) Your and any other third party’s
126
+ modifications of Covered Software, or (ii) the combination of its
127
+ Contributions with other software (except as part of its Contributor
128
+ Version); or
129
+
130
+ c. under Patent Claims infringed by Covered Software in the absence of its
131
+ Contributions.
132
+
133
+ This License does not grant any rights in the trademarks, service marks, or
134
+ logos of any Contributor (except as may be necessary to comply with the
135
+ notice requirements in Section 3.4).
136
+
137
+ 2.4. Subsequent Licenses
138
+
139
+ No Contributor makes additional grants as a result of Your choice to
140
+ distribute the Covered Software under a subsequent version of this License
141
+ (see Section 10.2) or under the terms of a Secondary License (if permitted
142
+ under the terms of Section 3.3).
143
+
144
+ 2.5. Representation
145
+
146
+ Each Contributor represents that the Contributor believes its Contributions
147
+ are its original creation(s) or it has sufficient rights to grant the
148
+ rights to its Contributions conveyed by this License.
149
+
150
+ 2.6. Fair Use
151
+
152
+ This License is not intended to limit any rights You have under applicable
153
+ copyright doctrines of fair use, fair dealing, or other equivalents.
154
+
155
+ 2.7. Conditions
156
+
157
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
158
+ Section 2.1.
159
+
160
+
161
+ 3. Responsibilities
162
+
163
+ 3.1. Distribution of Source Form
164
+
165
+ All distribution of Covered Software in Source Code Form, including any
166
+ Modifications that You create or to which You contribute, must be under the
167
+ terms of this License. You must inform recipients that the Source Code Form
168
+ of the Covered Software is governed by the terms of this License, and how
169
+ they can obtain a copy of this License. You may not attempt to alter or
170
+ restrict the recipients’ rights in the Source Code Form.
171
+
172
+ 3.2. Distribution of Executable Form
173
+
174
+ If You distribute Covered Software in Executable Form then:
175
+
176
+ a. such Covered Software must also be made available in Source Code Form,
177
+ as described in Section 3.1, and You must inform recipients of the
178
+ Executable Form how they can obtain a copy of such Source Code Form by
179
+ reasonable means in a timely manner, at a charge no more than the cost
180
+ of distribution to the recipient; and
181
+
182
+ b. You may distribute such Executable Form under the terms of this License,
183
+ or sublicense it under different terms, provided that the license for
184
+ the Executable Form does not attempt to limit or alter the recipients’
185
+ rights in the Source Code Form under this License.
186
+
187
+ 3.3. Distribution of a Larger Work
188
+
189
+ You may create and distribute a Larger Work under terms of Your choice,
190
+ provided that You also comply with the requirements of this License for the
191
+ Covered Software. If the Larger Work is a combination of Covered Software
192
+ with a work governed by one or more Secondary Licenses, and the Covered
193
+ Software is not Incompatible With Secondary Licenses, this License permits
194
+ You to additionally distribute such Covered Software under the terms of
195
+ such Secondary License(s), so that the recipient of the Larger Work may, at
196
+ their option, further distribute the Covered Software under the terms of
197
+ either this License or such Secondary License(s).
198
+
199
+ 3.4. Notices
200
+
201
+ You may not remove or alter the substance of any license notices (including
202
+ copyright notices, patent notices, disclaimers of warranty, or limitations
203
+ of liability) contained within the Source Code Form of the Covered
204
+ Software, except that You may alter any license notices to the extent
205
+ required to remedy known factual inaccuracies.
206
+
207
+ 3.5. Application of Additional Terms
208
+
209
+ You may choose to offer, and to charge a fee for, warranty, support,
210
+ indemnity or liability obligations to one or more recipients of Covered
211
+ Software. However, You may do so only on Your own behalf, and not on behalf
212
+ of any Contributor. You must make it absolutely clear that any such
213
+ warranty, support, indemnity, or liability obligation is offered by You
214
+ alone, and You hereby agree to indemnify every Contributor for any
215
+ liability incurred by such Contributor as a result of warranty, support,
216
+ indemnity or liability terms You offer. You may include additional
217
+ disclaimers of warranty and limitations of liability specific to any
218
+ jurisdiction.
219
+
220
+ 4. Inability to Comply Due to Statute or Regulation
221
+
222
+ If it is impossible for You to comply with any of the terms of this License
223
+ with respect to some or all of the Covered Software due to statute, judicial
224
+ order, or regulation then You must: (a) comply with the terms of this License
225
+ to the maximum extent possible; and (b) describe the limitations and the code
226
+ they affect. Such description must be placed in a text file included with all
227
+ distributions of the Covered Software under this License. Except to the
228
+ extent prohibited by statute or regulation, such description must be
229
+ sufficiently detailed for a recipient of ordinary skill to be able to
230
+ understand it.
231
+
232
+ 5. Termination
233
+
234
+ 5.1. The rights granted under this License will terminate automatically if You
235
+ fail to comply with any of its terms. However, if You become compliant,
236
+ then the rights granted under this License from a particular Contributor
237
+ are reinstated (a) provisionally, unless and until such Contributor
238
+ explicitly and finally terminates Your grants, and (b) on an ongoing basis,
239
+ if such Contributor fails to notify You of the non-compliance by some
240
+ reasonable means prior to 60 days after You have come back into compliance.
241
+ Moreover, Your grants from a particular Contributor are reinstated on an
242
+ ongoing basis if such Contributor notifies You of the non-compliance by
243
+ some reasonable means, this is the first time You have received notice of
244
+ non-compliance with this License from such Contributor, and You become
245
+ compliant prior to 30 days after Your receipt of the notice.
246
+
247
+ 5.2. If You initiate litigation against any entity by asserting a patent
248
+ infringement claim (excluding declaratory judgment actions, counter-claims,
249
+ and cross-claims) alleging that a Contributor Version directly or
250
+ indirectly infringes any patent, then the rights granted to You by any and
251
+ all Contributors for the Covered Software under Section 2.1 of this License
252
+ shall terminate.
253
+
254
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
255
+ license agreements (excluding distributors and resellers) which have been
256
+ validly granted by You or Your distributors under this License prior to
257
+ termination shall survive termination.
258
+
259
+ 6. Disclaimer of Warranty
260
+
261
+ Covered Software is provided under this License on an “as is” basis, without
262
+ warranty of any kind, either expressed, implied, or statutory, including,
263
+ without limitation, warranties that the Covered Software is free of defects,
264
+ merchantable, fit for a particular purpose or non-infringing. The entire
265
+ risk as to the quality and performance of the Covered Software is with You.
266
+ Should any Covered Software prove defective in any respect, You (not any
267
+ Contributor) assume the cost of any necessary servicing, repair, or
268
+ correction. This disclaimer of warranty constitutes an essential part of this
269
+ License. No use of any Covered Software is authorized under this License
270
+ except under this disclaimer.
271
+
272
+ 7. Limitation of Liability
273
+
274
+ Under no circumstances and under no legal theory, whether tort (including
275
+ negligence), contract, or otherwise, shall any Contributor, or anyone who
276
+ distributes Covered Software as permitted above, be liable to You for any
277
+ direct, indirect, special, incidental, or consequential damages of any
278
+ character including, without limitation, damages for lost profits, loss of
279
+ goodwill, work stoppage, computer failure or malfunction, or any and all
280
+ other commercial damages or losses, even if such party shall have been
281
+ informed of the possibility of such damages. This limitation of liability
282
+ shall not apply to liability for death or personal injury resulting from such
283
+ party’s negligence to the extent applicable law prohibits such limitation.
284
+ Some jurisdictions do not allow the exclusion or limitation of incidental or
285
+ consequential damages, so this exclusion and limitation may not apply to You.
286
+
287
+ 8. Litigation
288
+
289
+ Any litigation relating to this License may be brought only in the courts of
290
+ a jurisdiction where the defendant maintains its principal place of business
291
+ and such litigation shall be governed by laws of that jurisdiction, without
292
+ reference to its conflict-of-law provisions. Nothing in this Section shall
293
+ prevent a party’s ability to bring cross-claims or counter-claims.
294
+
295
+ 9. Miscellaneous
296
+
297
+ This License represents the complete agreement concerning the subject matter
298
+ hereof. If any provision of this License is held to be unenforceable, such
299
+ provision shall be reformed only to the extent necessary to make it
300
+ enforceable. Any law or regulation which provides that the language of a
301
+ contract shall be construed against the drafter shall not be used to construe
302
+ this License against a Contributor.
303
+
304
+
305
+ 10. Versions of the License
306
+
307
+ 10.1. New Versions
308
+
309
+ Mozilla Foundation is the license steward. Except as provided in Section
310
+ 10.3, no one other than the license steward has the right to modify or
311
+ publish new versions of this License. Each version will be given a
312
+ distinguishing version number.
313
+
314
+ 10.2. Effect of New Versions
315
+
316
+ You may distribute the Covered Software under the terms of the version of
317
+ the License under which You originally received the Covered Software, or
318
+ under the terms of any subsequent version published by the license
319
+ steward.
320
+
321
+ 10.3. Modified Versions
322
+
323
+ If you create software not governed by this License, and you want to
324
+ create a new license for such software, you may create and use a modified
325
+ version of this License if you rename the license and remove any
326
+ references to the name of the license steward (except to note that such
327
+ modified license differs from this License).
328
+
329
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
330
+ If You choose to distribute Source Code Form that is Incompatible With
331
+ Secondary Licenses under the terms of this version of the License, the
332
+ notice described in Exhibit B of this License must be attached.
333
+
334
+ Exhibit A - Source Code Form License Notice
335
+
336
+ This Source Code Form is subject to the
337
+ terms of the Mozilla Public License, v.
338
+ 2.0. If a copy of the MPL was not
339
+ distributed with this file, You can
340
+ obtain one at
341
+ http://mozilla.org/MPL/2.0/.
342
+
343
+ If it is not possible or desirable to put the notice in a particular file, then
344
+ You may include the notice in a location (such as a LICENSE file in a relevant
345
+ directory) where a recipient would be likely to look for such a notice.
346
+
347
+ You may add additional accurate notices of copyright ownership.
348
+
349
+ Exhibit B - “Incompatible With Secondary Licenses” Notice
350
+
351
+ This Source Code Form is “Incompatible
352
+ With Secondary Licenses”, as defined by
353
+ the Mozilla Public License, v. 2.0.
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "core/loader/context"
4
+
5
+ module Doctrine
6
+ # [public]
7
+ #
8
+ class Context
9
+ def initialize(suite:)
10
+ @suite = suite
11
+ end
12
+
13
+ # [public]
14
+ #
15
+ def doctrine(...)
16
+ @context.doctrine(...).tap { |doctrine|
17
+ @suite.doctrines << doctrine
18
+ }
19
+ end
20
+
21
+ # [public]
22
+ #
23
+ def load(...)
24
+ self.class.new(suite: @suite).internal_load(...)
25
+ end
26
+
27
+ def internal_load(path:, root:, type:, target:, strict:)
28
+ @context = Core::Loader::Context.new(path: path, root: root, type: type, target: target, strict: strict)
29
+
30
+ eval(path.read, binding, path.to_s)
31
+ end
32
+
33
+ # def method_missing(method, *name, **kwargs, &block)
34
+ # if method == :tenet
35
+ # @context.__send__(method, *name, block: block, **kwargs).tap { |tenet|
36
+ # @suite.tenets << tenet
37
+ # }
38
+ # else
39
+ # @context.__send__(method, *name, **kwargs, &block)
40
+ # end
41
+ # end
42
+
43
+ # def respond_to_missing?(name, include_private = false)
44
+ # @context.respond_to_missing?(name, include_private) || ::Kernel.respond_to?(name, include_private)
45
+ # end
46
+
47
+ # def self.const_missing(name)
48
+ # ::Object.const_get(name)
49
+ # end
50
+ end
51
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "is/stateful"
4
+
5
+ require_relative "tenet"
6
+
7
+ module Doctrine
8
+ class Definition
9
+ class << self
10
+ def subject(value = value_omitted = true, &block)
11
+ if block
12
+ @subject = block
13
+ @subject_type = :block
14
+ elsif !value_omitted
15
+ @subject = value
16
+ @subject_type = :value
17
+ end
18
+ end
19
+
20
+ def tenet(description, &block)
21
+ tenets << Tenet.new(description: description, &block)
22
+ end
23
+ end
24
+
25
+ include Is::Stateful
26
+ state :tenets, :class, default: []
27
+
28
+ # [public]
29
+ #
30
+ def subject(value = value_omitted = true, &block)
31
+ if block
32
+ @subject = block
33
+ @subject_type = :block
34
+ elsif !value_omitted
35
+ @subject = value
36
+ @subject_type = :value
37
+ end
38
+ end
39
+
40
+ # [public]
41
+ #
42
+ def assert
43
+ subject, subject_type = find_subject_and_subject_type
44
+
45
+ if subject_type
46
+ unless yield(resolve(subject, subject_type))
47
+ raise AssertionFailed
48
+ end
49
+ else
50
+ raise UndefinedSubject
51
+ end
52
+ end
53
+
54
+ # [public]
55
+ #
56
+ def capture
57
+ yield
58
+ rescue => error
59
+ @subject_type = :error
60
+ @subject = error
61
+ end
62
+
63
+ private def find_subject_and_subject_type
64
+ if @subject_type
65
+ [@subject, @subject_type]
66
+ elsif (subject_type = self.class.instance_variable_get(:@subject_type))
67
+ [self.class.instance_variable_get(:@subject), subject_type]
68
+ end
69
+ end
70
+
71
+ private def resolve(subject, subject_type)
72
+ case subject_type
73
+ when :block
74
+ subject.call
75
+ when :error, :value
76
+ subject
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doctrine
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../error"
4
+
5
+ module Doctrine
6
+ class AssertionFailed < Error
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../error"
4
+
5
+ module Doctrine
6
+ class UndefinedSubject < Error
7
+ end
8
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pastel"
4
+
5
+ module Doctrine
6
+ # [public]
7
+ #
8
+ class Reporter
9
+ def initialize(output: $stdout, tty: $stdout.tty?)
10
+ @output = output
11
+ @tty = tty
12
+ @started = current_time
13
+ @pastel = Pastel.new
14
+ end
15
+
16
+ def starting(tenet)
17
+ end
18
+
19
+ def finished(tenet)
20
+ end
21
+
22
+ def summarize(tenets)
23
+ elapsed_ms = ((current_time - @started) * 1_000)
24
+
25
+ if elapsed_ms > 1_000
26
+ elapsed = elapsed_ms / 1_000
27
+ elapsed_units = "s"
28
+ else
29
+ elapsed = elapsed_ms
30
+ elapsed_units = "ms"
31
+ end
32
+
33
+ tenet_text = if tenets.count == 1
34
+ "tenet"
35
+ else
36
+ "tenets"
37
+ end
38
+
39
+ failures = []
40
+ tenets.each do |tenet|
41
+ if tenet.errored?
42
+ failures << tenet
43
+ @output << decorate("x", color: :red)
44
+ else
45
+ @output << decorate(".", color: :green)
46
+ end
47
+ end
48
+
49
+ summary_text = "Tested #{tenets.count} #{tenet_text} in #{elapsed.round(2)}#{elapsed_units}"
50
+
51
+ if failures.any?
52
+ failure_text = if failures.count == 1
53
+ "failure"
54
+ else
55
+ "failures"
56
+ end
57
+
58
+ failures.each do |failure|
59
+ @output << "\n"
60
+ @output << "\n"
61
+ @output << decorate(failure.error.to_s, color: :red)
62
+ failure.error.backtrace.each do |line|
63
+ @output << "\n"
64
+ @output << decorate(line, color: :red)
65
+ end
66
+ end
67
+
68
+ @output << "\n"
69
+ @output << "\n"
70
+ @output << summary_text
71
+ @output << decorate(" (#{failures.count} #{failure_text})", color: :red)
72
+ else
73
+ @output << "\n"
74
+ @output << "\n"
75
+ @output << summary_text
76
+ @output << decorate(" (good to go)", color: :green)
77
+ end
78
+
79
+ @output << "\n"
80
+ end
81
+
82
+ private def decorate(text, color:)
83
+ if @tty
84
+ @pastel.public_send(color, text)
85
+ else
86
+ text
87
+ end
88
+ end
89
+
90
+ private def current_time
91
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doctrine
4
+ # [public]
5
+ #
6
+ class Run
7
+ def initialize(doctrine:, tenet:)
8
+ @doctrine = doctrine
9
+ @tenet = tenet
10
+ @error = nil
11
+ end
12
+
13
+ # [public]
14
+ #
15
+ attr_reader :error
16
+
17
+ # [public]
18
+ #
19
+ def perform
20
+ @doctrine.new.instance_eval(&@tenet.block)
21
+ rescue => error
22
+ errored(error)
23
+ end
24
+
25
+ # [public]
26
+ #
27
+ def errored?
28
+ !@error.nil?
29
+ end
30
+
31
+ # [public]
32
+ #
33
+ def errored(error)
34
+ @error = error
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "worker"
4
+
5
+ module Doctrine
6
+ # [public]
7
+ #
8
+ class Runner
9
+ include MonitorMixin
10
+
11
+ def initialize(reporter:)
12
+ @reporter = reporter
13
+ @condition = new_cond
14
+ @queue = Queue.new
15
+ @worker = Worker.new(queue: @queue, runner: self)
16
+ @thread = Thread.new { @worker.run }
17
+ @enqueued = []
18
+ @working = []
19
+ @finished = []
20
+ end
21
+
22
+ # [public]
23
+ #
24
+ def run(tenet)
25
+ @enqueued << tenet
26
+ @queue << tenet
27
+ end
28
+
29
+ # [public]
30
+ #
31
+ def starting(tenet)
32
+ @reporter.starting(tenet)
33
+ @enqueued.delete(tenet)
34
+ @working << tenet
35
+ end
36
+
37
+ # [public]
38
+ #
39
+ def finished(tenet)
40
+ @reporter.finished(tenet)
41
+ @working.delete(tenet)
42
+ @finished << tenet
43
+
44
+ synchronize do
45
+ @condition.signal
46
+ end
47
+ end
48
+
49
+ # [public]
50
+ #
51
+ def wait
52
+ synchronize do
53
+ @condition.wait_until do
54
+ @enqueued.empty? && @working.empty?
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "is/definable"
4
+ require "is/factory"
5
+ require "is/loadable"
6
+ require "is/stateful"
7
+
8
+ require_relative "reporter"
9
+ require_relative "runner"
10
+ require_relative "run"
11
+
12
+ module Doctrine
13
+ # [public]
14
+ #
15
+ class Suite
16
+ include Is::Definable
17
+ include Is::Factory
18
+ include Is::Loadable
19
+ include Is::Stateful
20
+
21
+ state :doctrines, default: []
22
+
23
+ # [public]
24
+ #
25
+ def self.run
26
+ reporter = Reporter.new
27
+ runner = Runner.new(reporter: reporter)
28
+
29
+ runs = []
30
+ @doctrines.each do |doctrine|
31
+ doctrine.tenets.each do |tenet|
32
+ run = Run.new(doctrine: doctrine, tenet: tenet)
33
+ runner.run(run)
34
+ runs << run
35
+ end
36
+ end
37
+
38
+ runner.wait
39
+
40
+ reporter.summarize(runs)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "errors/assertion_failed"
4
+ require_relative "errors/undefined_subject"
5
+
6
+ module Doctrine
7
+ # [public]
8
+ #
9
+ class Tenet
10
+ def initialize(description:, &block)
11
+ @description = description
12
+ @block = block
13
+ @error = nil
14
+ end
15
+
16
+ attr_reader :block
17
+
18
+ # attr_reader :error
19
+
20
+ # def errored?
21
+ # !@error.nil?
22
+ # end
23
+
24
+ # [public]
25
+ #
26
+ # def run
27
+ # instance_eval(&@block)
28
+ # rescue => error
29
+ # errored(error)
30
+ # end
31
+
32
+ # # [public]
33
+ # #
34
+ # def errored(error)
35
+ # @error = error
36
+ # end
37
+
38
+ # # [public]
39
+ # #
40
+ # def subject
41
+ # @subject = yield
42
+ # end
43
+
44
+ # # [public]
45
+ # #
46
+ # def assert
47
+ # if defined?(@subject)
48
+ # unless yield(@subject)
49
+ # raise AssertionFailed
50
+ # end
51
+ # else
52
+ # raise UndefinedSubject
53
+ # end
54
+ # end
55
+
56
+ # # [public]
57
+ # #
58
+ # def capture
59
+ # yield
60
+ # rescue => error
61
+ # @subject = error
62
+ # end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doctrine
4
+ VERSION = "0.0.0"
5
+
6
+ # [public]
7
+ #
8
+ def self.version
9
+ VERSION
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doctrine
4
+ # [public]
5
+ #
6
+ class Worker
7
+ def initialize(queue:, runner:)
8
+ @queue = queue
9
+ @runner = runner
10
+ end
11
+
12
+ # [public]
13
+ #
14
+ def run
15
+ until @queue.closed?
16
+ if (run = @queue.pop)
17
+ begin
18
+ @runner.starting(run)
19
+
20
+ run.perform
21
+ rescue => error
22
+ run.errored(error)
23
+ ensure
24
+ @runner.finished(run)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/doctrine.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module Doctrine
6
+ require_relative "doctrine/context"
7
+ require_relative "doctrine/definition"
8
+ require_relative "doctrine/suite"
9
+ require_relative "doctrine/version"
10
+
11
+ def self.load(path, pattern: "*_doctrine.rb")
12
+ path = Pathname(path).expand_path
13
+ name = path.to_s.split("/").last(2)
14
+ suite = Suite.define(*name)
15
+ context = Context.new(suite: suite)
16
+
17
+ suite.makes(:doctrine, Definition, within: name)
18
+ suite.loads(:doctrine, path, strict: false, pattern: pattern, context: context)
19
+ suite.load
20
+ suite
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doctrine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Powell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: core-define
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: core-factory
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: core-global
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: core-loader
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: core-state
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pastel
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ description: Ruby programs as doctrine.
98
+ email: bryan@metabahn.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - CHANGELOG.md
104
+ - LICENSE
105
+ - lib/doctrine.rb
106
+ - lib/doctrine/context.rb
107
+ - lib/doctrine/definition.rb
108
+ - lib/doctrine/error.rb
109
+ - lib/doctrine/errors/assertion_failed.rb
110
+ - lib/doctrine/errors/undefined_subject.rb
111
+ - lib/doctrine/reporter.rb
112
+ - lib/doctrine/run.rb
113
+ - lib/doctrine/runner.rb
114
+ - lib/doctrine/suite.rb
115
+ - lib/doctrine/tenet.rb
116
+ - lib/doctrine/version.rb
117
+ - lib/doctrine/worker.rb
118
+ homepage: https://github.com/metabahn/doctrine/
119
+ licenses:
120
+ - MPL-2.0
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.6.7
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.2.22
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Ruby programs as doctrine.
141
+ test_files: []