tryouts 2.4.0 → 3.0.0.pre

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.
@@ -1,15 +1,5 @@
1
- # frozen_string_literal: true
1
+ # lib/tryouts/version.rb
2
2
 
3
3
  class Tryouts
4
- module VERSION
5
- def self.to_s
6
- version_file
7
- [@version_file[:MAJOR], @version_file[:MINOR], @version_file[:PATCH]].join('.')
8
- end
9
- alias_method :inspect, :to_s
10
- def self.version_file
11
- require 'yaml'
12
- @version_file ||= YAML.load_file(File.join(TRYOUTS_LIB_HOME, '..', 'VERSION.yml'))
13
- end
14
- end
4
+ VERSION = '3.0.0.pre'
15
5
  end
data/lib/tryouts.rb CHANGED
@@ -1,23 +1,29 @@
1
- # frozen_string_literal: true
1
+ # lib/tryouts.rb
2
+
3
+ # Coverage tracking
4
+ if ENV['COVERAGE'] || ENV['SIMPLECOV']
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+ end
2
8
 
3
9
  require 'stringio'
4
10
 
5
11
  TRYOUTS_LIB_HOME = __dir__ unless defined?(TRYOUTS_LIB_HOME)
6
12
 
7
13
  require_relative 'tryouts/console'
8
- require_relative 'tryouts/section'
9
14
  require_relative 'tryouts/testbatch'
10
- require_relative 'tryouts/testcase'
11
15
  require_relative 'tryouts/version'
16
+ require_relative 'tryouts/prism_parser'
17
+ require_relative 'tryouts/cli'
12
18
 
13
19
  class Tryouts
14
- @debug = false
15
- @quiet = false
16
- @noisy = false
17
- @fails = false
18
- @container = Class.new
19
- @cases = []
20
- @sysinfo = nil
20
+ @debug = false
21
+ @quiet = false
22
+ @noisy = false
23
+ @fails = false
24
+ @container = Class.new
25
+ @cases = [] # rubocop:disable ThreadSafety/MutableClassInstanceVariable
26
+ @sysinfo = nil
21
27
  @testcase_io = StringIO.new
22
28
 
23
29
  module ClassMethods
@@ -39,250 +45,11 @@ class Tryouts
39
45
  Dir.glob(lib_glob).each { |dir| $LOAD_PATH.unshift(dir) }
40
46
  end
41
47
 
42
- def run_all *paths
43
- batches = paths.collect do |path|
44
- parse path
45
- end
46
-
47
- tryouts_incr = 0
48
- skipped_tests = 0
49
- failed_tests = 0
50
- skipped_batches = 0
51
- failed_batches = 0
52
-
53
- msg format('Ruby %s @ %-60s', RUBY_VERSION, Time.now), $/
54
-
55
- if Tryouts.debug?
56
- Tryouts.debug "Found #{paths.size} files:"
57
- paths.each { |path| Tryouts.debug " #{path}" }
58
- Tryouts.debug
59
- end
60
-
61
- batches.each do |batch|
62
- path = batch.path.gsub(%r{#{Dir.pwd}/?}, '')
63
- divider = '-' * 70
64
- path_pretty = format('>>>>> %-20s %s', path, '').ljust(70, '<')
65
-
66
- msg $/
67
- vmsg Console.reverse(divider)
68
- vmsg Console.reverse(path_pretty)
69
- vmsg Console.reverse(divider)
70
- vmsg $/
71
-
72
- before_handler = proc do |tc|
73
- if Tryouts.noisy
74
- tc_title = tc.desc.to_s
75
- vmsg Console.underline(format('%-58s ', tc_title))
76
- vmsg tc.test.inspect, tc.exps.inspect
77
- end
78
- end
79
-
80
- batch.run(before_handler) do |tc|
81
- tryouts_incr += 1
82
- failed_tests += 1 if tc.failed?
83
- skipped_tests += 1 if tc.skipped?
84
- codelines = tc.testrunner_output.join($/)
85
- first_exp_line = tc.exps.first
86
-
87
- Tryouts.debug Console.color(:white, "tryouts_incr is now %d" % tryouts_incr)
88
-
89
- first_exp_line = tc.exps.first
90
- location = format('%s:%d', tc.exps.path, first_exp_line)
91
-
92
- expectation = Console.color(tc.color, codelines)
93
- summary = Console.color(tc.color, "%s @ %s" % [tc.adjective, location])
94
- vmsg ' %s' % expectation
95
- if tc.failed?
96
- msg Console.reverse(summary)
97
- else
98
- msg summary
99
- end
100
- vmsg
101
-
102
- # Output the buffered testcase_io to stdout
103
- # and then reset it for the next test case.
104
- unless Tryouts.fails && !tc.failed?
105
- $stdout.puts testcase_io.string unless Tryouts.quiet
106
- $stdout.puts tc.console_output.string if Tryouts.noisy
107
- end
108
-
109
- # Reset the testcase IO buffer
110
- testcase_io.truncate(0)
111
- end
112
- end
113
-
114
- # Create a line of separation before the result summary
115
- msg $INPUT_RECORD_SEPARATOR # newline
116
-
117
- if tryouts_incr
118
- suffix = "tryouts passed"
119
- if skipped_tests > 0
120
- suffix = "#{suffix} (#{skipped_tests} skipped)"
121
- end
122
-
123
- actual_test_size = tryouts_incr - skipped_tests
124
- if actual_test_size > 0
125
- success_count = tryouts_incr - failed_tests - skipped_tests
126
- total_count = tryouts_incr - skipped_tests
127
- msg cformat(success_count, total_count, suffix)
128
- end
129
- end
130
-
131
- # In what circumstance is this ever true?
132
- #
133
- adjusted_batch_size = (batches.size - skipped_batches)
134
- if batches.size > 1 && adjusted_batch_size > 0
135
- suffix = 'batches passed'
136
- suffix << " (#{skipped_batches} skipped)" if skipped_batches > 0
137
- success_count = adjusted_batch_size - failed_batches
138
- total_count = adjusted_batch_size
139
- msg cformat(success_count, total_count, suffix)
140
- end
141
-
142
- # Print out the buffered result summary
143
- $stdout.puts testcase_io.string
144
-
145
- failed_tests # returns the number of failed tests (0 if all passed)
146
- end
147
-
148
- def cformat(lval, rval, suffix = nil)
149
- Console.bright '%d of %d %s' % [lval, rval, suffix]
150
- end
151
-
152
- def run(path)
153
- batch = parse path
154
- batch.run
155
- batch
156
- end
157
-
158
- def parse(path)
159
- # debug "Loading #{path}"
160
- lines = File.readlines path
161
- skip_ahead = 0
162
- batch = TestBatch.new path, lines
163
- lines.size.times do |idx|
164
- skip_ahead -= 1 and next if skip_ahead > 0
165
-
166
- line = lines[idx].chomp
167
- # debug('%-4d %s' % [idx, line])
168
- next unless expectation? line
169
-
170
- offset = 0
171
- exps = Section.new(path, idx + 1)
172
- exps << line.chomp
173
- while idx + offset < lines.size
174
- offset += 1
175
- this_line = lines[idx + offset]
176
- break if ignore?(this_line)
177
-
178
- if expectation?(this_line)
179
- exps << this_line.chomp
180
- skip_ahead += 1
181
- end
182
- exps.last += 1
183
- end
184
-
185
- offset = 0
186
- buffer = Section.new(path)
187
- desc = Section.new(path)
188
- test = Section.new(path, idx) # test start the line before the exp.
189
- while idx - offset >= 0
190
- offset += 1
191
- this_line = lines[idx - offset].chomp
192
- buffer.unshift this_line if ignore?(this_line)
193
- buffer.unshift this_line if comment?(this_line)
194
- if test?(this_line)
195
- test.unshift(*buffer) && buffer.clear
196
- test.unshift this_line
197
- end
198
- if test_begin?(this_line)
199
- while test_begin?(lines[idx - (offset + 1)].chomp)
200
- offset += 1
201
- buffer.unshift lines[idx - offset].chomp
202
- end
203
- end
204
- next unless test_begin?(this_line) || idx - offset == 0 || expectation?(this_line)
205
-
206
- adjust = expectation?(this_line) ? 2 : 1
207
- test.first = idx - offset + buffer.size + adjust
208
- desc.unshift(*buffer)
209
- desc.last = test.first - 1
210
- desc.first = desc.last - desc.size + 1
211
- # remove empty lines between the description
212
- # and the previous expectation
213
- while !desc.empty? && desc[0].empty?
214
- desc.shift
215
- desc.first += 1
216
- end
217
- break
218
- end
219
-
220
- batch << TestCase.new(desc, test, exps)
221
- end
222
-
223
- batch
224
- end
225
-
226
- def print(str)
227
- return if Tryouts.quiet
228
-
229
- $stdout.print str
230
- $stdout.flush
231
- end
232
-
233
- def vmsg *msgs
234
- msg(*msgs) if Tryouts.noisy
235
- end
236
-
237
- def msg *msgs
238
- testcase_io.puts(*msgs) unless Tryouts.quiet
239
- end
240
-
241
- def info *msgs
242
- msgs.each do |line|
243
- $stdout.puts line
244
- end
245
- end
246
-
247
- def err *msgs
248
- msgs.each do |line|
249
- $stderr.puts Console.color :red, line
250
- end
251
- end
252
-
253
- def debug *msgs
254
- $stderr.puts(*msgs) if debug?
255
- end
256
-
257
- def eval(str, path, line)
258
- Kernel.eval str, @container.send(:binding), path, line
259
- rescue SyntaxError, LoadError => e
260
- Tryouts.err Console.color(:red, e.message),
261
- Console.color(:red, e.backtrace.first)
262
- nil
263
- end
264
-
265
- private
266
-
267
- def expectation?(str)
268
- !ignore?(str) && str.strip.match(/\A\#+\s*=>/)
269
- end
270
-
271
- def comment?(str)
272
- !str.strip.match(/^\#+/).nil? && !expectation?(str)
273
- end
274
-
275
- def test?(str)
276
- !ignore?(str) && !expectation?(str) && !comment?(str)
277
- end
278
-
279
- def ignore?(str)
280
- str.to_s.strip.chomp.empty?
281
- end
48
+ def trace(msg, indent: 0)
49
+ return unless debug?
282
50
 
283
- def test_begin?(str)
284
- !str.strip.match(/\#+\s*TEST/i).nil? ||
285
- !str.strip.match(/\A\#\#+[\s\w]+/i).nil?
51
+ prefix = (' ' * indent) + Console.color(:dim, 'TRACE')
52
+ warn "#{prefix} #{msg}"
286
53
  end
287
54
  end
288
55
 
metadata CHANGED
@@ -1,29 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 3.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-07-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: sysinfo
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
15
28
  requirement: !ruby/object:Gem::Requirement
16
29
  requirements:
17
30
  - - "~>"
18
31
  - !ruby/object:Gem::Version
19
- version: '0.10'
32
+ version: '3.0'
20
33
  type: :runtime
21
34
  prerelease: false
22
35
  version_requirements: !ruby/object:Gem::Requirement
23
36
  requirements:
24
37
  - - "~>"
25
38
  - !ruby/object:Gem::Version
26
- version: '0.10'
39
+ version: '3.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: sysinfo
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0.8'
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0.8'
57
+ - - "<"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
27
60
  description: A simple test framework for Ruby code that uses introspection to allow
28
61
  defining checks in comments.
29
62
  email: gems@solutious.com
@@ -35,20 +68,35 @@ extra_rdoc_files: []
35
68
  files:
36
69
  - LICENSE.txt
37
70
  - README.md
38
- - VERSION.yml
39
71
  - exe/try
40
72
  - exe/tryouts
41
73
  - lib/tryouts.rb
74
+ - lib/tryouts/cli.rb
75
+ - lib/tryouts/cli/formatters.rb
76
+ - lib/tryouts/cli/formatters/base.rb
77
+ - lib/tryouts/cli/formatters/compact.rb
78
+ - lib/tryouts/cli/formatters/factory.rb
79
+ - lib/tryouts/cli/formatters/output_manager.rb
80
+ - lib/tryouts/cli/formatters/quiet.rb
81
+ - lib/tryouts/cli/formatters/verbose.rb
82
+ - lib/tryouts/cli/modes/generate.rb
83
+ - lib/tryouts/cli/modes/inspect.rb
84
+ - lib/tryouts/cli/opts.rb
42
85
  - lib/tryouts/console.rb
43
- - lib/tryouts/section.rb
86
+ - lib/tryouts/file_processor.rb
87
+ - lib/tryouts/prism_parser.rb
88
+ - lib/tryouts/test_executor.rb
89
+ - lib/tryouts/test_runner.rb
44
90
  - lib/tryouts/testbatch.rb
45
91
  - lib/tryouts/testcase.rb
92
+ - lib/tryouts/translators/minitest_translator.rb
93
+ - lib/tryouts/translators/rspec_translator.rb
46
94
  - lib/tryouts/version.rb
47
95
  homepage: https://github.com/delano/tryouts
48
96
  licenses:
49
97
  - MIT
50
- metadata: {}
51
- post_install_message:
98
+ metadata:
99
+ rubygems_mfa_required: 'true'
52
100
  rdoc_options: []
53
101
  require_paths:
54
102
  - lib
@@ -56,15 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
104
  requirements:
57
105
  - - ">="
58
106
  - !ruby/object:Gem::Version
59
- version: 2.7.8
107
+ version: '3.4'
60
108
  required_rubygems_version: !ruby/object:Gem::Requirement
61
109
  requirements:
62
110
  - - ">="
63
111
  - !ruby/object:Gem::Version
64
112
  version: '0'
65
113
  requirements: []
66
- rubygems_version: 3.5.15
67
- signing_key:
114
+ rubygems_version: 3.6.7
68
115
  specification_version: 4
69
116
  summary: Ruby tests that read like documentation.
70
117
  test_files: []
data/VERSION.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- :MAJOR: 2
3
- :MINOR: 4
4
- :PATCH: 0
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- class Tryouts
4
- class Section < Array
5
- attr_accessor :path, :first, :last
6
-
7
- def initialize(path, start = 0)
8
- @path = path
9
- @first = start
10
- @last = start
11
- end
12
-
13
- def range
14
- @first..@last
15
- end
16
-
17
- def inspect
18
- range.to_a.zip(self).collect do |line|
19
- "%-4d %s\n" % line
20
- end.join
21
- end
22
-
23
- def to_s
24
- join($/)
25
- end
26
- end
27
- end