pork 1.2.3 → 1.2.4
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 +4 -4
- data/CHANGES.md +11 -0
- data/README.md +24 -0
- data/Rakefile +1 -1
- data/lib/pork.rb +5 -0
- data/lib/pork/extra/show_source.rb +33 -0
- data/lib/pork/imp.rb +2 -2
- data/lib/pork/mode/parallel.rb +1 -1
- data/lib/pork/more/bottomup_backtrace.rb +1 -1
- data/lib/pork/more/color.rb +6 -2
- data/lib/pork/more/should.rb +2 -0
- data/lib/pork/stat.rb +31 -9
- data/lib/pork/test.rb +1 -0
- data/lib/pork/version.rb +1 -1
- data/pork.gemspec +11 -8
- data/test/test_nested.rb +1 -1
- data/test/test_stat.rb +88 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d777bebd67882252ec22825a62266878e8afb245
|
4
|
+
data.tar.gz: 5b59151244bdf671ca2c239b9eb503dd43eb04a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7345227bf8de435f9673db212c5d255dfd4ec2f11f73caa5cd9b2154d99491fe3e159c7d293e3e3b7c42d1696c935dab8c0279ccea4211e26b9a081d6763531a
|
7
|
+
data.tar.gz: 11175993f303c48a9984e0f967bb713b1a28c17c214badc2dc73cb98e1f8eada9d2a6ecdb14fc923121b9f01253b18da2cdf286c58c7fbbcba7701a3598af37d
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Pork 1.2.4 -- 2015-04-25
|
4
|
+
|
5
|
+
### Enhancement
|
6
|
+
|
7
|
+
* Introduced `Pork.show_source` to print the source of failing tests. Using
|
8
|
+
this feature requires `method_source` installed.
|
9
|
+
|
10
|
+
### Bugs fixed
|
11
|
+
|
12
|
+
* Fixed a potential data race in parallel tests using `should`.
|
13
|
+
|
3
14
|
## Pork 1.2.3 -- 2015-04-16
|
4
15
|
|
5
16
|
### Enhancement
|
data/README.md
CHANGED
@@ -148,6 +148,10 @@ end
|
|
148
148
|
## REQUIREMENTS:
|
149
149
|
|
150
150
|
* Tested with MRI (official CRuby), Rubinius and JRuby.
|
151
|
+
* (Optional) [method_source][] if you would like to print the source for the
|
152
|
+
failing tests.
|
153
|
+
|
154
|
+
[method_source]: https://github.com/banister/method_source
|
151
155
|
|
152
156
|
## INSTALLATION:
|
153
157
|
|
@@ -931,6 +935,25 @@ Pork.autorun(true) # enable
|
|
931
935
|
|
932
936
|
`require 'pork/auto'` would call `Pork.autorun`
|
933
937
|
|
938
|
+
### Pork.show_source
|
939
|
+
|
940
|
+
If you have [method_source][] installed, you could call this and have Pork
|
941
|
+
print the source to the failing lines. Here's an example of what Pork would
|
942
|
+
print with `Pork.show_source`:
|
943
|
+
|
944
|
+
```
|
945
|
+
Replicate this test with:
|
946
|
+
env PORK_TEST='test/test_pork.rb:12' PORK_MODE=shuffled PORK_SEED=345 /usr/bin/ruby -S test/test_pork.rb
|
947
|
+
test/test_pork.rb:13:in `block in <main>'
|
948
|
+
would 'print the source' do
|
949
|
+
=> flunk
|
950
|
+
end
|
951
|
+
would print the source
|
952
|
+
Pork::Error: Flunked
|
953
|
+
```
|
954
|
+
|
955
|
+
[method_source]: https://github.com/banister/method_source
|
956
|
+
|
934
957
|
### Pork.Rainbows!
|
935
958
|
|
936
959
|
Have you seen Rainbows!?
|
@@ -940,6 +963,7 @@ Have you seen Rainbows!?
|
|
940
963
|
* Chun-Yi Liu (@trantorliu)
|
941
964
|
* Lin Jen-Shin (@godfat)
|
942
965
|
* Josh Kalderimis (@joshk)
|
966
|
+
* Yang-Hsing Lin (@mz026)
|
943
967
|
|
944
968
|
## LICENSE:
|
945
969
|
|
data/Rakefile
CHANGED
data/lib/pork.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require 'method_source'
|
3
|
+
|
4
|
+
module Pork
|
5
|
+
module ShowSource
|
6
|
+
def show_source test, err
|
7
|
+
source = test.source
|
8
|
+
sopath = "#{test.source_location.first}:"
|
9
|
+
lowers = test.source_location.last
|
10
|
+
uppers = lowers + source.size
|
11
|
+
lineno = reject_pork(test, err).find do |backtrace|
|
12
|
+
# find the line from the test source, exclude everything else
|
13
|
+
next unless backtrace.start_with?(sopath)
|
14
|
+
number = backtrace[/(?<=\.rb:)\d+/].to_i
|
15
|
+
break number if number >= lowers && number < uppers
|
16
|
+
end
|
17
|
+
return '' unless lineno # TODO: error might be coming from before block
|
18
|
+
lowerl = lineno - lowers
|
19
|
+
upperl = MethodSource.expression_at(source, lowerl + 1).
|
20
|
+
count("\n") + lowerl
|
21
|
+
indent = source[/^\s*/].size
|
22
|
+
result = source.each_line.with_index.map do |source_line, index|
|
23
|
+
line = source_line[indent..-1] || "\n"
|
24
|
+
if index >= lowerl && index < upperl
|
25
|
+
highlight_line(" => #{line}")
|
26
|
+
else
|
27
|
+
backlight_line(" #{line}")
|
28
|
+
end
|
29
|
+
end.join
|
30
|
+
"\n#{result.chomp}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/pork/imp.rb
CHANGED
@@ -25,7 +25,7 @@ module Pork
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def would desc=:default, opts={}, &test
|
28
|
-
@tests << [:would, desc, test, opts]
|
28
|
+
@tests << [:would, desc, test || lambda{}, opts]
|
29
29
|
end
|
30
30
|
|
31
31
|
def execute mode, *args
|
@@ -67,7 +67,7 @@ module Pork
|
|
67
67
|
stat.incr_skips
|
68
68
|
stat.case_skip
|
69
69
|
else
|
70
|
-
err = [e, description_for("would #{desc}"), test
|
70
|
+
err = [e, description_for("would #{desc}"), test]
|
71
71
|
case e
|
72
72
|
when Failure
|
73
73
|
stat.add_failure(err)
|
data/lib/pork/mode/parallel.rb
CHANGED
@@ -10,7 +10,7 @@ module Pork
|
|
10
10
|
def parallel stat=Stat.new, paths=all_paths
|
11
11
|
paths.shuffle.each_slice(cores).map do |paths_slice|
|
12
12
|
Thread.new do
|
13
|
-
execute(:shuffled, Stat.new, paths_slice)
|
13
|
+
execute(:shuffled, Stat.new(stat.io), paths_slice)
|
14
14
|
end
|
15
15
|
end.map(&:value).inject(stat, &:merge)
|
16
16
|
end
|
data/lib/pork/more/color.rb
CHANGED
@@ -12,7 +12,7 @@ module Pork
|
|
12
12
|
gray(super)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def show_message msg
|
16
16
|
blue(super)
|
17
17
|
end
|
18
18
|
|
@@ -20,6 +20,10 @@ module Pork
|
|
20
20
|
magenta(super)
|
21
21
|
end
|
22
22
|
|
23
|
+
def highlight_line line
|
24
|
+
"#{color(41, super.chomp)}\n"
|
25
|
+
end
|
26
|
+
|
23
27
|
def time_spent
|
24
28
|
cyan(super)
|
25
29
|
end
|
@@ -40,7 +44,7 @@ module Pork
|
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
def backtrace
|
47
|
+
def backtrace *_
|
44
48
|
super.map do |b|
|
45
49
|
path, msgs = b.split(':', 2)
|
46
50
|
dir , file = ::File.split(path)
|
data/lib/pork/more/should.rb
CHANGED
@@ -13,10 +13,12 @@ module Pork
|
|
13
13
|
def execute mode, stat=Stat.new, *args
|
14
14
|
thread = Thread.current
|
15
15
|
original_group, group = thread.group, ThreadGroup.new
|
16
|
+
original_stat = thread[:pork_stat]
|
16
17
|
group.add(thread)
|
17
18
|
thread[:pork_stat] = stat
|
18
19
|
super(mode, stat, *args)
|
19
20
|
ensure
|
21
|
+
thread[:pork_stat] = original_stat
|
20
22
|
original_group.add(thread)
|
21
23
|
end
|
22
24
|
end
|
data/lib/pork/stat.rb
CHANGED
@@ -55,10 +55,11 @@ module Pork
|
|
55
55
|
|
56
56
|
private
|
57
57
|
def report_exceptions
|
58
|
-
exceptions.reverse_each.map do |(err, msg,
|
59
|
-
"\n #{show_command(source_location)}"
|
60
|
-
"\n #{show_backtrace(err)}"
|
61
|
-
"
|
58
|
+
exceptions.reverse_each.map do |(err, msg, test)|
|
59
|
+
"\n #{show_command(test.source_location)}" \
|
60
|
+
"\n #{show_backtrace(test, err)}" \
|
61
|
+
"#{show_source(test, err)}" \
|
62
|
+
"\n#{show_message(msg)}" \
|
62
63
|
"\n#{show_exception(err)}"
|
63
64
|
end
|
64
65
|
end
|
@@ -71,19 +72,31 @@ module Pork
|
|
71
72
|
"#{env(source_location)} #{Gem.ruby} -S #{$0} #{ARGV.join(' ')}"
|
72
73
|
end
|
73
74
|
|
74
|
-
def show_backtrace err
|
75
|
-
backtrace(err).join("\n ")
|
75
|
+
def show_backtrace test, err
|
76
|
+
backtrace(test, err).join("\n ")
|
76
77
|
end
|
77
78
|
|
78
|
-
def backtrace err
|
79
|
+
def backtrace test, err
|
79
80
|
if $VERBOSE
|
80
81
|
err.backtrace
|
81
82
|
else
|
82
|
-
strip(
|
83
|
+
strip(reject_pork(test, err))
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
86
|
-
def
|
87
|
+
def show_source _, _
|
88
|
+
''
|
89
|
+
end
|
90
|
+
|
91
|
+
def highlight_line line
|
92
|
+
line
|
93
|
+
end
|
94
|
+
|
95
|
+
def backlight_line line
|
96
|
+
line
|
97
|
+
end
|
98
|
+
|
99
|
+
def show_message msg
|
87
100
|
msg
|
88
101
|
end
|
89
102
|
|
@@ -91,6 +104,15 @@ module Pork
|
|
91
104
|
"#{err.class}: #{err.message}"
|
92
105
|
end
|
93
106
|
|
107
|
+
def reject_pork test, err
|
108
|
+
bt = err.backtrace.reject{ |l| l =~ %r{/lib/pork(/\w+)*\.rb:\d+} }
|
109
|
+
if bt.empty?
|
110
|
+
["#{test.source_location.join(':')}:in `block in would'"]
|
111
|
+
else
|
112
|
+
bt
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
94
116
|
def strip bt
|
95
117
|
strip_home(strip_cwd(bt))
|
96
118
|
end
|
data/lib/pork/test.rb
CHANGED
data/lib/pork/version.rb
CHANGED
data/pork.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: pork 1.2.
|
2
|
+
# stub: pork 1.2.4 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "pork"
|
6
|
-
s.version = "1.2.
|
6
|
+
s.version = "1.2.4"
|
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-04-
|
11
|
+
s.date = "2015-04-25"
|
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 = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/pork/executor.rb",
|
30
30
|
"lib/pork/expect.rb",
|
31
31
|
"lib/pork/extra/rainbows.rb",
|
32
|
+
"lib/pork/extra/show_source.rb",
|
32
33
|
"lib/pork/imp.rb",
|
33
34
|
"lib/pork/inspect.rb",
|
34
35
|
"lib/pork/mode/parallel.rb",
|
@@ -49,7 +50,8 @@ Gem::Specification.new do |s|
|
|
49
50
|
"test/test_nested.rb",
|
50
51
|
"test/test_pork_test.rb",
|
51
52
|
"test/test_readme.rb",
|
52
|
-
"test/test_should.rb"
|
53
|
+
"test/test_should.rb",
|
54
|
+
"test/test_stat.rb"]
|
53
55
|
s.homepage = "https://github.com/godfat/pork"
|
54
56
|
s.licenses = ["Apache License 2.0"]
|
55
57
|
s.rubygems_version = "2.4.6"
|
@@ -60,17 +62,18 @@ Gem::Specification.new do |s|
|
|
60
62
|
"test/test_nested.rb",
|
61
63
|
"test/test_pork_test.rb",
|
62
64
|
"test/test_readme.rb",
|
63
|
-
"test/test_should.rb"
|
65
|
+
"test/test_should.rb",
|
66
|
+
"test/test_stat.rb"]
|
64
67
|
|
65
68
|
if s.respond_to? :specification_version then
|
66
69
|
s.specification_version = 4
|
67
70
|
|
68
71
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
69
|
-
s.add_development_dependency(%q<
|
72
|
+
s.add_development_dependency(%q<method_source>, [">= 0"])
|
70
73
|
else
|
71
|
-
s.add_dependency(%q<
|
74
|
+
s.add_dependency(%q<method_source>, [">= 0"])
|
72
75
|
end
|
73
76
|
else
|
74
|
-
s.add_dependency(%q<
|
77
|
+
s.add_dependency(%q<method_source>, [">= 0"])
|
75
78
|
end
|
76
79
|
end
|
data/test/test_nested.rb
CHANGED
data/test/test_stat.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
require 'pork/test'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
describe Pork::Stat do
|
6
|
+
before do
|
7
|
+
@executor = Class.new(Pork::Executor){init}
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
@stat = @executor.execute(Pork.execute_mode, Pork::Stat.new(StringIO.new))
|
12
|
+
expect_one_error
|
13
|
+
end
|
14
|
+
|
15
|
+
def expect_one_error
|
16
|
+
expect(@stat.io.string) .eq "\e[31mE\e[0m"
|
17
|
+
expect(@stat.tests) .eq 1
|
18
|
+
expect(@stat.assertions).eq 0
|
19
|
+
expect(@stat.errors) .eq 1
|
20
|
+
end
|
21
|
+
|
22
|
+
would 'always have backtrace' do
|
23
|
+
@executor.would
|
24
|
+
run
|
25
|
+
|
26
|
+
err, _, test = @stat.exceptions.first
|
27
|
+
err.set_backtrace([])
|
28
|
+
|
29
|
+
expect(@stat.send(:show_backtrace, test, err)).not.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'Pork::Stat#show_source' do
|
33
|
+
def verify source
|
34
|
+
run
|
35
|
+
err, _, test = @stat.exceptions.first
|
36
|
+
yield(err) if block_given?
|
37
|
+
expect(@stat.send(:show_source, test, err)).include?(source)
|
38
|
+
end
|
39
|
+
|
40
|
+
would 'one line' do
|
41
|
+
@executor.would{ flunk }
|
42
|
+
verify('=> @executor.would{ flunk }')
|
43
|
+
end
|
44
|
+
|
45
|
+
would 'more lines' do
|
46
|
+
@executor.would do
|
47
|
+
flunk
|
48
|
+
end
|
49
|
+
verify(<<-SOURCE.chomp)
|
50
|
+
@executor.would do
|
51
|
+
\e[41m => flunk\e[0m
|
52
|
+
end
|
53
|
+
SOURCE
|
54
|
+
end
|
55
|
+
|
56
|
+
would 'multiple lines' do
|
57
|
+
@executor.would do
|
58
|
+
raise \
|
59
|
+
'error'
|
60
|
+
end
|
61
|
+
verify(<<-SOURCE.chomp)
|
62
|
+
@executor.would do
|
63
|
+
\e[41m => raise \\\e[0m
|
64
|
+
\e[41m => 'error'\e[0m
|
65
|
+
end
|
66
|
+
SOURCE
|
67
|
+
end
|
68
|
+
|
69
|
+
would 'show the line in the test, not other methods' do
|
70
|
+
@executor.send(:define_method, :f){ flunk }
|
71
|
+
@executor.would do
|
72
|
+
f
|
73
|
+
end
|
74
|
+
verify(<<-SOURCE.chomp)
|
75
|
+
@executor.would do
|
76
|
+
\e[41m => f\e[0m
|
77
|
+
end
|
78
|
+
SOURCE
|
79
|
+
end
|
80
|
+
|
81
|
+
would 'show the line in the test, even if it is from 3rd party' do
|
82
|
+
@executor.would{ flunk }
|
83
|
+
verify("=> @executor.would{ flunk }") do |err|
|
84
|
+
err.set_backtrace(err.backtrace.unshift("bad.rb:#{__LINE__}"))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
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-04-
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: method_source
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/pork/executor.rb
|
54
54
|
- lib/pork/expect.rb
|
55
55
|
- lib/pork/extra/rainbows.rb
|
56
|
+
- lib/pork/extra/show_source.rb
|
56
57
|
- lib/pork/imp.rb
|
57
58
|
- lib/pork/inspect.rb
|
58
59
|
- lib/pork/mode/parallel.rb
|
@@ -74,6 +75,7 @@ files:
|
|
74
75
|
- test/test_pork_test.rb
|
75
76
|
- test/test_readme.rb
|
76
77
|
- test/test_should.rb
|
78
|
+
- test/test_stat.rb
|
77
79
|
homepage: https://github.com/godfat/pork
|
78
80
|
licenses:
|
79
81
|
- Apache License 2.0
|
@@ -105,3 +107,4 @@ test_files:
|
|
105
107
|
- test/test_pork_test.rb
|
106
108
|
- test/test_readme.rb
|
107
109
|
- test/test_should.rb
|
110
|
+
- test/test_stat.rb
|