tryouts 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c9881b556aa0492a4e0cba92343efa2c9761664a9507ac3d123fee8143301b8
4
- data.tar.gz: 245f405149281445c9bb902695919f6fbd4c5ec461303f16c7078ed6ddcbe111
3
+ metadata.gz: 17dda7b61be5923b407bd6e00c98c0ef3731897b3dd7afca88d00ed2bf240e5d
4
+ data.tar.gz: 846fa9f79683f8ce9cd1e486653abfb6da44883e937fcd9edbeaece2c0ef0e4c
5
5
  SHA512:
6
- metadata.gz: ced6968dc159ab82ffcc8902b9835977bfdac9fbf1f8290ce20c216a09fb07fe7731235ac464827094cdebb422048ae963cf396fcb604c37d8945d73d148a619
7
- data.tar.gz: b57ed46b023c084209153176fcbb05c4ec710cf1da0a77e61db1ac14e50b87f4bd1c5d35c73e2b9a950d855415e4728d5f229138bb6d8d51edab1bb3df8961f3
6
+ metadata.gz: 9deedfac36285115ca643ddfa818ef5db33a1daf93906fadba8b49689390e0a020324f2fed638454ebee0b30e3600d48d2258b8213bc14cbcd25c0660d132a51
7
+ data.tar.gz: 87d94a10b8500d2eb543f6c4c84be10f236a485bf4b94c79f12c8fc05ad6e2de6536087c43cd35ce5395ec8d38781006d67dafcd876c03d42cdca69f49cbf5d1
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Tryouts v2.3.1 (2024-06-18)
1
+ # Tryouts v2.4 (2024-07-20)
2
2
 
3
3
  **Ruby tests that read like documentation.**
4
4
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :MAJOR: 2
3
- :MINOR: 3
4
- :PATCH: 1
3
+ :MINOR: 4
4
+ :PATCH: 0
@@ -22,14 +22,26 @@ class Tryouts
22
22
  setup
23
23
  ret = self.select do |tc|
24
24
  before_test.call(tc) unless before_test.nil?
25
- ret = !tc.run
26
- after_test.call(tc)
25
+ begin
26
+ ret = !tc.run # returns true if test failed
27
+ rescue StandardError => e
28
+ ret = true
29
+ $stderr.puts Console.color(:red, "Error in test: #{tc.inspect}")
30
+ $stderr.puts Console.color(:red, e.message)
31
+ $stderr.puts e.backtrace.join($/), $/
32
+ end
33
+ after_test.call(tc) # runs the tallying code
27
34
  ret # select failed tests
28
35
  end
36
+
29
37
  @failed = ret.size
30
38
  @run = true
31
39
  clean
32
40
  !failed?
41
+
42
+ rescue StandardError => e
43
+ @failed = 1
44
+ $stderr.puts e.message, e.backtrace.join($/), $/
33
45
  end
34
46
 
35
47
  def failed?
@@ -2,11 +2,12 @@
2
2
 
3
3
  class Tryouts
4
4
  class TestCase
5
- attr_reader :desc, :test, :exps, :path, :outlines, :test_result
5
+ attr_reader :desc, :test, :exps, :path, :testrunner_output, :test_result, :console_output
6
6
 
7
7
  def initialize(d, t, e)
8
8
  @desc, @test, @exps, @path = d, t, e
9
- @outlines = []
9
+ @testrunner_output = []
10
+ @console_output = StringIO.new
10
11
  end
11
12
 
12
13
  def inspect
@@ -20,23 +21,27 @@ class Tryouts
20
21
  def run
21
22
  Tryouts.debug format('%s:%d', @test.path, @test.first)
22
23
  Tryouts.debug inspect, $/
23
- $stdout = StringIO.new
24
+
25
+ $stdout = @console_output
24
26
  expectations = exps.collect do |exp, _idx|
25
27
  exp =~ /\A\#?\s*=>\s*(.+)\Z/
26
28
  ::Regexp.last_match(1) # this will be nil if the expectation is commented out
27
29
  end
28
30
 
31
+ Tryouts.info 'Capturing STDOUT for tryout'
32
+ Tryouts.info 'vvvvvvvvvvvvvvvvvvv'
29
33
  # Evaluate test block only if there are valid expectations
30
34
  unless expectations.compact.empty? # TODO: fast-fail if no expectations
31
35
  test_value = Tryouts.eval @test.to_s, @test.path, @test.first
32
36
  @has_run = true
33
37
  end
34
- $stdout = STDOUT # restore stdout
35
-
38
+ Tryouts.info '^^^^^^^^^^^^^^^^^^^'
36
39
 
40
+ Tryouts.info "Capturing STDOUT for expectations"
41
+ Tryouts.info 'vvvvvvvvvvvvvvvvvvv'
37
42
  expectations.each_with_index do |exp, idx|
38
43
  if exp.nil?
39
- @outlines << ' [skipped]'
44
+ @testrunner_output << ' [skipped]'
40
45
  @test_result = 0
41
46
  else
42
47
  # Evaluate expectation
@@ -45,14 +50,21 @@ class Tryouts
45
50
 
46
51
  test_passed = test_value.eql?(exp_value)
47
52
  @test_result = test_passed ? 1 : -1
48
- @outlines << test_value.inspect
53
+ @testrunner_output << test_value.inspect
49
54
  end
50
55
  end
56
+ Tryouts.info '^^^^^^^^^^^^^^^^^^^'
57
+ $stdout = STDOUT # restore stdout
58
+
51
59
  Tryouts.debug # extra newline
52
60
  failed?
53
61
 
54
- rescue Exception => e
55
- Tryouts.debug e.message, e.backtrace.join($/), $/
62
+
63
+ rescue StandardError => e
64
+ Tryouts.debug "[testcaste.run] #{e.message}", e.backtrace.join($/), $/
65
+ # Continue raising the exception
66
+ raise e
67
+ ensure
56
68
  $stdout = STDOUT # restore stdout
57
69
  end
58
70
 
data/lib/tryouts.rb CHANGED
@@ -44,7 +44,7 @@ class Tryouts
44
44
  parse path
45
45
  end
46
46
 
47
- all = 0
47
+ tryouts_incr = 0
48
48
  skipped_tests = 0
49
49
  failed_tests = 0
50
50
  skipped_batches = 0
@@ -78,12 +78,13 @@ class Tryouts
78
78
  end
79
79
 
80
80
  batch.run(before_handler) do |tc|
81
- all += 1
81
+ tryouts_incr += 1
82
82
  failed_tests += 1 if tc.failed?
83
83
  skipped_tests += 1 if tc.skipped?
84
- codelines = tc.outlines.join($/)
84
+ codelines = tc.testrunner_output.join($/)
85
85
  first_exp_line = tc.exps.first
86
- result_adjective = tc.failed? ? 'FAILED' : 'PASSED'
86
+
87
+ Tryouts.debug Console.color(:white, "tryouts_incr is now %d" % tryouts_incr)
87
88
 
88
89
  first_exp_line = tc.exps.first
89
90
  location = format('%s:%d', tc.exps.path, first_exp_line)
@@ -98,10 +99,11 @@ class Tryouts
98
99
  end
99
100
  vmsg
100
101
 
101
- # Output buffered testcase_io to stdout
102
- # and reset it for the next test case.
102
+ # Output the buffered testcase_io to stdout
103
+ # and then reset it for the next test case.
103
104
  unless Tryouts.fails && !tc.failed?
104
105
  $stdout.puts testcase_io.string unless Tryouts.quiet
106
+ $stdout.puts tc.console_output.string if Tryouts.noisy
105
107
  end
106
108
 
107
109
  # Reset the testcase IO buffer
@@ -112,19 +114,29 @@ class Tryouts
112
114
  # Create a line of separation before the result summary
113
115
  msg $INPUT_RECORD_SEPARATOR # newline
114
116
 
115
- if all
116
- suffix = "tests passed (#{skipped_tests} skipped)" if skipped_tests > 0
117
- actual_test_size = all - skipped_tests
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
118
124
  if actual_test_size > 0
119
- msg cformat(all - failed_tests - skipped_tests, all - skipped_tests, suffix)
125
+ success_count = tryouts_incr - failed_tests - skipped_tests
126
+ total_count = tryouts_incr - skipped_tests
127
+ msg cformat(success_count, total_count, suffix)
120
128
  end
121
129
  end
122
130
 
123
- actual_batch_size = (batches.size - skipped_batches)
124
- if batches.size > 1 && actual_batch_size > 0
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
125
135
  suffix = 'batches passed'
126
136
  suffix << " (#{skipped_batches} skipped)" if skipped_batches > 0
127
- msg cformat(batches.size - skipped_batches - failed_batches, batches.size - skipped_batches, suffix)
137
+ success_count = adjusted_batch_size - failed_batches
138
+ total_count = adjusted_batch_size
139
+ msg cformat(success_count, total_count, suffix)
128
140
  end
129
141
 
130
142
  # Print out the buffered result summary
@@ -133,8 +145,8 @@ class Tryouts
133
145
  failed_tests # returns the number of failed tests (0 if all passed)
134
146
  end
135
147
 
136
- def cformat(*args)
137
- Console.bright '%d of %d %s' % args
148
+ def cformat(lval, rval, suffix = nil)
149
+ Console.bright '%d of %d %s' % [lval, rval, suffix]
138
150
  end
139
151
 
140
152
  def run(path)
@@ -210,6 +222,7 @@ class Tryouts
210
222
 
211
223
  batch
212
224
  end
225
+
213
226
  def print(str)
214
227
  return if Tryouts.quiet
215
228
 
@@ -225,8 +238,14 @@ class Tryouts
225
238
  testcase_io.puts(*msgs) unless Tryouts.quiet
226
239
  end
227
240
 
241
+ def info *msgs
242
+ msgs.each do |line|
243
+ $stdout.puts line
244
+ end
245
+ end
246
+
228
247
  def err *msgs
229
- msg.each do |line|
248
+ msgs.each do |line|
230
249
  $stderr.puts Console.color :red, line
231
250
  end
232
251
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-20 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sysinfo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
13
27
  description: A simple test framework for Ruby code that uses introspection to allow
14
28
  defining checks in comments.
15
29
  email: gems@solutious.com
@@ -49,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
63
  - !ruby/object:Gem::Version
50
64
  version: '0'
51
65
  requirements: []
52
- rubygems_version: 3.4.19
66
+ rubygems_version: 3.5.15
53
67
  signing_key:
54
68
  specification_version: 4
55
69
  summary: Ruby tests that read like documentation.