test_bench-isolated 0 → 2.0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/test_bench_isolated/test_bench/cli.rb +298 -0
- data/lib/test_bench_isolated/test_bench/controls/file.rb +7 -0
- data/lib/test_bench_isolated/test_bench/controls/path.rb +7 -0
- data/lib/test_bench_isolated/test_bench/controls/random.rb +9 -0
- data/lib/test_bench_isolated/test_bench/controls/result.rb +7 -0
- data/lib/test_bench_isolated/test_bench/controls/stdin.rb +29 -0
- data/lib/test_bench_isolated/test_bench/controls.rb +11 -0
- data/lib/test_bench_isolated/test_bench/fixture/actuate/class.rb +97 -0
- data/lib/test_bench_isolated/test_bench/fixture/actuate/object.rb +93 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/exception.rb +9 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/fixture/class.rb +88 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/fixture/object/modules.rb +41 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/fixture/object.rb +33 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/fixture.rb +29 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/output.rb +9 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/random.rb +9 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/result.rb +9 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls/title.rb +9 -0
- data/lib/test_bench_isolated/test_bench/fixture/controls.rb +13 -0
- data/lib/test_bench_isolated/test_bench/fixture/evaluate.rb +31 -0
- data/lib/test_bench_isolated/test_bench/fixture/fixture.rb +201 -0
- data/lib/test_bench_isolated/test_bench/fixture.rb +8 -0
- data/lib/test_bench_isolated/test_bench/output/controls/data.rb +51 -0
- data/lib/test_bench_isolated/test_bench/output/controls/device.rb +29 -0
- data/lib/test_bench_isolated/test_bench/output/controls/event.rb +9 -0
- data/lib/test_bench_isolated/test_bench/output/controls/output.rb +36 -0
- data/lib/test_bench_isolated/test_bench/output/controls/random.rb +9 -0
- data/lib/test_bench_isolated/test_bench/output/controls/style.rb +33 -0
- data/lib/test_bench_isolated/test_bench/output/controls/styling.rb +29 -0
- data/lib/test_bench_isolated/test_bench/output/controls/text.rb +19 -0
- data/lib/test_bench_isolated/test_bench/output/controls.rb +10 -0
- data/lib/test_bench_isolated/test_bench/output/device/null.rb +21 -0
- data/lib/test_bench_isolated/test_bench/output/device/substitute.rb +60 -0
- data/lib/test_bench_isolated/test_bench/output/digest.rb +115 -0
- data/lib/test_bench_isolated/test_bench/output/output.rb +68 -0
- data/lib/test_bench_isolated/test_bench/output/writer/buffer.rb +59 -0
- data/lib/test_bench_isolated/test_bench/output/writer/defaults.rb +13 -0
- data/lib/test_bench_isolated/test_bench/output/writer/style.rb +52 -0
- data/lib/test_bench_isolated/test_bench/output/writer/substitute.rb +40 -0
- data/lib/test_bench_isolated/test_bench/output/writer.rb +212 -0
- data/lib/test_bench_isolated/test_bench/output.rb +14 -0
- data/lib/test_bench_isolated/test_bench/random/controls/seed.rb +27 -0
- data/lib/test_bench_isolated/test_bench/random/controls.rb +1 -0
- data/lib/test_bench_isolated/test_bench/random/random.rb +170 -0
- data/lib/test_bench_isolated/test_bench/random.rb +1 -0
- data/lib/test_bench_isolated/test_bench/run/controls/directory.rb +72 -0
- data/lib/test_bench_isolated/test_bench/run/controls/event_data.rb +9 -0
- data/lib/test_bench_isolated/test_bench/run/controls/events/event_data.rb +11 -0
- data/lib/test_bench_isolated/test_bench/run/controls/events/file_crashed.rb +111 -0
- data/lib/test_bench_isolated/test_bench/run/controls/events/file_finished.rb +58 -0
- data/lib/test_bench_isolated/test_bench/run/controls/events/file_started.rb +49 -0
- data/lib/test_bench_isolated/test_bench/run/controls/events/finished.rb +58 -0
- data/lib/test_bench_isolated/test_bench/run/controls/events/session.rb +11 -0
- data/lib/test_bench_isolated/test_bench/run/controls/events/started.rb +49 -0
- data/lib/test_bench_isolated/test_bench/run/controls/exception.rb +103 -0
- data/lib/test_bench_isolated/test_bench/run/controls/executor.rb +58 -0
- data/lib/test_bench_isolated/test_bench/run/controls/file/create.rb +71 -0
- data/lib/test_bench_isolated/test_bench/run/controls/file/pattern.rb +35 -0
- data/lib/test_bench_isolated/test_bench/run/controls/file.rb +182 -0
- data/lib/test_bench_isolated/test_bench/run/controls/path.rb +17 -0
- data/lib/test_bench_isolated/test_bench/run/controls/process_id.rb +9 -0
- data/lib/test_bench_isolated/test_bench/run/controls/random.rb +9 -0
- data/lib/test_bench_isolated/test_bench/run/controls/result.rb +9 -0
- data/lib/test_bench_isolated/test_bench/run/controls/time.rb +9 -0
- data/lib/test_bench_isolated/test_bench/run/controls.rb +26 -0
- data/lib/test_bench_isolated/test_bench/run/events.rb +14 -0
- data/lib/test_bench_isolated/test_bench/run/executor/serial.rb +36 -0
- data/lib/test_bench_isolated/test_bench/run/executor/substitute.rb +47 -0
- data/lib/test_bench_isolated/test_bench/run/executor.rb +46 -0
- data/lib/test_bench_isolated/test_bench/run/file.rb +83 -0
- data/lib/test_bench_isolated/test_bench/run/get_files/substitute.rb +48 -0
- data/lib/test_bench_isolated/test_bench/run/get_files.rb +78 -0
- data/lib/test_bench_isolated/test_bench/run/output/file.rb +137 -0
- data/lib/test_bench_isolated/test_bench/run/output/summary/error.rb +141 -0
- data/lib/test_bench_isolated/test_bench/run/output/summary.rb +184 -0
- data/lib/test_bench_isolated/test_bench/run/run.rb +156 -0
- data/lib/test_bench_isolated/test_bench/run.rb +18 -0
- data/lib/test_bench_isolated/test_bench/session/controls/comment.rb +107 -0
- data/lib/test_bench_isolated/test_bench/session/controls/detail.rb +93 -0
- data/lib/test_bench_isolated/test_bench/session/controls/event.rb +9 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/commented.rb +112 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/context_finished.rb +72 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/context_skipped.rb +49 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/context_started.rb +66 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/detailed.rb +112 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/event_data.rb +11 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/failed.rb +49 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/fixture_finished.rb +55 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/fixture_started.rb +49 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/test_finished.rb +72 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/test_skipped.rb +49 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events/test_started.rb +66 -0
- data/lib/test_bench_isolated/test_bench/session/controls/events.rb +35 -0
- data/lib/test_bench_isolated/test_bench/session/controls/exception.rb +47 -0
- data/lib/test_bench_isolated/test_bench/session/controls/failure.rb +21 -0
- data/lib/test_bench_isolated/test_bench/session/controls/fixture.rb +21 -0
- data/lib/test_bench_isolated/test_bench/session/controls/output/detail.rb +31 -0
- data/lib/test_bench_isolated/test_bench/session/controls/output.rb +57 -0
- data/lib/test_bench_isolated/test_bench/session/controls/process_id.rb +9 -0
- data/lib/test_bench_isolated/test_bench/session/controls/random.rb +9 -0
- data/lib/test_bench_isolated/test_bench/session/controls/result.rb +25 -0
- data/lib/test_bench_isolated/test_bench/session/controls/substitute/path.rb +35 -0
- data/lib/test_bench_isolated/test_bench/session/controls/time.rb +9 -0
- data/lib/test_bench_isolated/test_bench/session/controls/title.rb +41 -0
- data/lib/test_bench_isolated/test_bench/session/controls.rb +36 -0
- data/lib/test_bench_isolated/test_bench/session/events.rb +27 -0
- data/lib/test_bench_isolated/test_bench/session/output/get.rb +29 -0
- data/lib/test_bench_isolated/test_bench/session/output/writer/buffer/interactive/viewport.rb +167 -0
- data/lib/test_bench_isolated/test_bench/session/output/writer/buffer/interactive.rb +141 -0
- data/lib/test_bench_isolated/test_bench/session/output/writer/buffer.rb +29 -0
- data/lib/test_bench_isolated/test_bench/session/output/writer/defaults.rb +19 -0
- data/lib/test_bench_isolated/test_bench/session/output/writer/substitute.rb +19 -0
- data/lib/test_bench_isolated/test_bench/session/output/writer.rb +97 -0
- data/lib/test_bench_isolated/test_bench/session/output.rb +377 -0
- data/lib/test_bench_isolated/test_bench/session/projection.rb +30 -0
- data/lib/test_bench_isolated/test_bench/session/session.rb +220 -0
- data/lib/test_bench_isolated/test_bench/session/store.rb +61 -0
- data/lib/test_bench_isolated/test_bench/session/substitute/path.rb +65 -0
- data/lib/test_bench_isolated/test_bench/session/substitute/sink.rb +114 -0
- data/lib/test_bench_isolated/test_bench/session/substitute.rb +120 -0
- data/lib/test_bench_isolated/test_bench/session.rb +22 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/event/event_data.rb +17 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/event/metadata.rb +72 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/event.rb +140 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/event_data.rb +131 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/file.rb +86 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/handler.rb +83 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/process_id.rb +21 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/projection/receiver.rb +33 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/projection.rb +86 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/random.rb +9 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/sink.rb +35 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls/time.rb +125 -0
- data/lib/test_bench_isolated/test_bench/telemetry/controls.rb +17 -0
- data/lib/test_bench_isolated/test_bench/telemetry/event.rb +108 -0
- data/lib/test_bench_isolated/test_bench/telemetry/event_data/serialization.rb +172 -0
- data/lib/test_bench_isolated/test_bench/telemetry/event_data.rb +15 -0
- data/lib/test_bench_isolated/test_bench/telemetry/sink/file.rb +33 -0
- data/lib/test_bench_isolated/test_bench/telemetry/sink/handler/event_registry.rb +44 -0
- data/lib/test_bench_isolated/test_bench/telemetry/sink/handler.rb +128 -0
- data/lib/test_bench_isolated/test_bench/telemetry/sink/projection.rb +134 -0
- data/lib/test_bench_isolated/test_bench/telemetry/sink.rb +13 -0
- data/lib/test_bench_isolated/test_bench/telemetry/substitute/sink.rb +85 -0
- data/lib/test_bench_isolated/test_bench/telemetry/substitute.rb +34 -0
- data/lib/test_bench_isolated/test_bench/telemetry/telemetry.rb +111 -0
- data/lib/test_bench_isolated/test_bench/telemetry.rb +17 -0
- data/lib/test_bench_isolated/test_bench/test_bench.rb +56 -0
- data/lib/test_bench_isolated/test_bench.rb +5 -0
- data/script/bench +5 -0
- metadata +156 -7
- data/lib/test_bench/bootstrap.rb +0 -328
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f481a604aa280b59333588ed3473d30c0ca272f732133952a54ee2d833914fad
|
4
|
+
data.tar.gz: 3aa29f7077ea35970b3e263bee0d6cff7dfd00f2221d39bb491cfebcfecef260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b482e2e30289919565e2a2995809ee8c188cc20be58985bc2ff7e53721866c02376f3bdb480211de1ce3b691c97e5ed543a7a101b6f4e8d11759f6c6ce3d15f1
|
7
|
+
data.tar.gz: 119daa3855015ce6d2de5438cf99f70f8969dc0f96c21d8a644f9844b05572d8b23590bfa6c05d96ca4edf3e0073d1f5d31cee7a246465416f156f2069457ace
|
@@ -0,0 +1,298 @@
|
|
1
|
+
module TestBenchIsolated
|
2
|
+
module TestBench
|
3
|
+
class CLI
|
4
|
+
ArgumentError = Class.new(RuntimeError)
|
5
|
+
|
6
|
+
attr_reader :arguments
|
7
|
+
|
8
|
+
attr_accessor :exit_code
|
9
|
+
|
10
|
+
def env
|
11
|
+
@env ||= {}
|
12
|
+
end
|
13
|
+
attr_writer :env
|
14
|
+
|
15
|
+
def program_name
|
16
|
+
@program_name ||= Defaults.program_name
|
17
|
+
end
|
18
|
+
attr_writer :program_name
|
19
|
+
|
20
|
+
def version
|
21
|
+
@version ||= Defaults.version
|
22
|
+
end
|
23
|
+
attr_writer :version
|
24
|
+
|
25
|
+
def stdin
|
26
|
+
@stdin ||= STDIN
|
27
|
+
end
|
28
|
+
attr_writer :stdin
|
29
|
+
|
30
|
+
def writer
|
31
|
+
@writer ||= Output::Writer::Substitute.build
|
32
|
+
end
|
33
|
+
attr_writer :writer
|
34
|
+
|
35
|
+
def run
|
36
|
+
@run ||= Run::Substitute.build
|
37
|
+
end
|
38
|
+
attr_writer :run
|
39
|
+
|
40
|
+
def random
|
41
|
+
@random ||= Random::Substitute.build
|
42
|
+
end
|
43
|
+
attr_writer :random
|
44
|
+
|
45
|
+
def initialize(*arguments)
|
46
|
+
@arguments = arguments
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.build(arguments=nil, env: nil)
|
50
|
+
arguments ||= ::ARGV
|
51
|
+
env ||= ::ENV
|
52
|
+
|
53
|
+
instance = new(*arguments)
|
54
|
+
instance.env = env
|
55
|
+
Output::Writer.configure(instance)
|
56
|
+
Run.configure(instance)
|
57
|
+
Random.configure(instance)
|
58
|
+
instance
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.call(arguments=nil, env: nil)
|
62
|
+
instance = build(arguments, env:)
|
63
|
+
|
64
|
+
session = instance.run.session
|
65
|
+
Session::Store.reset(session)
|
66
|
+
|
67
|
+
exit_code = instance.()
|
68
|
+
|
69
|
+
exit(exit_code)
|
70
|
+
end
|
71
|
+
|
72
|
+
def call
|
73
|
+
parse_arguments
|
74
|
+
|
75
|
+
if exit_code?
|
76
|
+
return exit_code
|
77
|
+
end
|
78
|
+
|
79
|
+
writer.puts(RUBY_DESCRIPTION)
|
80
|
+
writer.puts("Random Seed: #{random.seed.to_s(36)}")
|
81
|
+
writer.puts
|
82
|
+
|
83
|
+
default_path = Defaults.tests_directory
|
84
|
+
|
85
|
+
result = run.! do |run|
|
86
|
+
if not stdin.tty?
|
87
|
+
until stdin.eof?
|
88
|
+
path = stdin.gets(chomp: true)
|
89
|
+
|
90
|
+
next if path.empty?
|
91
|
+
|
92
|
+
run << path
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
arguments.each do |path|
|
97
|
+
run << path
|
98
|
+
end
|
99
|
+
|
100
|
+
if not run.ran?
|
101
|
+
run << default_path
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
self.exit_code = self.class.exit_code(result)
|
106
|
+
|
107
|
+
exit_code
|
108
|
+
end
|
109
|
+
|
110
|
+
def parse_arguments
|
111
|
+
argument_index = 0
|
112
|
+
|
113
|
+
until argument_index == arguments.count
|
114
|
+
next_argument = next_argument(argument_index)
|
115
|
+
|
116
|
+
if not next_argument.start_with?('-')
|
117
|
+
argument_index += 1
|
118
|
+
next
|
119
|
+
end
|
120
|
+
|
121
|
+
switch = next_argument!(argument_index)
|
122
|
+
|
123
|
+
case switch
|
124
|
+
when '--'
|
125
|
+
break
|
126
|
+
|
127
|
+
when '-h', '--help'
|
128
|
+
print_help_text
|
129
|
+
|
130
|
+
self.exit_code = 0
|
131
|
+
|
132
|
+
when '-v', '--version'
|
133
|
+
writer.puts "TestBench Version: #{version}"
|
134
|
+
|
135
|
+
self.exit_code = 0
|
136
|
+
|
137
|
+
when '-d', '--detail', '--no-detail'
|
138
|
+
if not negated?(switch)
|
139
|
+
detail_policy_text = 'on'
|
140
|
+
else
|
141
|
+
detail_policy_text = 'off'
|
142
|
+
end
|
143
|
+
|
144
|
+
detail_policy = detail_policy_text.to_sym
|
145
|
+
Session::Output::Detail.assure_detail(detail_policy)
|
146
|
+
|
147
|
+
env['TEST_BENCH_DETAIL'] = detail_policy_text
|
148
|
+
|
149
|
+
when '-x', '--exclude', '--no-exclude'
|
150
|
+
if not negated?(switch)
|
151
|
+
exclude_file_pattern_text = switch_value!(argument_index, switch)
|
152
|
+
else
|
153
|
+
exclude_file_pattern_text = ''
|
154
|
+
end
|
155
|
+
|
156
|
+
env['TEST_BENCH_EXCLUDE_FILE_PATTERN'] = exclude_file_pattern_text
|
157
|
+
|
158
|
+
when '-f', '--only-failure', '--no-only-failure'
|
159
|
+
if not negated?(switch)
|
160
|
+
only_failure_text = 'on'
|
161
|
+
else
|
162
|
+
only_failure_text = 'off'
|
163
|
+
end
|
164
|
+
|
165
|
+
env['TEST_BENCH_ONLY_FAILURE'] = only_failure_text
|
166
|
+
|
167
|
+
when '-o', '--output-styling'
|
168
|
+
output_styling_text = switch_value(argument_index) do
|
169
|
+
'on'
|
170
|
+
end
|
171
|
+
|
172
|
+
output_styling = output_styling_text.to_sym
|
173
|
+
Output::Writer::Styling.assure_styling(output_styling)
|
174
|
+
|
175
|
+
env['TEST_BENCH_OUTPUT_STYLING'] = output_styling_text
|
176
|
+
|
177
|
+
when '-s', '--seed'
|
178
|
+
seed_text = switch_value!(argument_index, switch)
|
179
|
+
|
180
|
+
begin
|
181
|
+
Integer(seed_text)
|
182
|
+
rescue
|
183
|
+
raise ArgumentError, "Seed switch must be an integer (Seed: #{seed_text.inspect})"
|
184
|
+
end
|
185
|
+
|
186
|
+
env['TEST_BENCH_SEED'] = seed_text
|
187
|
+
|
188
|
+
when '-r', '--require'
|
189
|
+
library = switch_value!(argument_index, switch)
|
190
|
+
|
191
|
+
require library
|
192
|
+
|
193
|
+
else
|
194
|
+
raise ArgumentError, "Unknown switch #{switch.inspect}"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def print_help_text
|
200
|
+
writer.write <<~TEXT
|
201
|
+
Usage: #{program_name} [options] [paths]
|
202
|
+
|
203
|
+
Informational Options:
|
204
|
+
\t-h, --help Print this help message and exit successfully
|
205
|
+
\t-v, --version Print version and exit successfully
|
206
|
+
|
207
|
+
Configuration Options:
|
208
|
+
\t-d, --[no]detail Always show (or hide) details (Default: #{Session::Output::Detail.default})
|
209
|
+
\t-x, --[no-]exclude PATTERN Do not execute test files matching PATTERN (Default: #{Run::GetFiles::Defaults.exclude_file_pattern.inspect})
|
210
|
+
\t-f, --[no-]only-failure Don't display output for test files that pass (Default: #{Run::Output::File::Defaults.only_failure ? 'on' : 'off'})
|
211
|
+
\t-o, --output-styling [on|off|detect]
|
212
|
+
\t Render output coloring and font styling escape codes (Default: #{Output::Writer::Styling.default})
|
213
|
+
\t-s, --seed NUMBER Sets pseudo-random number seed (Default: not set)
|
214
|
+
|
215
|
+
Other Options:
|
216
|
+
\t-r, --require LIBRARY Require LIBRARY before running any files
|
217
|
+
|
218
|
+
Paths to test files (and directories containing test files) can be given after any command line arguments or via STDIN (or both).
|
219
|
+
|
220
|
+
If no paths are given, a default path (#{Defaults.tests_directory}) is scanned for test files.
|
221
|
+
|
222
|
+
The following environment variables can also control execution:
|
223
|
+
|
224
|
+
\tTEST_BENCH_DETAIL Same as -d or --detail
|
225
|
+
\tTEST_BENCH_EXCLUDE_FILE_PATTERN Same as -x or --exclude-file-pattern
|
226
|
+
\tTEST_BENCH_ONLY_FAILURE Same as -f or --only-failure
|
227
|
+
\tTEST_BENCH_OUTPUT_STYLING Same as -o or --output-styling
|
228
|
+
\tTEST_BENCH_SEED Same as -s or --seed
|
229
|
+
|
230
|
+
TEXT
|
231
|
+
end
|
232
|
+
|
233
|
+
def negated?(switch)
|
234
|
+
switch.start_with?('--no-')
|
235
|
+
end
|
236
|
+
|
237
|
+
def exit_code?
|
238
|
+
!exit_code.nil?
|
239
|
+
end
|
240
|
+
|
241
|
+
def switch_value!(argument_index, argument)
|
242
|
+
switch_value(argument_index) do
|
243
|
+
raise ArgumentError, "Argument #{argument.inspect} requires an argument"
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def switch_value(argument_index, &no_value_action)
|
248
|
+
next_value = next_argument(argument_index)
|
249
|
+
|
250
|
+
if next_value.nil? || next_value.start_with?('-')
|
251
|
+
switch_value = nil
|
252
|
+
|
253
|
+
return no_value_action.()
|
254
|
+
else
|
255
|
+
switch_value = next_argument!(argument_index)
|
256
|
+
|
257
|
+
return switch_value
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def next_argument(argument_index)
|
262
|
+
arguments[argument_index]
|
263
|
+
end
|
264
|
+
|
265
|
+
def next_argument!(argument_index)
|
266
|
+
arguments.delete_at(argument_index)
|
267
|
+
end
|
268
|
+
|
269
|
+
def self.exit_code(result)
|
270
|
+
if result == true
|
271
|
+
0
|
272
|
+
elsif result == false
|
273
|
+
1
|
274
|
+
else
|
275
|
+
2
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
module Defaults
|
280
|
+
def self.tests_directory
|
281
|
+
ENV.fetch('TEST_BENCH_TESTS_DIRECTORY', 'test/automated')
|
282
|
+
end
|
283
|
+
|
284
|
+
def self.program_name
|
285
|
+
$PROGRAM_NAME || 'bench'
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.version
|
289
|
+
if Object.const_defined?(:Gem)
|
290
|
+
spec = Gem.loaded_specs['test_bench']
|
291
|
+
end
|
292
|
+
|
293
|
+
spec&.version || '(unknown)'
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module TestBenchIsolated
|
2
|
+
module TestBench
|
3
|
+
module Controls
|
4
|
+
module Stdin
|
5
|
+
module Create
|
6
|
+
def self.call(*paths)
|
7
|
+
if paths.empty?
|
8
|
+
paths = Path.examples
|
9
|
+
end
|
10
|
+
|
11
|
+
contents = <<~TEXT
|
12
|
+
#{paths.join("\n")}
|
13
|
+
TEXT
|
14
|
+
|
15
|
+
file = File::Create.(contents:)
|
16
|
+
|
17
|
+
::File.open(file, 'r')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.contents
|
21
|
+
<<~TEXT
|
22
|
+
#{Path.example}
|
23
|
+
TEXT
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test_bench_isolated/test_bench/random/controls'
|
2
|
+
require 'test_bench_isolated/test_bench/run/controls'
|
3
|
+
|
4
|
+
require 'test_bench_isolated/test_bench/controls/result'
|
5
|
+
|
6
|
+
require 'test_bench_isolated/test_bench/controls/path'
|
7
|
+
|
8
|
+
require 'test_bench_isolated/test_bench/controls/file'
|
9
|
+
require 'test_bench_isolated/test_bench/controls/stdin'
|
10
|
+
|
11
|
+
require 'test_bench_isolated/test_bench/controls/random'
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module TestBenchIsolated
|
2
|
+
module TestBench
|
3
|
+
module Fixture
|
4
|
+
module Actuate
|
5
|
+
module Class
|
6
|
+
Error = ::Class.new(RuntimeError)
|
7
|
+
|
8
|
+
def self.call(fixture_class, *, session: nil, **, &block)
|
9
|
+
if test_block?(fixture_class)
|
10
|
+
test_block = block
|
11
|
+
else
|
12
|
+
block_actuator = block
|
13
|
+
end
|
14
|
+
|
15
|
+
fixture = build_fixture(fixture_class, *, **, &test_block)
|
16
|
+
|
17
|
+
Session.configure(fixture, session:, attr_name: :test_session)
|
18
|
+
|
19
|
+
actuate(fixture, &block_actuator)
|
20
|
+
|
21
|
+
fixture
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.actuate(fixture, &block_actuator)
|
25
|
+
if fixture.respond_to?(:call)
|
26
|
+
fixture_actuator = fixture
|
27
|
+
end
|
28
|
+
|
29
|
+
if block_actuator && fixture_actuator
|
30
|
+
raise Error, "Block argument given to fixture that has an actuator (Fixture Class: #{fixture.class})"
|
31
|
+
end
|
32
|
+
|
33
|
+
if block_actuator.nil? && fixture_actuator.nil?
|
34
|
+
raise Error, "No actuator"
|
35
|
+
end
|
36
|
+
|
37
|
+
if not block_actuator.nil?
|
38
|
+
block_actuator.(fixture)
|
39
|
+
else
|
40
|
+
fixture_actuator.()
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.build_fixture(fixture_class, ...)
|
45
|
+
constructor = constructor(fixture_class)
|
46
|
+
|
47
|
+
fixture_class.public_send(constructor, ...)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.test_block?(fixture_class)
|
51
|
+
assure_fixture(fixture_class)
|
52
|
+
|
53
|
+
constructor = constructor(fixture_class)
|
54
|
+
|
55
|
+
if constructor == :build
|
56
|
+
constructor_method = fixture_class.method(:build)
|
57
|
+
else
|
58
|
+
constructor_method = fixture_class.instance_method(:initialize)
|
59
|
+
end
|
60
|
+
|
61
|
+
constructor_parameters = constructor_method.parameters
|
62
|
+
|
63
|
+
constructor_parameters.any? do |(type, _)|
|
64
|
+
type == :block
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.constructor(fixture_class)
|
69
|
+
assure_fixture(fixture_class)
|
70
|
+
|
71
|
+
if fixture_class.respond_to?(:build)
|
72
|
+
:build
|
73
|
+
else
|
74
|
+
:new
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.assure_fixture(fixture_class)
|
79
|
+
is_class = fixture_class.instance_of?(::Class)
|
80
|
+
|
81
|
+
if not is_class
|
82
|
+
raise Error, "Not a class (Class: #{fixture_class})"
|
83
|
+
end
|
84
|
+
|
85
|
+
if is_class
|
86
|
+
is_fixture_class = fixture_class.included_modules.include?(Fixture)
|
87
|
+
end
|
88
|
+
|
89
|
+
if not is_fixture_class
|
90
|
+
raise Error, "Not a fixture class (Class: #{fixture_class})"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module TestBenchIsolated
|
2
|
+
module TestBench
|
3
|
+
module Fixture
|
4
|
+
module Actuate
|
5
|
+
module Object
|
6
|
+
ModuleError = ::Class.new(RuntimeError)
|
7
|
+
|
8
|
+
def self.call(object, *modules, session: nil, &block_actuator)
|
9
|
+
extend(object, *modules)
|
10
|
+
|
11
|
+
Session.configure(object, session:, attr_name: :test_session)
|
12
|
+
|
13
|
+
block_actuator.(object)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.extend(object, *modules)
|
17
|
+
if modules.empty?
|
18
|
+
fixture_modules = fixture_modules(object)
|
19
|
+
else
|
20
|
+
fixture_modules = modules.map do |mod|
|
21
|
+
assure_included(object, mod)
|
22
|
+
|
23
|
+
fixture_module(mod)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if fixture_modules.empty?
|
28
|
+
raise ModuleError, "No Fixture modules found -- #{object.inspect}"
|
29
|
+
end
|
30
|
+
|
31
|
+
fixture_modules.each do |fixture_module|
|
32
|
+
object.extend(fixture_module)
|
33
|
+
end
|
34
|
+
|
35
|
+
object.extend(Fixture)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.assure_included(object, mod)
|
39
|
+
if not object.is_a?(mod)
|
40
|
+
raise ModuleError, "Object doesn't include module -- #{mod.inspect}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.fixture_modules(object)
|
45
|
+
fixture_modules = []
|
46
|
+
|
47
|
+
targets = included_modules(object)
|
48
|
+
|
49
|
+
targets << object
|
50
|
+
|
51
|
+
targets.select do |target|
|
52
|
+
if fixture_module?(target)
|
53
|
+
fixture_module = fixture_module(target)
|
54
|
+
fixture_modules << fixture_module
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
fixture_modules
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.fixture_module(object)
|
62
|
+
if not fixture_module?(object)
|
63
|
+
raise ModuleError, "Couldn't resolve a Fixture module -- #{object.inspect}"
|
64
|
+
end
|
65
|
+
|
66
|
+
target = fixture_module_target(object)
|
67
|
+
|
68
|
+
target.const_get(:Fixture, false)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.fixture_module?(object)
|
72
|
+
target = fixture_module_target(object)
|
73
|
+
|
74
|
+
target.const_defined?(:Fixture, false)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.fixture_module_target(object)
|
78
|
+
if object.is_a?(Module)
|
79
|
+
object
|
80
|
+
else
|
81
|
+
object.class
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.included_modules(object)
|
86
|
+
modules = (object.class.included_modules | object.singleton_class.included_modules) - ::Object.included_modules
|
87
|
+
modules.sort_by(&:name)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module TestBenchIsolated
|
2
|
+
module TestBench
|
3
|
+
module Fixture
|
4
|
+
module Controls
|
5
|
+
module Fixture
|
6
|
+
module Class
|
7
|
+
Example = Fixture::Example
|
8
|
+
|
9
|
+
class BuildMethod
|
10
|
+
include TestBench::Fixture
|
11
|
+
|
12
|
+
attr_accessor :some_argument
|
13
|
+
attr_accessor :some_keyword_argument
|
14
|
+
|
15
|
+
def self.build(some_argument=nil, some_keyword_argument: nil)
|
16
|
+
instance = new
|
17
|
+
instance.some_argument = some_argument
|
18
|
+
instance.some_keyword_argument = some_keyword_argument
|
19
|
+
instance
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class NoBuildMethod
|
24
|
+
include TestBench::Fixture
|
25
|
+
|
26
|
+
attr_reader :some_argument
|
27
|
+
attr_reader :some_keyword_argument
|
28
|
+
|
29
|
+
def initialize(some_argument=nil, some_keyword_argument: nil)
|
30
|
+
@some_argument = some_argument
|
31
|
+
@some_keyword_argument = some_keyword_argument
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class TestBlock
|
36
|
+
include TestBench::Fixture
|
37
|
+
|
38
|
+
attr_reader :test_block
|
39
|
+
|
40
|
+
def initialize(&test_block)
|
41
|
+
@test_block = test_block
|
42
|
+
end
|
43
|
+
|
44
|
+
NoBuildMethod = TestBlock
|
45
|
+
|
46
|
+
class BuildMethod
|
47
|
+
include TestBench::Fixture
|
48
|
+
|
49
|
+
attr_reader :test_block
|
50
|
+
|
51
|
+
def initialize(test_block)
|
52
|
+
@test_block = test_block
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.build(&test_block)
|
56
|
+
new(test_block)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
None = Fixture::Class::BuildMethod
|
61
|
+
end
|
62
|
+
|
63
|
+
class Actuator
|
64
|
+
include TestBench::Fixture
|
65
|
+
|
66
|
+
attr_accessor :actuated
|
67
|
+
def actuated? = !!actuated
|
68
|
+
|
69
|
+
def call
|
70
|
+
self.actuated = true
|
71
|
+
end
|
72
|
+
|
73
|
+
class TestBlock < Actuator
|
74
|
+
attr_reader :test_block
|
75
|
+
|
76
|
+
def initialize(&test_block)
|
77
|
+
@test_block = test_block
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
NoActuator = Example
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|