corn 0.0.8 → 0.0.9
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/lib/corn.rb +6 -2
- data/lib/corn/mini_test.rb +7 -8
- data/lib/corn/report.rb +42 -27
- data/lib/corn/test_unit.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 885902f5a77dd01b2e1ad5d50bd2466359f9390a
|
4
|
+
data.tar.gz: 812a743f03f5cce869e4bb8f47edb5ebb290c4d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 201f2d5083ba0bb47d553bd879b6d2834878fd5e4087c7eaac1d6571e6ad51df78b53de93c8a61c4de2311f75c1f7a4f1c37818ade0c1d22d0a3f407eb0c9197
|
7
|
+
data.tar.gz: e76a9cf28cf57458ee7e93bd8f72aa6d292983a3780c8beb3641e692ca5c5a646a4347594c72ad61603df48c6f0467004467eca22e086a084a636967d5775fa4
|
data/lib/corn.rb
CHANGED
@@ -39,9 +39,13 @@ module Corn
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def report(label, &block)
|
42
|
+
def report(label=nil, &block)
|
43
43
|
@report ||= Report.new
|
44
|
-
|
44
|
+
if label
|
45
|
+
@report.record(label, &block)
|
46
|
+
else
|
47
|
+
@report
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
def submit
|
data/lib/corn/mini_test.rb
CHANGED
@@ -7,28 +7,27 @@ module Corn
|
|
7
7
|
|
8
8
|
def run_with_corn(runner, &block)
|
9
9
|
label = "#{self.class.name}.#{__name__}"
|
10
|
-
Corn.report(label) do
|
11
|
-
@corn_report = report
|
10
|
+
Corn.report(label) do
|
12
11
|
run_without_corn(runner, &block)
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
15
|
def before_setup
|
17
|
-
|
16
|
+
Corn.report.record_start(:setup)
|
18
17
|
end
|
19
18
|
|
20
19
|
def after_setup
|
21
|
-
|
22
|
-
|
20
|
+
Corn.report.record_end
|
21
|
+
Corn.report.record_start(:run_test)
|
23
22
|
end
|
24
23
|
|
25
24
|
def before_teardown
|
26
|
-
|
27
|
-
|
25
|
+
Corn.report.record_end
|
26
|
+
Corn.report.record_start(:teardown)
|
28
27
|
end
|
29
28
|
|
30
29
|
def after_teardown
|
31
|
-
|
30
|
+
Corn.report.record_end
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
data/lib/corn/report.rb
CHANGED
@@ -3,64 +3,79 @@ require 'csv'
|
|
3
3
|
module Corn
|
4
4
|
class Report
|
5
5
|
|
6
|
+
class RecordNotStartError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
class Record
|
10
|
+
attr_reader :data
|
11
|
+
|
12
|
+
def initialize(label, parent=nil)
|
13
|
+
@label = label
|
14
|
+
@parent = parent
|
15
|
+
@data = []
|
16
|
+
@start = Time.now
|
17
|
+
end
|
18
|
+
|
19
|
+
def push(label)
|
20
|
+
Record.new(label, self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def pop
|
24
|
+
return if @parent.nil?
|
25
|
+
@parent.record(@label, @start, Time.now - @start)
|
26
|
+
@data.each { |d| @parent.record(*d) }
|
27
|
+
@parent
|
28
|
+
end
|
29
|
+
|
30
|
+
def record(label, start, time)
|
31
|
+
@data << [record_label(label), start, time]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def record_label(label)
|
36
|
+
[@label, label].compact.join('.').to_sym
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
6
40
|
def initialize(prefix=nil)
|
7
|
-
@
|
8
|
-
@records = []
|
41
|
+
@record = Record.new(prefix, nil)
|
9
42
|
end
|
10
43
|
|
11
44
|
def record(label, &block)
|
12
45
|
record_start(label)
|
13
|
-
yield
|
46
|
+
yield
|
14
47
|
ensure
|
15
48
|
record_end
|
16
49
|
end
|
17
50
|
|
18
|
-
# start record a benchmark time by label
|
19
51
|
def record_start(label)
|
20
|
-
@record =
|
52
|
+
@record = @record.push(label)
|
21
53
|
end
|
22
54
|
|
23
|
-
# should only be called between record_start and record_end to generate
|
24
|
-
# sub report for current report
|
25
|
-
def sub_report
|
26
|
-
@sub_report ||= Report.new(@record[0])
|
27
|
-
end
|
28
|
-
|
29
|
-
# should only be called after record_start
|
30
55
|
def record_end
|
31
|
-
@record
|
32
|
-
@records << @record
|
33
|
-
if @sub_report
|
34
|
-
@records.concat @sub_report.to_a
|
35
|
-
@sub_report = nil
|
36
|
-
end
|
56
|
+
@record = @record.pop || raise(RecordNotStartError)
|
37
57
|
end
|
38
58
|
|
39
59
|
def empty?
|
40
|
-
|
60
|
+
to_a.empty?
|
41
61
|
end
|
42
62
|
|
43
63
|
def to_a
|
44
|
-
@
|
64
|
+
@record.data
|
45
65
|
end
|
46
66
|
|
47
67
|
def to_csv
|
48
68
|
if RUBY_VERSION =~ /1.8/
|
49
69
|
buf = ''
|
50
|
-
|
70
|
+
self.to_a.each do |r|
|
51
71
|
CSV.generate_row(r, r.size, buf)
|
52
72
|
end
|
53
73
|
buf
|
54
74
|
else
|
55
75
|
CSV.generate do |csv|
|
56
|
-
|
76
|
+
self.to_a.each { |r| csv << r }
|
57
77
|
end
|
58
78
|
end
|
59
79
|
end
|
60
|
-
|
61
|
-
private
|
62
|
-
def record_label(label)
|
63
|
-
[@prefix, label].compact.join('.').to_sym
|
64
|
-
end
|
65
80
|
end
|
66
81
|
end
|
data/lib/corn/test_unit.rb
CHANGED
@@ -9,17 +9,17 @@ module Corn
|
|
9
9
|
|
10
10
|
def run_with_corn(result, &block)
|
11
11
|
label = "#{self.class.name}.#{@method_name}"
|
12
|
-
Corn.report(label) do
|
13
|
-
__run_with_corn__(
|
12
|
+
Corn.report(label) do
|
13
|
+
__run_with_corn__(result, &block)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def __run_with_corn__(
|
17
|
+
def __run_with_corn__(result, &block)
|
18
18
|
yield(Test::Unit::TestCase::STARTED, name)
|
19
19
|
@_result = result
|
20
20
|
begin
|
21
|
-
report
|
22
|
-
report
|
21
|
+
Corn.report(:setup) { setup }
|
22
|
+
Corn.report(:run_test) { __send__(@method_name) }
|
23
23
|
rescue AssertionFailedError => e
|
24
24
|
add_failure(e.message, e.backtrace)
|
25
25
|
rescue Exception
|
@@ -27,7 +27,7 @@ module Corn
|
|
27
27
|
add_error($!)
|
28
28
|
ensure
|
29
29
|
begin
|
30
|
-
report
|
30
|
+
Corn.report(:teardown) { teardown }
|
31
31
|
rescue AssertionFailedError => e
|
32
32
|
add_failure(e.message, e.backtrace)
|
33
33
|
rescue Exception
|