tryouts 2.2.0.pre.RC1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tryouts.rb +55 -58
  3. metadata +11 -12
  4. data/README.rdoc +0 -123
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbbfffa0cddd9a7e3e7515a9d48a4574041f9c98c5896d5abba268f8583b3efc
4
- data.tar.gz: ad85207912aeb782ea679c4298c1beeac8837ef1e42e9ecefc51a5fda832ca25
3
+ metadata.gz: 64a4341b114113a2302709a5d550682346092cc677c7dbc5933c6d7a3e139fa6
4
+ data.tar.gz: 7e1f1e8fed19debc6e2b7766e76510c7904c1b565ae6c841571a0c005fbc755f
5
5
  SHA512:
6
- metadata.gz: f0b5b32c5ec3c48f0cde12963cfdefc7202284c13b464b11d4fbd2cbc24f928e8147471a653d7f345bcdad509fec94a458c2a007362236c1970c4f304766f405
7
- data.tar.gz: 96a95e649151dd3b815bd8993e9ea2ad2133616a968a6254a5e4930b7ebe39acebff3b8d086b009bf8755b6872198f516a8f2a7f352a023b892e2d3622c8fe9e
6
+ metadata.gz: 0d6cb90fb7b6e14cbbff68fd5aa5f0d46e93453490a088cdd613cbaf5f10522409a784015fbe5215fcc27c730003a7d3f380df3c303d8f7f6e0293522ae2df45
7
+ data.tar.gz: 68f3f1202acf7f7e661435372bf4470462ff254cf2f25dd76902e4a01817d46a40a06e54e8b2a59acfb49c59520682234e19527a6745af0370d45c4cd675e278
data/lib/tryouts.rb CHANGED
@@ -1,9 +1,7 @@
1
- #require 'pathname'
2
- #p Pathname(caller.last.split(':').first)
3
1
  require 'ostruct'
4
2
 
5
3
  unless defined?(TRYOUTS_LIB_HOME)
6
- TRYOUTS_LIB_HOME = File.expand_path File.dirname(__FILE__)
4
+ TRYOUTS_LIB_HOME = File.expand_path File.dirname(__FILE__)
7
5
  end
8
6
 
9
7
  class Tryouts
@@ -31,42 +29,42 @@ class Tryouts
31
29
  class << self
32
30
  attr_accessor :debug, :container, :quiet, :noisy
33
31
  attr_reader :cases
34
-
32
+
35
33
  def sysinfo
36
34
  require 'sysinfo'
37
35
  @sysinfo ||= SysInfo.new
38
36
  @sysinfo
39
37
  end
40
-
38
+
41
39
  def debug?() @debug == true end
42
-
40
+
43
41
  def run_all *paths
44
42
  batches = paths.collect do |path|
45
43
  parse path
46
44
  end
47
-
45
+
48
46
  all, skipped_tests, failed_tests = 0, 0, 0
49
47
  skipped_batches, failed_batches = 0, 0
50
-
48
+
51
49
  msg 'Ruby %s @ %-40s' % [RUBY_VERSION, Time.now], $/
52
-
50
+
53
51
  batches.each do |batch|
54
-
52
+
55
53
  path = batch.path.gsub(/#{Dir.pwd}\/?/, '')
56
-
54
+
57
55
  vmsg '%-60s %s' % [path, '']
58
-
56
+
59
57
  before_handler = Proc.new do |t|
60
58
  if Tryouts.noisy
61
- vmsg Console.reverse(' %-58s ' % [t.desc.to_s])
59
+ vmsg Console.reverse(' %-58s ' % [t.desc.to_s])
62
60
  vmsg t.test.inspect, t.exps.inspect
63
61
  end
64
62
  end
65
-
63
+
66
64
  batch.run(before_handler) do |t|
67
- if t.failed?
65
+ if t.failed?
68
66
  failed_tests += 1
69
- if Tryouts.noisy
67
+ if Tryouts.noisy
70
68
  vmsg Console.color(:red, t.failed.join($/)), $/
71
69
  else
72
70
  msg ' %s (%s:%s)' % [Console.color(:red, "FAIL"), path, t.exps.first]
@@ -88,7 +86,7 @@ class Tryouts
88
86
  all += 1
89
87
  end
90
88
  end
91
-
89
+
92
90
  msg
93
91
  if all > 0
94
92
  suffix = 'tests passed'
@@ -100,22 +98,22 @@ class Tryouts
100
98
  suffix = "batches passed"
101
99
  suffix << " (and #{skipped_batches} skipped)" if skipped_batches > 0
102
100
  msg cformat(batches.size-skipped_batches-failed_batches, batches.size-skipped_batches, suffix)
103
- end
101
+ end
104
102
  end
105
-
103
+
106
104
  failed_tests # 0 means success
107
105
  end
108
-
106
+
109
107
  def cformat(*args)
110
108
  Console.bright '%d of %d %s' % args
111
109
  end
112
-
110
+
113
111
  def run path
114
112
  batch = parse path
115
113
  batch.run
116
114
  batch
117
115
  end
118
-
116
+
119
117
  def parse path
120
118
  #debug "Loading #{path}"
121
119
  lines = File.readlines path
@@ -139,17 +137,17 @@ class Tryouts
139
137
  end
140
138
  exps.last += 1
141
139
  end
142
-
140
+
143
141
  offset = 0
144
142
  buffer, desc = Section.new(path), Section.new(path)
145
- test = Section.new(path, idx) # test start the line before the exp.
143
+ test = Section.new(path, idx) # test start the line before the exp.
146
144
  blank_buffer = Section.new(path)
147
145
  while (idx-offset >= 0)
148
146
  offset += 1
149
147
  this_line = lines[idx-offset].chomp
150
148
  buffer.unshift this_line if ignore?(this_line)
151
149
  if comment?(this_line)
152
- buffer.unshift this_line
150
+ buffer.unshift this_line
153
151
  end
154
152
  if test?(this_line)
155
153
  test.unshift(*buffer) && buffer.clear
@@ -167,47 +165,47 @@ class Tryouts
167
165
  desc.unshift *buffer
168
166
  desc.last = test.first-1
169
167
  desc.first = desc.last-desc.size+1
170
- # remove empty lines between the description
168
+ # remove empty lines between the description
171
169
  # and the previous expectation
172
- while !desc.empty? && desc[0].empty?
170
+ while !desc.empty? && desc[0].empty?
173
171
  desc.shift
174
172
  desc.first += 1
175
173
  end
176
- break
174
+ break
177
175
  end
178
176
  end
179
-
177
+
180
178
  batch << TestCase.new(desc, test, exps)
181
179
  end
182
180
  end
183
-
181
+
184
182
  batch
185
183
  end
186
-
184
+
187
185
  def print str
188
186
  return if Tryouts.quiet
189
187
  STDOUT.print str
190
188
  STDOUT.flush
191
189
  end
192
-
190
+
193
191
  def vmsg *msg
194
192
  STDOUT.puts *msg if !Tryouts.quiet && Tryouts.noisy
195
193
  end
196
-
194
+
197
195
  def msg *msg
198
196
  STDOUT.puts *msg unless Tryouts.quiet
199
197
  end
200
-
198
+
201
199
  def err *msg
202
200
  msg.each do |line|
203
201
  STDERR.puts Console.color :red, line
204
202
  end
205
203
  end
206
-
204
+
207
205
  def debug *msg
208
206
  STDERR.puts *msg if @debug
209
207
  end
210
-
208
+
211
209
  def eval(str, path, line)
212
210
  begin
213
211
  Kernel.eval str, @container.send(:binding), path, line
@@ -217,34 +215,34 @@ class Tryouts
217
215
  nil
218
216
  end
219
217
  end
220
-
218
+
221
219
  private
222
-
220
+
223
221
  def expectation? str
224
222
  !ignore?(str) && str.strip.match(/\A\#+\s*=>/)
225
223
  end
226
-
224
+
227
225
  def comment? str
228
226
  !str.strip.match(/^\#+/).nil? && !expectation?(str)
229
227
  end
230
-
228
+
231
229
  def test? str
232
230
  !ignore?(str) && !expectation?(str) && !comment?(str)
233
231
  end
234
-
232
+
235
233
  def ignore? str
236
234
  str.to_s.strip.chomp.empty?
237
235
  end
238
-
236
+
239
237
  def test_begin? str
240
238
  ret = !str.strip.match(/\#+\s*TEST/i).nil? ||
241
239
  !str.strip.match(/\A\#\#+[\s\w]+/i).nil?
242
240
  ret
243
241
  end
244
242
 
245
-
243
+
246
244
  end
247
-
245
+
248
246
  class TestBatch < Array
249
247
  class Container
250
248
  def metaclass
@@ -262,12 +260,12 @@ class Tryouts
262
260
  def run(before_test, &after_test)
263
261
  return if empty?
264
262
  setup
265
- ret = self.select { |tc|
263
+ ret = self.select { |tc|
266
264
  before_test.call(tc) unless before_test.nil?
267
- ret = !tc.run
265
+ ret = !tc.run
268
266
  after_test.call(tc)
269
267
  ret # select failed tests
270
- }
268
+ }
271
269
  @failed = ret.size
272
270
  @run = true
273
271
  clean
@@ -306,27 +304,27 @@ class Tryouts
306
304
  def run
307
305
  Tryouts.debug '%s:%d' % [@test.path, @test.first]
308
306
  Tryouts.debug inspect, $/
309
- expectations = exps.collect { |exp,idx|
307
+ expectations = exps.collect { |exp,idx|
310
308
  exp =~ /\A\#?\s*=>\s*(.+)\Z/
311
309
  $1 # this will be nil if the expectation is commented out
312
310
  }
313
-
311
+
314
312
  # Evaluate test block only if there are valid expectations
315
313
  unless expectations.compact.empty?
316
314
  test_value = Tryouts.eval @test.to_s, @test.path, @test.first
317
315
  @has_run = true
318
316
  end
319
-
317
+
320
318
  @passed, @failed, @skipped = [], [], []
321
- expectations.each_with_index { |exp,idx|
319
+ expectations.each_with_index { |exp,idx|
322
320
  if exp.nil?
323
321
  @skipped << ' [skipped]'
324
322
  else
325
323
  exp_value = Tryouts.eval(exp, @exps.path, @exps.first+idx)
326
324
  if test_value == exp_value
327
- @passed << ' == %s' % [test_value.inspect]
325
+ @passed << ' == %s' % [test_value.inspect]
328
326
  else
329
- @failed << ' != %s' % [test_value.inspect]
327
+ @failed << ' != %s' % [test_value.inspect]
330
328
  end
331
329
  end
332
330
  }
@@ -366,9 +364,9 @@ class Tryouts
366
364
  end
367
365
  end
368
366
 
369
-
367
+
370
368
  module Console
371
-
369
+
372
370
  # ANSI escape sequence numbers for text attributes
373
371
  ATTRIBUTES = {
374
372
  :normal => 0,
@@ -408,7 +406,7 @@ class Tryouts
408
406
  :default => 49,
409
407
  :random => 40 + rand(10).to_i
410
408
  }.freeze unless defined? BGCOLOURS
411
-
409
+
412
410
  module InstanceMethods
413
411
  def bright
414
412
  Console.bright(self)
@@ -426,7 +424,7 @@ class Tryouts
426
424
  Console.bgcolor(col, self)
427
425
  end
428
426
  end
429
-
427
+
430
428
  def self.bright(str)
431
429
  str = [style(ATTRIBUTES[:bright]), str, default_style].join
432
430
  str.extend Console::InstanceMethods
@@ -463,4 +461,3 @@ class Tryouts
463
461
  end
464
462
 
465
463
  end
466
-
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0.pre.RC1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-03 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sysinfo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.0.pre.RC1
19
+ version: '0.10'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.0.pre.RC1
27
- description: Don't waste your time writing tests
26
+ version: '0.10'
27
+ description: 'Tryouts: Don''t waste your time writing tests'
28
28
  email: delano@solutious.com
29
29
  executables:
30
30
  - try
@@ -32,7 +32,6 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - LICENSE.txt
35
- - README.rdoc
36
35
  - Rakefile
37
36
  - bin/try
38
37
  - lib/tryouts.rb
@@ -48,14 +47,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
47
  requirements:
49
48
  - - ">="
50
49
  - !ruby/object:Gem::Version
51
- version: '3.1'
50
+ version: 2.6.8
52
51
  required_rubygems_version: !ruby/object:Gem::Requirement
53
52
  requirements:
54
- - - ">"
53
+ - - ">="
55
54
  - !ruby/object:Gem::Version
56
- version: 1.3.1
55
+ version: '0'
57
56
  requirements: []
58
- rubygems_version: 3.3.26
57
+ rubygems_version: 3.5.7
59
58
  signing_key:
60
59
  specification_version: 4
61
60
  summary: Don't waste your time writing tests
data/README.rdoc DELETED
@@ -1,123 +0,0 @@
1
- = Tryouts v2.0 ALPHA
2
-
3
- <i>Don't waste your time writing tests.</i>
4
-
5
- <b>NOTE: Tryouts syntax changed since 0.x. The old version is still available in the 0.8-FINAL branch.</b>
6
-
7
- Check out the screencast[http://www.rubypulse.com/episode-0.46_tryouts.html] created by Alex Peuchert.
8
-
9
-
10
- == Basic syntax
11
-
12
- ## A very simple test
13
- 1 + 1
14
- #=> 2
15
-
16
- ## The test description can spread
17
- ## across multiple lines. The same
18
- ## is true for test definitions.
19
- a = 'foo'
20
- b = 'bar'
21
- a + b
22
- #=> 'foobar'
23
-
24
- ## A test will pass when its return
25
- ## value equals the expectation.
26
- 'foo'.class
27
- #=> String
28
-
29
- ## The expectations are evaluated.
30
- 1 + 1
31
- #=> 1 + 1
32
-
33
- ## Here's an example of testing errors
34
- begin
35
- raise RuntimeError
36
- rescue RuntimeError
37
- :success
38
- end
39
- #=> :success
40
-
41
- For real world examples, see the Gibbler[http://github.com/delano/gibbler/tree/master/try/] tryouts.
42
-
43
- == Setup / Cleanup
44
-
45
- All code before the first test definition is assumed to be setup code. All code after the last definition is assumed to be cleanup code. Here is an example:
46
-
47
-
48
- # This is called before all tests
49
- require 'gibbler'
50
- Gibbler.digest_type = Digest::SHA256
51
-
52
- ## A Symbol can gibbler
53
- :anything.gibbler
54
- #=> '754f87ca720ec256633a286d9270d68478850b2abd7b0ae65021cb769ae70c08'
55
-
56
- # This will be called after all tests
57
- Gibbler.digest_type = Digest::SHA1
58
-
59
-
60
- == Running Tests
61
-
62
- Try ships with a command-line tool called <tt>try</tt>. When called with no arguments, it will look for files ending with _try.rb in the current directory, or in the subfolder try.
63
-
64
- You can also supply a specific file to test.
65
-
66
- $ try path/2/test.rb
67
- Ruby 1.9.1 @ 2011-01-06 12:38:29 -0500
68
-
69
- # TEST 1: test matches result with expectation
70
- 7 a = 1 + 1
71
- 8 #=> 2
72
- == 2
73
- ...
74
-
75
- ## TEST 12: comments, tests, and expectations can
76
- ## contain multiple lines
77
- 13 a = 1
78
- 14 b = 2
79
- 15 a + b
80
- 16 # => 3
81
- 17 # => 2 + 1
82
- == 3
83
- == 3
84
-
85
- 12 of 12 tests passed (and 5 skipped)
86
-
87
-
88
- If all tests pass, try exits with a 0. Otherwise it exits with the number of tests that failed.
89
-
90
-
91
- For reduced output, use the `-q` option:
92
-
93
- $ try -q
94
- Ruby 1.9.1 @ 2011-01-06 12:38:29 -0500
95
-
96
- 42 of 42 tests passed (and 5 skipped)
97
- 4 of 4 batches passed
98
-
99
-
100
- == Installation
101
-
102
- One of:
103
-
104
- $ gem install tryouts
105
-
106
-
107
-
108
- == Credits
109
-
110
- * delano[http://github.com/delano]
111
-
112
- With help from:
113
-
114
- * cloudhead[http://github.com/cloudhead]
115
- * mynyml[http://github.com/mynyml]
116
-
117
- == Thanks
118
-
119
- * Syntenic[http://syntenic.com/] for the hackfest venue.
120
- * AlexPeuchert[http://www.rubypulse.com/] for the screencast.
121
- * Christian Michon for suggesting a better default output format.
122
-
123
- <i>This collision was brought to you by Montreal.rb.</i>