tryouts 2.3.2 → 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: eb6e297c2fe5c80dfc2f056d0df5e2742c72ee14e26566283746410d8d3eed5b
4
- data.tar.gz: de4ff46738db509b6a511e57a8cd4713510c9a38bec5d4fa7f61383585f0e554
3
+ metadata.gz: 17dda7b61be5923b407bd6e00c98c0ef3731897b3dd7afca88d00ed2bf240e5d
4
+ data.tar.gz: 846fa9f79683f8ce9cd1e486653abfb6da44883e937fcd9edbeaece2c0ef0e4c
5
5
  SHA512:
6
- metadata.gz: dd90be3bd46856d40055cf36e7cf41820b2692c06f117645daf1614ce8910dc4e7f28ada9731e1cf00674208f1c99f6fccd1f03b4b304ea03f29628fe51700ea
7
- data.tar.gz: d8214885cbc47e502c65f4a46383774ee881869aa88164ac475f559914110a2905448db7b8a4afb461d491e70d3f57be56be09924083619a4127dccc504ae63d
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: 2
3
+ :MINOR: 4
4
+ :PATCH: 0
@@ -22,14 +22,23 @@ 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
+
33
42
  rescue StandardError => e
34
43
  @failed = 1
35
44
  $stderr.puts e.message, e.backtrace.join($/), $/
@@ -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,22 +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
38
+ Tryouts.info '^^^^^^^^^^^^^^^^^^^'
35
39
 
40
+ Tryouts.info "Capturing STDOUT for expectations"
41
+ Tryouts.info 'vvvvvvvvvvvvvvvvvvv'
36
42
  expectations.each_with_index do |exp, idx|
37
43
  if exp.nil?
38
- @outlines << ' [skipped]'
44
+ @testrunner_output << ' [skipped]'
39
45
  @test_result = 0
40
46
  else
41
47
  # Evaluate expectation
@@ -44,17 +50,22 @@ class Tryouts
44
50
 
45
51
  test_passed = test_value.eql?(exp_value)
46
52
  @test_result = test_passed ? 1 : -1
47
- @outlines << test_value.inspect
53
+ @testrunner_output << test_value.inspect
48
54
  end
49
55
  end
56
+ Tryouts.info '^^^^^^^^^^^^^^^^^^^'
57
+ $stdout = STDOUT # restore stdout
58
+
50
59
  Tryouts.debug # extra newline
51
60
  failed?
52
61
 
53
- rescue StandardException => e
62
+
63
+ rescue StandardError => e
54
64
  Tryouts.debug "[testcaste.run] #{e.message}", e.backtrace.join($/), $/
55
- $stdout = STDOUT # restore stdout
56
65
  # Continue raising the exception
57
66
  raise e
67
+ ensure
68
+ $stdout = STDOUT # restore stdout
58
69
  end
59
70
 
60
71
  def run?
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,6 +238,12 @@ 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
248
  msgs.each do |line|
230
249
  $stderr.puts Console.color :red, line
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
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-25 00:00:00.000000000 Z
11
+ date: 2024-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sysinfo
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.4.19
66
+ rubygems_version: 3.5.15
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Ruby tests that read like documentation.