rgot 0.1.5 → 0.2.0

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
1
  ---
2
2
  SHA1:
3
- metadata.gz: fad880c302f5d362eda08135ab27437e1888969d
4
- data.tar.gz: fbed3fac0716f0957c4a88864c0444e261f2ad74
3
+ metadata.gz: a4246161e01be60d8f75c374c5411521513b4892
4
+ data.tar.gz: b72b95bb14e0793b70d613abdb61078defb658d5
5
5
  SHA512:
6
- metadata.gz: 60c14ab525a73c15392801891161bde4f45c21544037fc273c657b75ab96bab751efa0c8fc166a51fcfaf069b8b5ce0c452f84d8b8aaffc272a95c939634e8b6
7
- data.tar.gz: 441094eb65219d7b2105bce7b7df8945abb14186025eb71f7af2e953269735f8df98e740cfe76c86ae8ef78fc7c3e10d238a3b76ba724cadd6777cba30bde84f
6
+ metadata.gz: 865bf93fdc54e99fdb2b17194516f13d694ad84fe2f11372200a4dcc90e3ee895571f2a041700b991749344a4d15b213b91f55172d8c59636afc85b86051d0d4
7
+ data.tar.gz: c24d7e37e5ac9c1ce61539e27196875b1091e896ca8a512a845e2cb78d56d38407c773a511e317adc2bf9a758a35456adca57a9a18db171107a9ca2ad9b6958f
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.7
5
- - 2.2.3
3
+ - 2.1.10
4
+ - 2.2.4
5
+ - 2.3.0
6
6
  notifications:
7
7
  email: false
data/bin/rgot CHANGED
@@ -6,7 +6,7 @@ opts = Rgot::M::Options.new
6
6
  require_paths = []
7
7
  parser = OptionParser.new do |o|
8
8
  o.on '-v', '--verbose', "log all tests" do |arg|
9
- Rgot.class_eval{ @chatty = arg }
9
+ Rgot.class_eval { @chatty = arg }
10
10
  end
11
11
  o.on '--version', "show Rgot version" do |arg|
12
12
  puts "rgot #{Rgot::VERSION} (ruby #{RUBY_VERSION})"
@@ -42,17 +42,19 @@ require_paths.each do |path|
42
42
  require path
43
43
  end
44
44
 
45
+ testing_files = []
46
+
45
47
  if ARGV.empty?
46
48
  Dir.glob("./**/*_test.rb") do |i|
47
- require i
49
+ testing_files << i
48
50
  end
49
51
  else
50
52
  ARGV.each do |target|
51
53
  if File.file?(target)
52
- require File.expand_path(target)
54
+ testing_files << File.expand_path(target)
53
55
  elsif File.directory?(target)
54
56
  Dir.glob("./#{target}/**/*_test.rb") do |i|
55
- require i
57
+ testing_files << i
56
58
  end
57
59
  else
58
60
  puts target
@@ -60,72 +62,71 @@ else
60
62
  end
61
63
  end
62
64
 
63
- modules = Object.constants.select { |c|
64
- next if c == :FileTest
65
- /.*Test\z/ =~ c
66
- }.map{ |c|
67
- Object.const_get(c)
68
- }
69
-
70
- # if 1 != modules.length
71
- # puts "can not load module. found #{modules.join(', ')}"
72
- # exit 1
73
- # end
74
-
75
65
  code = 0
76
- modules.each do |test_module|
66
+ testing_files.each do |testing_file|
77
67
  begin
78
- pid = fork {
79
- tests = []
80
- benchmarks = []
81
- examples = []
82
- main = nil
83
- methods = test_module.instance_methods
84
- methods.grep(/\Atest_/).each do |m|
85
- if m == :test_main && main.nil?
86
- main = Rgot::InternalTest.new(test_module, m)
87
- else
88
- tests << Rgot::InternalTest.new(test_module, m)
68
+ pid = fork do
69
+ require testing_file
70
+
71
+ modules = Object.constants.select { |c|
72
+ next if c == :FileTest
73
+ /.*Test\z/ =~ c
74
+ }.map { |c|
75
+ Object.const_get(c)
76
+ }
77
+
78
+ modules.each do |test_module|
79
+ tests = []
80
+ benchmarks = []
81
+ examples = []
82
+ main = nil
83
+ methods = test_module.instance_methods
84
+ methods.grep(/\Atest_/).each do |m|
85
+ if m == :test_main && main.nil?
86
+ main = Rgot::InternalTest.new(test_module, m)
87
+ else
88
+ tests << Rgot::InternalTest.new(test_module, m)
89
+ end
89
90
  end
90
- end
91
91
 
92
- methods.grep(/\Abenchmark_/).each do |m|
93
- benchmarks << Rgot::InternalBenchmark.new(test_module, m)
94
- end
92
+ methods.grep(/\Abenchmark_/).each do |m|
93
+ benchmarks << Rgot::InternalBenchmark.new(test_module, m)
94
+ end
95
95
 
96
- methods.grep(/\Aexample_?/).each do |m|
97
- examples << Rgot::InternalExample.new(test_module, m)
98
- end
96
+ methods.grep(/\Aexample_?/).each do |m|
97
+ examples << Rgot::InternalExample.new(test_module, m)
98
+ end
99
99
 
100
- duration = Rgot.now
101
- at_exit {
102
- template = "%s\t%s\t%.3fs"
100
+ duration = Rgot.now
101
+ at_exit do
102
+ template = "%s\t%s\t%.3fs"
103
103
 
104
- case $!
105
- when SystemExit
106
- if $!.success?
107
- # exit 0
108
- puts sprintf(template, "ok ", test_module, Rgot.now - duration)
104
+ case $!
105
+ when SystemExit
106
+ if $!.success?
107
+ # exit 0
108
+ puts sprintf(template, "ok ", test_module, Rgot.now - duration)
109
+ else
110
+ # exit 1
111
+ puts "exit status #{$!.status}"
112
+ puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
113
+ end
114
+ when NilClass
115
+ # not raise, not exit
109
116
  else
110
- # exit 1
111
- puts "exit status #{$!.status}"
117
+ # any exception
112
118
  puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
113
119
  end
114
- when NilClass
115
- # not raise, not exit
120
+ end
121
+ m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
122
+ if main
123
+ main.module.extend main.module
124
+ main.module.instance_method(main.name).bind(main.module).call(m)
116
125
  else
117
- # any exception
118
- puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
126
+ exit m.run
119
127
  end
120
- }
121
- m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
122
- if main
123
- main.module.extend main.module
124
- main.module.instance_method(main.name).bind(main.module).call(m)
125
- else
126
- exit m.run
127
128
  end
128
- }
129
+ end
129
130
  ensure
130
131
  _, status = Process.waitpid2(pid)
131
132
  unless status.success?
@@ -8,33 +8,18 @@ module Rgot
8
8
  require 'rgot/benchmark_result'
9
9
  require 'rgot/example_parser'
10
10
 
11
- class OptionError < StandardError
12
- end
13
-
14
- class InternalTest < Struct.new(:module, :name)
15
- end
16
-
17
- class InternalBenchmark < Struct.new(:module, :name)
18
- end
19
-
20
- class InternalExample < Struct.new(:module, :name)
21
- end
22
-
23
- class ExampleOutput < Struct.new(:name, :output)
24
- end
11
+ OptionError = Class.new(StandardError)
12
+ InternalTest = Struct.new(:module, :name)
13
+ InternalBenchmark = Struct.new(:module, :name)
14
+ InternalExample = Struct.new(:module, :name)
15
+ ExampleOutput = Struct.new(:name, :output)
25
16
 
26
17
  class << self
27
- if "2.0.0" < RUBY_VERSION
28
- def now
29
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
30
- end
31
- else
32
- def now
33
- Time.now
34
- end
18
+ def now
19
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
35
20
  end
36
21
 
37
- def benchmark(opts_hash={}, &block)
22
+ def benchmark(opts_hash = {}, &block)
38
23
  opts = B::Options.new
39
24
  opts_hash.each do |k, v|
40
25
  opts[k] = v
@@ -1,13 +1,13 @@
1
1
  module Rgot
2
2
  class B < Common
3
- class Options < Struct.new(
3
+ Options = Struct.new(
4
4
  :procs,
5
5
  :threads,
6
- :benchtime
7
- ); end
6
+ :benchtime,
7
+ )
8
8
 
9
9
  attr_accessor :n
10
- def initialize(benchmark_module, name, opts=Options.new)
10
+ def initialize(benchmark_module, name, opts = Options.new)
11
11
  super()
12
12
  @n = 1
13
13
  @module = benchmark_module
@@ -42,7 +42,7 @@ module Rgot
42
42
  def run(&block)
43
43
  n = 1
44
44
  benchtime = (@opts.benchtime || 1).to_f
45
- catch(:skip) {
45
+ catch(:skip) do
46
46
  run_n(n.to_i, block)
47
47
  while !failed? && @duration < benchtime && @n < 1e9
48
48
  if @duration < (benchtime / 100.0)
@@ -61,7 +61,7 @@ module Rgot
61
61
  end
62
62
  run_n(@n.to_i, block)
63
63
  end
64
- }
64
+ end
65
65
 
66
66
  BenchmarkResult.new(n: @n, t: @duration)
67
67
  end
@@ -73,13 +73,13 @@ module Rgot
73
73
  threads = (@opts.threads || 1)
74
74
 
75
75
  procs.times do
76
- fork {
76
+ fork do
77
77
  Array.new(threads) {
78
78
  Thread.new {
79
79
  yield PB.new(bn: @n)
80
80
  }.tap { |t| t.abort_on_exception = true }
81
81
  }.each(&:join)
82
- }
82
+ end
83
83
  end
84
84
  @n *= procs * threads
85
85
  Process.waitall
@@ -87,7 +87,7 @@ module Rgot
87
87
 
88
88
  private
89
89
 
90
- def run_n(n, block=nil)
90
+ def run_n(n, block = nil)
91
91
  GC.start
92
92
  @n = n
93
93
  reset_timer
@@ -98,7 +98,7 @@ module Rgot
98
98
  bench_method = @module.instance_method(@name).bind(@module)
99
99
  if bench_method.arity == 0
100
100
  path, line = bench_method.source_location
101
- self.skip "#{path}:#{line} `#{bench_method.name}' is not running. It's a benchmark method name, But not have argument"
101
+ skip "#{path}:#{line} `#{bench_method.name}' is not running. It's a benchmark method name, But not have argument"
102
102
  else
103
103
  bench_method.call(self)
104
104
  end
@@ -1,9 +1,6 @@
1
1
  module Rgot
2
2
  class BenchmarkResult
3
- # Ruby-2.0.0 wants default value of keyword_argument
4
- def initialize(n: nil, t: nil)
5
- raise ArgumentError, "missing keyword: n" unless n
6
- raise ArgumentError, "missing keyword: t" unless t
3
+ def initialize(n:, t:)
7
4
  @n = n
8
5
  @t = t
9
6
  end
@@ -12,12 +12,8 @@ module Rgot
12
12
  :thread,
13
13
  ); end
14
14
 
15
- # Ruby-2.0.0 wants default value of keyword_argument
16
- def initialize(tests: nil, benchmarks: nil, examples: nil, opts: Options.new)
17
- raise ArgumentError, "missing keyword: tests" unless tests
18
- raise ArgumentError, "missing keyword: benchmarks" unless benchmarks
19
- raise ArgumentError, "missing keyword: examples" unless examples
20
- cpu = opts.cpu || "#{Etc.respond_to?(:nprocessors) ? Etc.nprocessors : "1"}"
15
+ def initialize(tests:, benchmarks:, examples:, opts: Options.new)
16
+ cpu = opts.cpu || (Etc.respond_to?(:nprocessors) ? Etc.nprocessors : '1').to_s
21
17
  @cpu_list = cpu.split(',').map { |i|
22
18
  j = i.to_i
23
19
  raise Rgot::OptionError, "invalid value #{i.inspect} for --cpu" unless 0 < j
@@ -38,10 +34,10 @@ module Rgot
38
34
  test_ok = false
39
35
  example_ok = false
40
36
 
41
- Timeout.timeout(@opts.timeout.to_f) {
37
+ Timeout.timeout(@opts.timeout.to_f) do
42
38
  test_ok = run_tests
43
39
  example_ok = run_examples
44
- }
40
+ end
45
41
  if !test_ok || !example_ok
46
42
  puts "FAIL"
47
43
  return 1
@@ -118,7 +114,7 @@ module Rgot
118
114
  file = method.source_location[0]
119
115
  r = ExampleParser.new(File.read(file))
120
116
  r.parse
121
- e = r.examples.find{|e| e.name == example.name}
117
+ e = r.examples.find { |e| e.name == example.name }
122
118
 
123
119
  duration = Rgot.now - start
124
120
  if e && e.output.strip != out.strip
@@ -2,9 +2,7 @@ module Rgot
2
2
  class PB
3
3
  attr_accessor :bn
4
4
 
5
- # Ruby-2.0.0 wants default value of keyword_argument
6
- def initialize(bn: nil)
7
- raise ArgumentError, "missing keyword: bn" unless bn
5
+ def initialize(bn:)
8
6
  @bn = bn
9
7
  end
10
8
 
@@ -8,14 +8,12 @@ module Rgot
8
8
  end
9
9
 
10
10
  def run
11
- begin
12
- catch(:skip) { call }
13
- finish!
14
- rescue => e
15
- fail!
16
- report
17
- raise e
18
- end
11
+ catch(:skip) { call }
12
+ finish!
13
+ rescue => e
14
+ fail!
15
+ report
16
+ raise e
19
17
  end
20
18
 
21
19
  def report
@@ -1,3 +1,3 @@
1
1
  module Rgot
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-12 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  requirements: []
85
85
  rubyforge_project:
86
- rubygems_version: 2.5.0
86
+ rubygems_version: 2.5.1
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: Ruby + Golang Testing = Rgot