corn 0.0.1 → 0.0.2

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
- ---
2
- SHA1:
3
- metadata.gz: 65c8f764fa897611e644e7d5ad89afeeb9a88317
4
- data.tar.gz: dc42b9d354000c87e9b90e1b43f1557399a7814d
5
- SHA512:
6
- metadata.gz: 08901a2e5162aa0c346816a6b51899c9097d1c5917701919c63bd7903127cc1ee352103ce7c7fa447b5b7f8601b800245eea49d680a76de12cc9dd05471e5f43
7
- data.tar.gz: eb38dd6ecaaa95436dc77f35f3e13123c7696d798e629532bb6cd8a0f4927e18963d4798ea9cd21c465d9d0dc7920e96df269d6009861057ebfcb5d66e022952
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 607a7f0ddaf8c0d778472a489584bae965435d46
4
+ data.tar.gz: bbd395af2e6c79c364ac5ed250994a49baedd9d1
5
+ SHA512:
6
+ metadata.gz: ab8d249138a7a9ae6246e130b9af1f9b1d15366f59114f826aef86f00f755118a617754b5fa721919ef75660179cdd6ab88255a4aa9fad5f7f74d8920ccb3c59
7
+ data.tar.gz: 2b375bf3db20fffee3e335f6fde8a841f72f955c8767d2a72f9fb371cca9a32ad08ceaa4ff8d77ffe916013ce6064d9f9c51847dadf9bfed294c81cd0257e518
@@ -1,8 +1,10 @@
1
- require 'corn/test_unit'
2
1
  require 'net/http'
3
2
  require 'net/https'
4
3
  require 'logger'
5
4
 
5
+ require 'corn/report'
6
+ require 'corn/test_unit'
7
+
6
8
  module Corn
7
9
  module_function
8
10
 
@@ -26,31 +28,27 @@ module Corn
26
28
  Test::Unit::TestCase.send(:include, Corn::TestUnit)
27
29
  end
28
30
 
29
- def benchmark(*labels, &block)
30
- reports = []
31
- yield(reporter(reports))
32
-
33
- log_error { report(labels, reports) }
31
+ def report(test_name, &block)
32
+ rep = report_start
33
+ begin
34
+ yield(rep)
35
+ ensure
36
+ report_end(test_name, rep)
37
+ end
34
38
  end
35
39
 
36
- def reporter(reports)
37
- lambda do |label, &block|
38
- start_at = Time.now
39
- begin
40
- block.call
41
- ensure
42
- realtime = Time.now - start_at
43
- reports << [label, start_at.to_i, realtime]
44
- end
45
- end
40
+ def report_start
41
+ Report.new
46
42
  end
47
43
 
48
- def report(labels, reports)
49
- data = [['client_id', client_id],
50
- ['build_id', build_id]]
51
- data.concat(labels.map {|l| ['labels[]', l]})
52
- data.concat(reports.map {|r| ['reports[]', r.join(",")]})
53
- http_post(File.join(host, 'benchmarks'), data)
44
+ def report_end(test_name, report)
45
+ log_error do
46
+ head = [['client_id', client_id],
47
+ ['build_id', build_id],
48
+ ['test_name', test_name]]
49
+ data = head.concat(report.records.map {|r| ['reports[]', r.join(",")]})
50
+ http_post(File.join(host, 'benchmarks'), data)
51
+ end
54
52
  end
55
53
 
56
54
  def http_post(url, data)
@@ -0,0 +1,29 @@
1
+ module Corn
2
+ class Report
3
+ attr_reader :records
4
+
5
+ def initialize
6
+ @records = []
7
+ end
8
+
9
+ def record(label, &block)
10
+ record_start(label)
11
+ yield
12
+ ensure
13
+ record_end
14
+ end
15
+
16
+ def record_start(label)
17
+ @record = [label, Time.now]
18
+ end
19
+
20
+ def record_end
21
+ @record << Time.now - @record[1]
22
+ @records << @record
23
+ end
24
+
25
+ def record_time
26
+ Time.now - @start_at
27
+ end
28
+ end
29
+ end
@@ -8,7 +8,7 @@ module Corn
8
8
  end
9
9
 
10
10
  def run_with_corn(result, &block)
11
- Corn.benchmark(name) do |report|
11
+ Corn.report(name) do |report|
12
12
  __run_with_corn__(report, result, &block)
13
13
  end
14
14
  end
@@ -17,8 +17,8 @@ module Corn
17
17
  yield(Test::Unit::TestCase::STARTED, name)
18
18
  @_result = result
19
19
  begin
20
- report.call(:setup) { setup }
21
- report.call(@method_name) { __send__(@method_name) }
20
+ report.record(:setup) { setup }
21
+ report.record(@method_name) { __send__(@method_name) }
22
22
  rescue AssertionFailedError => e
23
23
  add_failure(e.message, e.backtrace)
24
24
  rescue Exception
@@ -26,7 +26,7 @@ module Corn
26
26
  add_error($!)
27
27
  ensure
28
28
  begin
29
- report.call(:teardown) { teardown }
29
+ report.record(:teardown) { teardown }
30
30
  rescue AssertionFailedError => e
31
31
  add_failure(e.message, e.backtrace)
32
32
  rescue Exception
@@ -38,5 +38,38 @@ module Corn
38
38
  yield(Test::Unit::TestCase::FINISHED, name)
39
39
  end
40
40
  end
41
- TestUnit = TestUnit18
41
+
42
+ module TestUnit19
43
+ def self.included(base)
44
+ base.send(:alias_method, :run_without_corn, :run)
45
+ base.send(:alias_method, :run, :run_with_corn)
46
+ end
47
+
48
+ def run_with_corn(runner, &block)
49
+ Corn.report("#{__name__}(#{self.class.name})") do |report|
50
+ @__corn_report__ = report
51
+ run_without_corn(runner, &block)
52
+ end
53
+ end
54
+
55
+ def before_setup
56
+ @__corn_report__.record_start(:setup)
57
+ end
58
+
59
+ def after_setup
60
+ @__corn_report__.record_end
61
+ @__corn_report__.record_start(__name__)
62
+ end
63
+
64
+ def before_teardown
65
+ @__corn_report__.record_end
66
+ @__corn_report__.record_start(:teardown)
67
+ end
68
+
69
+ def after_teardown
70
+ @__corn_report__.record_end
71
+ end
72
+ end
73
+
74
+ TestUnit = RUBY_VERSION =~ /^1.8/ ? TestUnit18 : TestUnit19
42
75
  end
metadata CHANGED
@@ -1,56 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: corn
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  platform: ruby
6
- authors:
7
- - Xiao Li
6
+ authors:
7
+ - Xiao Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-01-29 00:00:00 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
13
12
  dependencies: []
14
-
15
13
  description: TBD
16
- email:
17
- - swing1979@gmail.com
14
+ email:
15
+ - swing1979@gmail.com
18
16
  executables: []
19
-
20
17
  extensions: []
21
-
22
18
  extra_rdoc_files: []
23
-
24
- files:
25
- - README.md
26
- - lib/corn.rb
27
- - lib/corn/setup.rb
28
- - lib/corn/test_unit.rb
19
+ files:
20
+ - README.md
21
+ - lib/corn.rb
22
+ - lib/corn/report.rb
23
+ - lib/corn/setup.rb
24
+ - lib/corn/test_unit.rb
29
25
  homepage: https://github.com/xli/corn
30
- licenses:
31
- - MIT
26
+ licenses:
27
+ - MIT
32
28
  metadata: {}
33
-
34
29
  post_install_message:
35
30
  rdoc_options: []
36
-
37
- require_paths:
38
- - lib
39
- required_ruby_version: !ruby/object:Gem::Requirement
40
- requirements:
41
- - &id001
42
- - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
45
- required_rubygems_version: !ruby/object:Gem::Requirement
46
- requirements:
47
- - *id001
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
48
43
  requirements: []
49
-
50
44
  rubyforge_project:
51
- rubygems_version: 2.1.9
45
+ rubygems_version: 2.2.0
52
46
  signing_key:
53
47
  specification_version: 4
54
48
  summary: TBD
55
49
  test_files: []
56
-