test_benchmark 0.0.3 → 0.4.6
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.
- data/lib/test_benchmark.rb +104 -18
- metadata +47 -52
- data/History.txt +0 -10
- data/Manifest.txt +0 -8
- data/README.txt +0 -16
- data/Rakefile +0 -13
- data/about.yml +0 -7
- data/init.rb +0 -1
- data/test/test_benchmark_test.rb +0 -16
data/lib/test_benchmark.rb
CHANGED
@@ -1,26 +1,112 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/unit/testresult'
|
3
|
+
require 'test/unit/testcase'
|
4
|
+
require 'test/unit/ui/console/testrunner'
|
4
5
|
|
5
|
-
|
6
|
+
class Test::Unit::UI::Console::TestRunner
|
7
|
+
DEFAULT_DISPLAY_LIMIT = 15
|
8
|
+
DEFAULT_SUITE_DISPLAY_LIMIT = 5
|
9
|
+
|
10
|
+
@@display_limit = DEFAULT_DISPLAY_LIMIT
|
11
|
+
@@suite_display_limit = DEFAULT_SUITE_DISPLAY_LIMIT
|
12
|
+
|
13
|
+
def self.set_test_benchmark_limits(set_display_limit=DEFAULT_DISPLAY_LIMIT, set_suite_display_limit=DEFAULT_SUITE_DISPLAY_LIMIT)
|
14
|
+
@@display_limit = set_display_limit
|
15
|
+
@@suite_display_limit = set_suite_display_limit
|
16
|
+
end
|
17
|
+
|
18
|
+
alias attach_to_mediator_old attach_to_mediator
|
19
|
+
# def attach_to_mediator_old
|
20
|
+
# @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
|
21
|
+
# @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
|
22
|
+
# @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
|
23
|
+
# @mediator.add_listener(TestCase::STARTED, &method(:test_started))
|
24
|
+
# @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
|
25
|
+
# end
|
26
|
+
def attach_to_mediator
|
27
|
+
attach_to_mediator_old
|
28
|
+
@mediator.add_listener(Test::Unit::TestSuite::STARTED, &method(:test_suite_started))
|
29
|
+
@mediator.add_listener(Test::Unit::TestSuite::FINISHED, &method(:test_suite_finished))
|
30
|
+
end
|
31
|
+
|
32
|
+
alias started_old started
|
33
|
+
def started(result)
|
34
|
+
started_old(result)
|
35
|
+
@test_benchmarks = {}
|
36
|
+
@suite_benchmarks = {}
|
37
|
+
end
|
38
|
+
|
39
|
+
alias finished_old finished
|
40
|
+
def finished(elapsed_time)
|
41
|
+
finished_old(elapsed_time)
|
42
|
+
output_benchmarks
|
43
|
+
output_benchmarks(:suite)
|
44
|
+
puts "\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
alias test_started_old test_started
|
48
|
+
def test_started(name)
|
49
|
+
test_started_old(name)
|
50
|
+
@test_benchmarks[name] = Time.now
|
51
|
+
end
|
52
|
+
|
53
|
+
alias test_finished_old test_finished
|
54
|
+
def test_finished(name)
|
55
|
+
test_finished_old(name)
|
56
|
+
@test_benchmarks[name] = Time.now - @test_benchmarks[name]
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_suite_started(suite_name)
|
60
|
+
@suite_benchmarks[suite_name] = Time.now
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_suite_finished(suite_name)
|
64
|
+
@suite_benchmarks[suite_name] = Time.now - @suite_benchmarks[suite_name]
|
65
|
+
output_benchmarks(suite_name) if full_output?
|
66
|
+
end
|
67
|
+
|
68
|
+
@@format_benchmark_row = lambda {|tuple| ("%0.3f" % tuple[1]) + " #{tuple[0]}"}
|
69
|
+
@@sort_by_time = lambda { |a,b| b[1] <=> a[1] }
|
6
70
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
71
|
+
private
|
72
|
+
def full_output?
|
73
|
+
ENV['BENCHMARK'] == 'full'
|
74
|
+
end
|
75
|
+
|
76
|
+
def select_by_suite_name(suite_name)
|
77
|
+
if suite_name == :suite
|
78
|
+
@suite_benchmarks.select{ |k,v| @test_benchmarks.detect{ |k1,v1| k1.include?(k) } }
|
79
|
+
elsif suite_name
|
80
|
+
@test_benchmarks.select{ |k,v| k.include?(suite_name) }
|
81
|
+
else
|
82
|
+
@test_benchmarks
|
16
83
|
end
|
17
|
-
|
84
|
+
end
|
18
85
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
86
|
+
def prep_benchmarks(suite_name=nil)
|
87
|
+
benchmarks = select_by_suite_name(suite_name)
|
88
|
+
return if benchmarks.nil? || benchmarks.empty?
|
89
|
+
benchmarks = benchmarks.sort(&@@sort_by_time)
|
90
|
+
unless full_output?
|
91
|
+
cutoff = (suite_name == :suite) ? @@suite_display_limit : @@display_limit
|
92
|
+
benchmarks = benchmarks.slice(0, cutoff)
|
23
93
|
end
|
94
|
+
benchmarks.map(&@@format_benchmark_row)
|
24
95
|
end
|
25
96
|
|
97
|
+
def header(suite_name)
|
98
|
+
if suite_name == :suite
|
99
|
+
"\nTest Benchmark Times: Suite Totals:\n"
|
100
|
+
elsif suite_name
|
101
|
+
"\nTest Benchmark Times: #{suite_name}\n"
|
102
|
+
else
|
103
|
+
"\nTEST BENCHMARK TIMES: OVERALL\n"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def output_benchmarks(suite_name=nil)
|
108
|
+
benchmarks = prep_benchmarks(suite_name)
|
109
|
+
return if benchmarks.nil? || benchmarks.empty?
|
110
|
+
puts header(suite_name) + benchmarks.join("\n") + "\n"
|
111
|
+
end
|
26
112
|
end
|
metadata
CHANGED
@@ -1,64 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: test_benchmark
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-06-24 00:00:00 -07:00
|
8
|
-
summary: A plugin for showing how long tests take to run.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: boss AT topfunky.com
|
12
|
-
homepage: http://rubyforge.org/projects/seattlerb
|
13
|
-
rubyforge_project: seattlerb
|
14
|
-
description: A simple hack that prints a report of test/unit test runtimes.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.4.6
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
7
|
+
- Tim Connor
|
30
8
|
- Geoffrey Grosenbach
|
31
|
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
- README.txt
|
45
|
-
extra_rdoc_files:
|
46
|
-
- History.txt
|
47
|
-
- Manifest.txt
|
48
|
-
- README.txt
|
9
|
+
- Mike Gunderloy
|
10
|
+
- Luke Francl
|
11
|
+
- Marek de Heus
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2009-01-13 00:00:00 -08:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description:
|
21
|
+
email: timocratic@gmail.com
|
49
22
|
executables: []
|
50
23
|
|
51
24
|
extensions: []
|
52
25
|
|
26
|
+
extra_rdoc_files: []
|
27
|
+
|
28
|
+
files:
|
29
|
+
- lib/test_benchmark.rb
|
30
|
+
has_rdoc: false
|
31
|
+
homepage: http://github.com/timocratic/test_benchmark
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
53
51
|
requirements: []
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: 1.2.1
|
64
|
-
version:
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.2
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: "Rails plugin (and/or ruby gem) for benchmarking your test::units: a rework of the original by topfunky"
|
58
|
+
test_files: []
|
59
|
+
|
data/History.txt
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
== 0.0.3 / 2007-06-24
|
2
|
-
|
3
|
-
* Updated Manifest.txt so files are actually packaged in the gem. D'oh!
|
4
|
-
* See also release notes for version 0.0.2
|
5
|
-
|
6
|
-
== 0.0.2
|
7
|
-
|
8
|
-
* Renamed gem to test_benchmark
|
9
|
-
* Upgraded to Hoe.
|
10
|
-
* Will always show report. If you don't want to see the report, it is recommended that you install the gem and list or comment out "require 'test_benchmark'" to enable the gem.
|
data/Manifest.txt
DELETED
data/README.txt
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
Test Benchmark
|
2
|
-
==============
|
3
|
-
|
4
|
-
A hack to show a report of how long each test takes to run.
|
5
|
-
|
6
|
-
Useful for troubleshooting slow tests.
|
7
|
-
|
8
|
-
Sample output:
|
9
|
-
|
10
|
-
7.124 test_destroy(FeedTest)
|
11
|
-
7.219 test_create(FeedTest)
|
12
|
-
7.646 test_subscribe_to_auto_discovery(FeedTest)
|
13
|
-
9.339 test_auto_discover_updates_url(FeedTest)
|
14
|
-
9.543 test_find_or_create_by_auto_discover_url(FeedTest)
|
15
|
-
15.780 test_import_from_opml(FeedTest)
|
16
|
-
|
data/Rakefile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'hoe'
|
3
|
-
# require './lib/test_benchmark.rb'
|
4
|
-
|
5
|
-
Hoe.new("test_benchmark", '0.0.3') do |p|
|
6
|
-
p.summary = "A plugin for showing how long tests take to run."
|
7
|
-
p.rubyforge_name = 'seattlerb'
|
8
|
-
p.author = 'Geoffrey Grosenbach'
|
9
|
-
p.email = 'boss AT topfunky.com'
|
10
|
-
p.description = 'A simple hack that prints a report of test/unit test runtimes.'
|
11
|
-
p.url = "http://rubyforge.org/projects/seattlerb"
|
12
|
-
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
-
end
|
data/about.yml
DELETED
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/lib/test_benchmark"
|
data/test/test_benchmark_test.rb
DELETED