rgot 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 +4 -4
- data/.travis.yml +1 -0
- data/Rakefile +1 -1
- data/bin/rgot +23 -8
- data/lib/rgot.rb +17 -4
- data/lib/rgot/b.rb +78 -0
- data/lib/rgot/m.rb +24 -5
- data/lib/rgot/t.rb +6 -2
- data/lib/rgot/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b420828d0e0801d5f766faa6ef3c57c67ae81a6b
|
4
|
+
data.tar.gz: 49271b8268fc5eb3b61da0350a2ac12adb5b91c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 384ccc588fe79b31c639d8e4aaa6ada76ba283ab9082ddc113b84362277142616dcb54fba6c4250827bafc3443f90de7a1284b2ebda61e6bab1573b8f5ef39ea
|
7
|
+
data.tar.gz: 39490b59b9baf6c883b6beafce640ddd5301aa34ee2f0e3f199db0daead6932463c74c3408576638fc63ee5275f083d49b6b73f9bb05fdbb15e690c01e86a27d
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
data/bin/rgot
CHANGED
@@ -4,8 +4,17 @@ require 'rgot'
|
|
4
4
|
|
5
5
|
opts = {}
|
6
6
|
parser = OptionParser.new do |o|
|
7
|
-
o.on '-v', '--verbose', "log all tests" do
|
8
|
-
opts[:verbose] =
|
7
|
+
o.on '-v', '--verbose', "log all tests" do |arg|
|
8
|
+
opts[:verbose] = arg
|
9
|
+
end
|
10
|
+
o.on '-b', '--bench [regexp]', "benchmark" do |arg|
|
11
|
+
unless arg
|
12
|
+
raise Rgot::OptionError, "missing argument for flag --bench"
|
13
|
+
end
|
14
|
+
opts[:bench] = arg
|
15
|
+
end
|
16
|
+
o.on '--benchtime [sec]', "benchmark running time" do |arg|
|
17
|
+
opts[:benchtime] = arg
|
9
18
|
end
|
10
19
|
end
|
11
20
|
parser.parse!(ARGV)
|
@@ -20,7 +29,7 @@ if target
|
|
20
29
|
require i
|
21
30
|
end
|
22
31
|
else
|
23
|
-
puts
|
32
|
+
puts target
|
24
33
|
end
|
25
34
|
else
|
26
35
|
Dir.glob("./**/*_test.rb") do |i|
|
@@ -38,20 +47,26 @@ if 1 != modules.length
|
|
38
47
|
exit 1
|
39
48
|
end
|
40
49
|
|
41
|
-
|
50
|
+
tests = []
|
51
|
+
benchmarks = []
|
42
52
|
main = nil
|
43
53
|
c = modules.first
|
44
54
|
|
45
55
|
test_module = Object.const_get(c)
|
46
|
-
test_module.instance_methods
|
56
|
+
methods = test_module.instance_methods
|
57
|
+
methods.grep(/\Atest_.*/).sort.each do |m|
|
47
58
|
if m == :test_main && main.nil?
|
48
|
-
main = Rgot::
|
59
|
+
main = Rgot::InternalTest.new(test_module, m)
|
49
60
|
else
|
50
|
-
|
61
|
+
tests << Rgot::InternalTest.new(test_module, m)
|
51
62
|
end
|
52
63
|
end
|
53
64
|
|
54
|
-
|
65
|
+
methods.grep(/\Abenchmark_.*/).sort.each do |m|
|
66
|
+
benchmarks << Rgot::InternalBenchmark.new(test_module, m)
|
67
|
+
end
|
68
|
+
|
69
|
+
m = Rgot::M.new(tests: tests, benchmarks: benchmarks, opts: opts)
|
55
70
|
duration = Rgot.now
|
56
71
|
at_exit {
|
57
72
|
puts sprintf("ok\t%.3fs", Rgot.now - duration)
|
data/lib/rgot.rb
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
module Rgot
|
2
2
|
autoload :VERSION, 'rgot/version'
|
3
3
|
autoload :Common, 'rgot/common'
|
4
|
-
autoload :T, 'rgot/t'
|
5
4
|
autoload :M, 'rgot/m'
|
5
|
+
autoload :T, 'rgot/t'
|
6
|
+
autoload :B, 'rgot/b'
|
7
|
+
|
8
|
+
class OptionError < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
class InternalTest < Struct.new(:module, :name)
|
12
|
+
end
|
6
13
|
|
7
|
-
class
|
14
|
+
class InternalBenchmark < Struct.new(:module, :name)
|
8
15
|
end
|
9
16
|
|
10
17
|
class << self
|
11
|
-
|
12
|
-
|
18
|
+
if "2.0.0" < RUBY_VERSION
|
19
|
+
def now
|
20
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
def now
|
24
|
+
Time.now
|
25
|
+
end
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|
data/lib/rgot/b.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Rgot
|
2
|
+
class B < Common
|
3
|
+
attr_accessor :n
|
4
|
+
def initialize(benchmark_module, name, opts)
|
5
|
+
super()
|
6
|
+
@n = 1
|
7
|
+
@module = benchmark_module
|
8
|
+
@name = name
|
9
|
+
@opts = opts
|
10
|
+
@benchtime = @opts.fetch(:benchtime, 1).to_f
|
11
|
+
@timer_on = false
|
12
|
+
@start = Rgot.now
|
13
|
+
@duration = 0
|
14
|
+
@module.extend @module
|
15
|
+
end
|
16
|
+
|
17
|
+
def start_timer
|
18
|
+
if !@timer_on
|
19
|
+
@start = Rgot.now
|
20
|
+
@timer_on = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def stop_timer
|
25
|
+
if @timer_on
|
26
|
+
@duration += Rgot.now - @start
|
27
|
+
@timer_on = false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset_timer
|
32
|
+
if @timer_on
|
33
|
+
@start = Rgot.now
|
34
|
+
end
|
35
|
+
@duration = 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def run
|
39
|
+
n = 1
|
40
|
+
a = Rgot.now
|
41
|
+
run_n(n)
|
42
|
+
while !failed? && @duration < @benchtime && @n < 1e9
|
43
|
+
if @duration < (@benchtime / 100.0)
|
44
|
+
n *= 100
|
45
|
+
elsif @duration < (@benchtime / 10.0)
|
46
|
+
n *= 10
|
47
|
+
elsif @duration < (@benchtime / 5.0)
|
48
|
+
n *= 5
|
49
|
+
elsif @duration < (@benchtime / 2.0)
|
50
|
+
n *= 2
|
51
|
+
else
|
52
|
+
n *= 1.2
|
53
|
+
end
|
54
|
+
run_n(n)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def report
|
59
|
+
printf("%s\t%d\t%.3f ns/op\n", @name, @n, @duration / @n * 1_000_000_000)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def run_n(n)
|
65
|
+
GC.start
|
66
|
+
i = 0
|
67
|
+
@n = n
|
68
|
+
reset_timer
|
69
|
+
start_timer
|
70
|
+
call
|
71
|
+
stop_timer
|
72
|
+
end
|
73
|
+
|
74
|
+
def call
|
75
|
+
@module.instance_method(@name).bind(@module).call(self)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/rgot/m.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Rgot
|
2
2
|
class M
|
3
|
-
|
4
|
-
|
3
|
+
# Ruby-2.0.0 wants default value of keyword_argument
|
4
|
+
def initialize(tests: [], benchmarks: [], opts: {})
|
5
|
+
@tests = tests
|
6
|
+
@benchmarks = benchmarks
|
5
7
|
@opts = opts
|
6
8
|
end
|
7
9
|
|
8
10
|
def run
|
9
11
|
test_ok = run_tests
|
10
|
-
|
12
|
+
benchmark_ok = run_benchmarks
|
13
|
+
if !test_ok || !benchmark_ok
|
11
14
|
puts "FAIL"
|
12
15
|
1
|
13
16
|
else
|
@@ -20,8 +23,8 @@ module Rgot
|
|
20
23
|
|
21
24
|
def run_tests
|
22
25
|
ok = true
|
23
|
-
@
|
24
|
-
t =
|
26
|
+
@tests.each do |test|
|
27
|
+
t = T.new(test.module, test.name.to_sym, @opts)
|
25
28
|
if @opts[:verbose]
|
26
29
|
puts "=== RUN #{test.name}\n"
|
27
30
|
end
|
@@ -33,5 +36,21 @@ module Rgot
|
|
33
36
|
end
|
34
37
|
ok
|
35
38
|
end
|
39
|
+
|
40
|
+
def run_benchmarks
|
41
|
+
ok = true
|
42
|
+
return ok unless @opts[:bench]
|
43
|
+
@benchmarks.each do |bench|
|
44
|
+
next unless /#{@opts[:bench]}/ =~ bench.name
|
45
|
+
|
46
|
+
b = B.new(bench.module, bench.name.to_sym, @opts)
|
47
|
+
b.run
|
48
|
+
b.report
|
49
|
+
if b.failed?
|
50
|
+
ok = false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
ok
|
54
|
+
end
|
36
55
|
end
|
37
56
|
end
|
data/lib/rgot/t.rb
CHANGED
@@ -5,12 +5,12 @@ module Rgot
|
|
5
5
|
@module = test_module
|
6
6
|
@name = name
|
7
7
|
@opts = opts
|
8
|
+
@module.extend @module
|
8
9
|
end
|
9
10
|
|
10
11
|
def run
|
11
12
|
begin
|
12
|
-
|
13
|
-
@module.instance_method(@name).bind(@module).call(self)
|
13
|
+
call
|
14
14
|
finished!
|
15
15
|
rescue => e
|
16
16
|
fail!
|
@@ -32,5 +32,9 @@ module Rgot
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
def call
|
37
|
+
@module.instance_method(@name).bind(@module).call(self)
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
data/lib/rgot/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: rgot is golang like testing module in ruby
|
@@ -46,14 +46,15 @@ executables:
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
-
|
50
|
-
-
|
49
|
+
- .gitignore
|
50
|
+
- .travis.yml
|
51
51
|
- Gemfile
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
55
|
- bin/rgot
|
56
56
|
- lib/rgot.rb
|
57
|
+
- lib/rgot/b.rb
|
57
58
|
- lib/rgot/common.rb
|
58
59
|
- lib/rgot/m.rb
|
59
60
|
- lib/rgot/t.rb
|
@@ -69,17 +70,17 @@ require_paths:
|
|
69
70
|
- lib
|
70
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
72
|
requirements:
|
72
|
-
- -
|
73
|
+
- - '>='
|
73
74
|
- !ruby/object:Gem::Version
|
74
75
|
version: '0'
|
75
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
77
|
requirements:
|
77
|
-
- -
|
78
|
+
- - '>='
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
82
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.0.14
|
83
84
|
signing_key:
|
84
85
|
specification_version: 4
|
85
86
|
summary: The Ruby GOlang like Testing module
|