pork 1.1.2 → 1.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6be40200d742b7e914299393fd153df6aa2f221
4
- data.tar.gz: 5727e914add3a14a117f3a2783f511dbf7309e49
3
+ metadata.gz: 67d12f898ed53bc341734b4a53f3571e158eed58
4
+ data.tar.gz: 5930a1821b4ec2bd8bad6d0168baf26561a2edbb
5
5
  SHA512:
6
- metadata.gz: 5334721d9e117e448255baaca63a13d1295ccbb0518b40bf436925b6dbe9dc14a2ea9884c90024b7bb4f5e565bf106243b022ea34c0b4a4cc67ab83f6abc6f0e
7
- data.tar.gz: 20d9b914a4d068d8a6fc4f5660df4ca29523873e2da69680059192775bb5db10336b455cb04db937a4fe7beabb9affa6e751ab0fd43e17b202efa4ad2d029159
6
+ metadata.gz: 2839c6e48efb8957c9abb05e83f61f0458de4e85e0db11ad5d3b0854891eadcbdfe5b665dc60182b6bf1e5d47c09e670167b4d71d1fcb808977eabc4c63bef2f
7
+ data.tar.gz: 0fc345ebec361a78a0ba7fba004194197a25f3508ce5d7f70b215a059990ef53581354dff2ce686c1c1c1b922a034bbf24160629e76a16dd514b9f7b20430a15
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGES
2
2
 
3
+ ## Pork 1.1.3 -- 2015-02-04
4
+
5
+ * Fixed exit status.
6
+ * Introduced `require 'pork/more'` for colored output and bottom-up backtrace.
7
+ * Introduced `Pork.Rainbows!` for fun.
8
+
3
9
  ## Pork 1.1.2 -- 2015-01-28
4
10
 
5
11
  * Really fixed passing `ENV['PORK_MODE']=execute`. I should sleep now.
data/README.md CHANGED
@@ -284,6 +284,7 @@ Here's what `require 'pork/auto'` would do:
284
284
  ``` ruby
285
285
  require 'pork'
286
286
  require 'pork/should'
287
+ require 'pork/more'
287
288
  extend Pork::API
288
289
  Pork.autorun
289
290
  ```
@@ -329,6 +330,12 @@ could re-enable it.
329
330
 
330
331
  [mutant]: https://github.com/mbj/mutant
331
332
 
333
+ Also note that there's a number of plugins would be loaded upon:
334
+
335
+ ``` ruby
336
+ require 'pork/more'
337
+ ```
338
+
332
339
  ## Where's the pork command?
333
340
 
334
341
  It's not implemented. No strong reasons. You could simply run the tests by
@@ -860,6 +867,10 @@ Pork.inspect_failure_mode :newline
860
867
 
861
868
  Then it would always use the mode we specified.
862
869
 
870
+ ### Pork.Rainbows!
871
+
872
+ Have you seen Rainbows!?
873
+
863
874
  ## CONTRIBUTORS:
864
875
 
865
876
  * Chun-Yi Liu (@trantorliu)
data/TODO.md ADDED
@@ -0,0 +1,4 @@
1
+
2
+ * remove sequential tests
3
+ * introduce configs
4
+ * plugin: color/reverse backtrace, replicating command, inspect mode
data/lib/pork.rb CHANGED
@@ -17,6 +17,11 @@ module Pork
17
17
  @execute = execute || @execute ||= :execute
18
18
  end
19
19
 
20
+ def self.Rainbows!
21
+ require 'pork/extra/rainbows'
22
+ Pork::Stat.__send__(:include, Pork::Rainbows)
23
+ end
24
+
20
25
  def self.stat
21
26
  @stat ||= Pork::Stat.new
22
27
  end
@@ -32,8 +37,8 @@ module Pork
32
37
  def self.trap sig='SIGINT'
33
38
  Signal.trap(sig) do
34
39
  stat.report
35
- puts "\nterminated by signal SIGINT"
36
- exit! 255
40
+ puts "\nterminated by signal #{sig}"
41
+ exit 255
37
42
  end
38
43
  end
39
44
 
@@ -49,7 +54,7 @@ module Pork
49
54
  end
50
55
  else
51
56
  puts "Cannot find test: #{ENV['PORK_TEST']}"
52
- exit! 254
57
+ exit 254
53
58
  end
54
59
  else
55
60
  @stat = Executor.public_send(execute_mode, stat)
@@ -67,7 +72,7 @@ module Pork
67
72
  trap
68
73
  run
69
74
  stat.report
70
- exit! stat.failures.size + stat.errors.size + ($! && 1).to_i
75
+ exit stat.failures + stat.errors + ($! && 1).to_i
71
76
  end
72
77
  end
73
78
  end
data/lib/pork/auto.rb CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'pork'
3
3
  require 'pork/should'
4
+ require 'pork/more'
4
5
  extend Pork::API
5
6
  Pork.autorun
@@ -0,0 +1,23 @@
1
+
2
+ module Pork
3
+ module Rainbows
4
+ def case_pass msg='.'
5
+ @rainbows ||= 0
6
+ io.print( color256(rainbows(@rainbows)){msg} )
7
+ @rainbows += 1
8
+ end
9
+
10
+ private
11
+ def color256 rgb
12
+ "\e[38;5;#{rgb}m#{yield}\e[0m"
13
+ end
14
+
15
+ def rainbows i
16
+ n = (i%42) / 6.0
17
+ r = Math.sin(n + 0*Math::PI/3) * 3 + 3
18
+ g = Math.sin(n + 2*Math::PI/3) * 3 + 3
19
+ b = Math.sin(n + 4*Math::PI/3) * 3 + 3
20
+ 16 + 36*r.to_i + 6*g.to_i + b.to_i
21
+ end
22
+ end
23
+ end
data/lib/pork/imp.rb CHANGED
@@ -52,7 +52,7 @@ module Pork
52
52
  if assertions == stat.assertions
53
53
  raise Error.new('Missing assertions')
54
54
  end
55
- stat.io.print '.'
55
+ stat.case_pass
56
56
  end
57
57
  ensure
58
58
  stat.incr_tests
@@ -65,13 +65,13 @@ module Pork
65
65
  case e
66
66
  when Skip
67
67
  stat.incr_skips
68
- stat.io.print 's'
68
+ stat.case_skip
69
69
  when Failure
70
70
  stat.add_failure(e, description_for("would #{desc}"))
71
- stat.io.print 'F'
71
+ stat.case_failed
72
72
  when Error, StandardError
73
73
  stat.add_error( e, description_for("would #{desc}"))
74
- stat.io.print 'E'
74
+ stat.case_errored
75
75
  end
76
76
  end
77
77
 
data/lib/pork/more.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+ require 'pork/stat'
3
+
4
+ require 'pork/more/bottomup_backtrace'
5
+ require 'pork/more/color'
6
+
7
+ Pork::Stat.__send__(:include, Pork::BottomupBacktrace)
8
+ Pork::Stat.__send__(:include, Pork::Color)
@@ -0,0 +1,9 @@
1
+
2
+ module Pork
3
+ module BottomupBacktrace
4
+ private
5
+ def backtrace err
6
+ super.reverse
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,59 @@
1
+
2
+ module Pork
3
+ module Color
4
+ def case_skip msg='s'; super(yellow {msg}); end
5
+ def case_failed msg='F'; super(magenta{msg}); end
6
+ def case_errored msg='E'; super(red {msg}); end
7
+
8
+ private
9
+ def command name
10
+ gray{super}
11
+ end
12
+
13
+ def message msg
14
+ blue{super}
15
+ end
16
+
17
+ def show_exception err
18
+ magenta{super}
19
+ end
20
+
21
+ def time_spent
22
+ cyan{super}
23
+ end
24
+
25
+ def numbers
26
+ super.zip(%w[green green magenta red yellow]).map do |(num, col)|
27
+ if num == 0
28
+ num
29
+ else
30
+ send(col){ num }
31
+ end
32
+ end
33
+ end
34
+
35
+ def backtrace err
36
+ super.map do |b|
37
+ path, msgs = b.split(':', 2)
38
+ dir , file = ::File.split(path)
39
+ msg = msgs.sub(/(\d+):/){red{$1}+':'}.sub(/`.+?'/){green{$&}}
40
+
41
+ "#{dir+'/'}#{yellow{file}}:#{msg}"
42
+ end
43
+ end
44
+
45
+ def gray █ color('1;30', &block); end
46
+ def black █ color( 30 , &block); end
47
+ def red █ color( 31 , &block); end
48
+ def green █ color( 32 , &block); end
49
+ def yellow █ color( 33 , &block); end
50
+ def blue █ color( 34 , &block); end
51
+ def magenta █ color( 35 , &block); end
52
+ def cyan █ color( 36 , &block); end
53
+ def white █ color( 37 , &block); end
54
+
55
+ def color rgb
56
+ "\e[#{rgb}m#{yield}\e[0m"
57
+ end
58
+ end
59
+ end
data/lib/pork/stat.rb CHANGED
@@ -2,26 +2,42 @@
2
2
  require 'thread'
3
3
 
4
4
  module Pork
5
- class Stat < Struct.new(:io, :start, :mutex,
6
- :tests, :assertions, :skips, :failures, :errors)
5
+ Stat = Struct.new(:io, :start, :mutex,
6
+ :tests, :assertions, :skips, :failures, :errors,
7
+ :exceptions)
8
+
9
+ Stat::Imp = Module.new do
7
10
  def initialize io=$stdout, st=Time.now, mu=Mutex.new,
8
- t=0, a=0, s=0, f=[], e=[]
11
+ t=0, a=0, s=0, f=0, e=0, x=[]
9
12
  super
10
13
  end
11
14
  def incr_assertions; mutex.synchronize{ self.assertions += 1 }; end
12
15
  def incr_tests ; mutex.synchronize{ self.tests += 1 }; end
13
16
  def incr_skips ; mutex.synchronize{ self.skips += 1 }; end
14
- def add_failure *e ; mutex.synchronize{ failures << e }; end
15
- def add_error *e ; mutex.synchronize{ errors << e }; end
16
- def passed?; failures.size + errors.size == 0 ; end
17
- def numbers; [tests, assertions, failures.size, errors.size, skips]; end
17
+ def add_failure *err
18
+ mutex.synchronize do
19
+ self.failures += 1
20
+ exceptions << err
21
+ end
22
+ end
23
+ def add_error *err
24
+ mutex.synchronize do
25
+ self.errors += 1
26
+ exceptions << err
27
+ end
28
+ end
29
+ def case_pass msg='.'; io.print msg; end
30
+ def case_skip msg='s'; io.print msg; end
31
+ def case_failed msg='F'; io.print msg; end
32
+ def case_errored msg='E'; io.print msg; end
33
+ def passed?; exceptions.size == 0 ; end
34
+ def numbers; [tests, assertions, failures, errors, skips]; end
35
+ def time_spent; Time.now - start; end
18
36
  def report
19
37
  io.puts
20
- io.puts (failures + errors).map{ |(e, m)|
21
- "\n#{m}\n#{e.class}: #{e.message}\n #{backtrace(e)}\n#{command(m)}"
22
- }
23
- io.printf("\nFinished in %f seconds.\n", Time.now - start)
24
- io.printf("%d tests, %d assertions, %d failures, %d errors, %d skips\n",
38
+ io.puts report_exceptions
39
+ io.printf("\nFinished in %s seconds.\n", time_spent)
40
+ io.printf("%s tests, %s assertions, %s failures, %s errors, %s skips\n",
25
41
  *numbers)
26
42
  end
27
43
  def merge stat
@@ -30,29 +46,53 @@ module Pork
30
46
  end
31
47
 
32
48
  private
33
- def backtrace e
49
+ def report_exceptions
50
+ exceptions.reverse.map do |(err, msg)|
51
+ "\n #{show_command(msg)}" \
52
+ "\n #{show_backtrace(err)}" \
53
+ "\n#{message(msg)}" \
54
+ "\n#{show_exception(err)}"
55
+ end
56
+ end
57
+
58
+ def show_command name
59
+ "Replicate this test with:\n#{command(name)}"
60
+ end
61
+
62
+ def command name
63
+ "#{env(name)} #{Gem.ruby} -S #{$0} #{ARGV.join(' ')}"
64
+ end
65
+
66
+ def show_backtrace err
67
+ backtrace(err).join("\n ")
68
+ end
69
+
70
+ def backtrace err
34
71
  if $VERBOSE
35
- e.backtrace
72
+ err.backtrace
36
73
  else
37
- strip(e.backtrace.reject{ |line| line =~ %r{/pork(/\w+)?\.rb:\d+} })
38
- end.join("\n ")
74
+ strip(err.backtrace.reject{ |line| line =~ %r{/pork(/\w+)?\.rb:\d+} })
75
+ end
39
76
  end
40
77
 
41
- def strip backtrace
42
- strip_home(strip_cwd(backtrace))
78
+ def message msg
79
+ msg
43
80
  end
44
81
 
45
- def strip_home backtrace
46
- backtrace.map{ |path| path.sub(ENV['HOME'], '~') }
82
+ def show_exception err
83
+ "#{err.class}: #{err.message}"
47
84
  end
48
85
 
49
- def strip_cwd backtrace
50
- backtrace.map{ |path| path.sub(Dir.pwd, '.') }
86
+ def strip bt
87
+ strip_home(strip_cwd(bt))
51
88
  end
52
89
 
53
- def command name
54
- "You can replicate this test with the following command:\n " \
55
- "#{env(name)} #{Gem.ruby} -S #{$0} #{ARGV.join(' ')}"
90
+ def strip_home bt
91
+ bt.map{ |path| path.sub(ENV['HOME'], '~') }
92
+ end
93
+
94
+ def strip_cwd bt
95
+ bt.map{ |path| path.sub(Dir.pwd, '.') }
56
96
  end
57
97
 
58
98
  def env name
@@ -71,4 +111,6 @@ module Pork
71
111
  "PORK_SEED=#{Pork.seed}"
72
112
  end
73
113
  end
114
+
115
+ Stat.__send__(:include, Stat::Imp)
74
116
  end
data/lib/pork/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Pork
3
- VERSION = '1.1.2'
3
+ VERSION = '1.1.3'
4
4
  end
data/pork.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: pork 1.1.2 ruby lib
2
+ # stub: pork 1.1.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "pork"
6
- s.version = "1.1.2"
6
+ s.version = "1.1.3"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Lin Jen-Shin (godfat)"]
11
- s.date = "2015-01-28"
11
+ s.date = "2015-02-04"
12
12
  s.description = "Pork -- Simple and clean and modular testing library.\n\nInspired by [Bacon][].\n\n[Bacon]: https://github.com/chneukirchen/bacon"
13
13
  s.email = ["godfat (XD) godfat.org"]
14
14
  s.files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  "LICENSE",
21
21
  "README.md",
22
22
  "Rakefile",
23
+ "TODO.md",
23
24
  "lib/mutant/integration/pork.rb",
24
25
  "lib/pork.rb",
25
26
  "lib/pork/auto.rb",
@@ -28,11 +29,15 @@ Gem::Specification.new do |s|
28
29
  "lib/pork/error.rb",
29
30
  "lib/pork/executor.rb",
30
31
  "lib/pork/expect.rb",
32
+ "lib/pork/extra/rainbows.rb",
31
33
  "lib/pork/imp.rb",
32
34
  "lib/pork/inspect.rb",
33
35
  "lib/pork/isolate.rb",
34
36
  "lib/pork/mode/parallel.rb",
35
37
  "lib/pork/mode/shuffle.rb",
38
+ "lib/pork/more.rb",
39
+ "lib/pork/more/bottomup_backtrace.rb",
40
+ "lib/pork/more/color.rb",
36
41
  "lib/pork/should.rb",
37
42
  "lib/pork/stat.rb",
38
43
  "lib/pork/test.rb",
data/task/gemgem.rb CHANGED
@@ -102,6 +102,7 @@ module Gemgem
102
102
  if ENV['CI']
103
103
  require 'coveralls'
104
104
  SimpleCov.formatter = Coveralls::SimpleCov::Formatter
105
+ SimpleCov.command_name('pork')
105
106
  end
106
107
  SimpleCov.start do
107
108
  add_filter('test/')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pork
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-28 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: muack
@@ -44,6 +44,7 @@ files:
44
44
  - LICENSE
45
45
  - README.md
46
46
  - Rakefile
47
+ - TODO.md
47
48
  - lib/mutant/integration/pork.rb
48
49
  - lib/pork.rb
49
50
  - lib/pork/auto.rb
@@ -52,11 +53,15 @@ files:
52
53
  - lib/pork/error.rb
53
54
  - lib/pork/executor.rb
54
55
  - lib/pork/expect.rb
56
+ - lib/pork/extra/rainbows.rb
55
57
  - lib/pork/imp.rb
56
58
  - lib/pork/inspect.rb
57
59
  - lib/pork/isolate.rb
58
60
  - lib/pork/mode/parallel.rb
59
61
  - lib/pork/mode/shuffle.rb
62
+ - lib/pork/more.rb
63
+ - lib/pork/more/bottomup_backtrace.rb
64
+ - lib/pork/more/color.rb
60
65
  - lib/pork/should.rb
61
66
  - lib/pork/stat.rb
62
67
  - lib/pork/test.rb