rgot 0.2.0 → 1.1.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
- SHA1:
3
- metadata.gz: a4246161e01be60d8f75c374c5411521513b4892
4
- data.tar.gz: b72b95bb14e0793b70d613abdb61078defb658d5
2
+ SHA256:
3
+ metadata.gz: edabddcdf99d28070fbe94f391d49d7c034cb1b6d467629c76fc671f7d27956b
4
+ data.tar.gz: 642606670788ef496178d91b9450f6c08bb97e8e4f9e14442e0868ddf0c2acbd
5
5
  SHA512:
6
- metadata.gz: 865bf93fdc54e99fdb2b17194516f13d694ad84fe2f11372200a4dcc90e3ee895571f2a041700b991749344a4d15b213b91f55172d8c59636afc85b86051d0d4
7
- data.tar.gz: c24d7e37e5ac9c1ce61539e27196875b1091e896ca8a512a845e2cb78d56d38407c773a511e317adc2bf9a758a35456adca57a9a18db171107a9ca2ad9b6958f
6
+ metadata.gz: eb8824c1730be5395ffb22b3c075239b612a987db000367c804201394305b080834bb246c7c198da556e26090ae7a8424830b6253f7c10fd0183662ff6d490d0
7
+ data.tar.gz: 4064bdb31930c1cc0a072ab6c7113f93f66ce8cd3bafd4208824c36a5c591685a0e82f7e09758ff32a4d342eefee64efeb92910e8b45c75a48175571f84e03f7
@@ -0,0 +1,30 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '2.6.10'
18
+ - '2.7.6'
19
+ - '3.0.4'
20
+ - '3.1.2'
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Set up Ruby
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ bundler-cache: true
29
+ - name: Run the default task
30
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Rgot
2
2
  ===
3
3
 
4
- [![Build Status](https://travis-ci.org/ksss/rgot.svg)](https://travis-ci.org/ksss/rgot)
4
+ [![Ruby](https://github.com/ksss/rgot/actions/workflows/main.yml/badge.svg)](https://github.com/ksss/rgot/actions/workflows/main.yml)
5
5
 
6
6
  Ruby + Golang Testing = Rgot
7
7
 
@@ -36,8 +36,8 @@ module SampleTest
36
36
  s = Sample.new
37
37
  DATA.each do |ts|
38
38
  sum = s.sum(ts.left, ts.right)
39
- unless sum.kind_of?(Fixnum)
40
- t.error("expect Fixnum got #{sum.class}")
39
+ unless sum.kind_of?(Integer)
40
+ t.error("expect Integer got #{sum.class}")
41
41
  end
42
42
  unless sum == ts.expect
43
43
  t.error("expect #{ts.expect} got #{sum}")
@@ -131,6 +131,36 @@ end
131
131
 
132
132
  So, you can notice that the sample code is wrong.
133
133
 
134
+ # Table Driven Tests
135
+
136
+ ```rb
137
+ FLAGTESTS = [
138
+ ["%a", "[%a]"],
139
+ ["%-a", "[%-a]"],
140
+ ["%+a", "[%+a]"],
141
+ ["%#a", "[%#a]"],
142
+ ["% a", "[% a]"],
143
+ ["%0a", "[%0a]"],
144
+ ["%1.2a", "[%1.2a]"],
145
+ ["%-1.2a", "[%-1.2a]"],
146
+ ["%+1.2a", "[%+1.2a]"],
147
+ ["%-+1.2a", "[%+-1.2a]"],
148
+ ["%-+1.2abc", "[%+-1.2a]bc"],
149
+ ["%-1.2abc", "[%-1.2a]bc"],
150
+ ]
151
+
152
+ def test_flag_parser(t)
153
+ FLAGTESTS.each do |input, output|
154
+ s = Flag.print(input)
155
+ unless s == output
156
+ t.errorf("Flag.print(%p) => %p, want %p", input, s, output)
157
+ end
158
+ end
159
+ end
160
+ ```
161
+
162
+ see https://github.com/golang/go/wiki/TableDrivenTests
163
+
134
164
  # Naming convention
135
165
 
136
166
  ## Filename
data/Rakefile CHANGED
@@ -2,8 +2,11 @@ require "bundler/gem_tasks"
2
2
 
3
3
  desc "test to rgot"
4
4
  task :test do |t|
5
- target = "test/{rgot_common,rgot}_test.rb"
6
- ruby "bin/rgot -v #{target}"
5
+ targets = [
6
+ "test/rgot_common_test.rb",
7
+ "test/rgot_test.rb",
8
+ ]
9
+ ruby "bin/rgot -v #{targets.join(' ')}"
7
10
  end
8
11
 
9
12
  task :default => [:test]
data/bin/rgot CHANGED
@@ -1,138 +1,4 @@
1
1
  #! /usr/bin/env ruby
2
- require 'optparse'
3
- require 'rgot'
2
+ require 'rgot/cli'
4
3
 
5
- opts = Rgot::M::Options.new
6
- require_paths = []
7
- parser = OptionParser.new do |o|
8
- o.on '-v', '--verbose', "log all tests" do |arg|
9
- Rgot.class_eval { @chatty = arg }
10
- end
11
- o.on '--version', "show Rgot version" do |arg|
12
- puts "rgot #{Rgot::VERSION} (ruby #{RUBY_VERSION})"
13
- exit 0
14
- end
15
- o.on '--bench [regexp]', "benchmark" do |arg|
16
- unless arg
17
- raise Rgot::OptionError, "missing argument for flag --bench"
18
- end
19
- opts.bench = arg
20
- end
21
- o.on '--benchtime [sec]', "benchmark running time" do |arg|
22
- opts.benchtime = arg
23
- end
24
- o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
25
- opts.timeout = arg
26
- end
27
- o.on '--cpu [count,...]', "set cpu counts of comma split" do |arg|
28
- opts.cpu = arg
29
- end
30
- o.on '--thread [count,...]', "set thread counts of comma split" do |arg|
31
- opts.thread = arg
32
- end
33
- o.on '--require [path]', "load some code before running" do |arg|
34
- require_paths << arg
35
- end
36
- o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
37
- $LOAD_PATH.unshift(arg)
38
- end
39
- end
40
- parser.parse!(ARGV)
41
- require_paths.each do |path|
42
- require path
43
- end
44
-
45
- testing_files = []
46
-
47
- if ARGV.empty?
48
- Dir.glob("./**/*_test.rb") do |i|
49
- testing_files << i
50
- end
51
- else
52
- ARGV.each do |target|
53
- if File.file?(target)
54
- testing_files << File.expand_path(target)
55
- elsif File.directory?(target)
56
- Dir.glob("./#{target}/**/*_test.rb") do |i|
57
- testing_files << i
58
- end
59
- else
60
- puts target
61
- end
62
- end
63
- end
64
-
65
- code = 0
66
- testing_files.each do |testing_file|
67
- begin
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
90
- end
91
-
92
- methods.grep(/\Abenchmark_/).each do |m|
93
- benchmarks << Rgot::InternalBenchmark.new(test_module, m)
94
- end
95
-
96
- methods.grep(/\Aexample_?/).each do |m|
97
- examples << Rgot::InternalExample.new(test_module, m)
98
- end
99
-
100
- duration = Rgot.now
101
- at_exit do
102
- template = "%s\t%s\t%.3fs"
103
-
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
116
- else
117
- # any exception
118
- puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
119
- end
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)
125
- else
126
- exit m.run
127
- end
128
- end
129
- end
130
- ensure
131
- _, status = Process.waitpid2(pid)
132
- unless status.success?
133
- code = 1
134
- end
135
- end
136
- end
137
-
138
- exit code
4
+ Rgot::Cli.new(ARGV).run
data/lib/rgot/cli.rb ADDED
@@ -0,0 +1,154 @@
1
+ require 'optparse'
2
+
3
+ require_relative '../rgot'
4
+
5
+ module Rgot
6
+ class Cli
7
+ def initialize(argv)
8
+ @argv = argv
9
+ end
10
+
11
+ def run
12
+ opts = Rgot::M::Options.new
13
+ parse_option(opts)
14
+ process_start(opts)
15
+ end
16
+
17
+ private
18
+
19
+ def parse_option(opts)
20
+ require_paths = []
21
+ parser = OptionParser.new do |o|
22
+ o.on '-v', '--verbose', "log all tests" do |arg|
23
+ Rgot.class_eval { @chatty = arg }
24
+ end
25
+ o.on '--version', "show Rgot version" do |arg|
26
+ puts "rgot #{Rgot::VERSION} (ruby #{RUBY_VERSION})"
27
+ exit 0
28
+ end
29
+ o.on '--bench [regexp]', "benchmark" do |arg|
30
+ unless arg
31
+ raise Rgot::OptionError, "missing argument for flag --bench"
32
+ end
33
+ opts.bench = arg
34
+ end
35
+ o.on '--benchtime [sec]', "benchmark running time" do |arg|
36
+ opts.benchtime = arg
37
+ end
38
+ o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
39
+ opts.timeout = arg
40
+ end
41
+ o.on '--cpu [count,...]', "set cpu counts of comma split" do |arg|
42
+ opts.cpu = arg
43
+ end
44
+ o.on '--thread [count,...]', "set thread counts of comma split" do |arg|
45
+ opts.thread = arg
46
+ end
47
+ o.on '--require [path]', "load some code before running" do |arg|
48
+ require_paths << arg
49
+ end
50
+ o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
51
+ $LOAD_PATH.unshift(arg)
52
+ end
53
+ end
54
+ parser.parse!(@argv)
55
+
56
+ require_paths.each do |path|
57
+ require path
58
+ end
59
+ end
60
+
61
+ def testing_files
62
+ if @argv.empty?
63
+ Dir.glob("./**/*_test.rb")
64
+ else
65
+ @argv.flat_map do |target|
66
+ if File.file?(target)
67
+ File.expand_path(target)
68
+ elsif File.directory?(target)
69
+ Dir.glob("./#{target}/**/*_test.rb")
70
+ else
71
+ warn "#{target} is not file or directory"
72
+ end
73
+ end.compact
74
+ end
75
+ end
76
+
77
+ def process_start(opts)
78
+ code = 0
79
+ testing_files.map do |testing_file|
80
+ begin
81
+ pid = fork do
82
+ require testing_file
83
+
84
+ modules = Object.constants.select { |c|
85
+ next if c == :FileTest
86
+ /.*Test\z/ =~ c
87
+ }.map { |c|
88
+ Object.const_get(c)
89
+ }
90
+
91
+ modules.each do |test_module|
92
+ tests = []
93
+ benchmarks = []
94
+ examples = []
95
+ main = nil
96
+ methods = test_module.instance_methods
97
+ methods.grep(/\Atest_/).each do |m|
98
+ if m == :test_main && main.nil?
99
+ main = Rgot::InternalTest.new(test_module, m)
100
+ else
101
+ tests << Rgot::InternalTest.new(test_module, m)
102
+ end
103
+ end
104
+
105
+ methods.grep(/\Abenchmark_/).each do |m|
106
+ benchmarks << Rgot::InternalBenchmark.new(test_module, m)
107
+ end
108
+
109
+ methods.grep(/\Aexample_?/).each do |m|
110
+ examples << Rgot::InternalExample.new(test_module, m)
111
+ end
112
+
113
+ duration = Rgot.now
114
+ at_exit do
115
+ template = "%s\t%s\t%.3fs"
116
+
117
+ case $!
118
+ when SystemExit
119
+ if $!.success?
120
+ # exit 0
121
+ puts sprintf(template, "ok ", test_module, Rgot.now - duration)
122
+ else
123
+ # exit 1
124
+ puts "exit status #{$!.status}"
125
+ puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
126
+ end
127
+ when NilClass
128
+ # not raise, not exit
129
+ else
130
+ # any exception
131
+ puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
132
+ end
133
+ end
134
+ m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
135
+ if main
136
+ main.module.extend main.module
137
+ main.module.instance_method(main.name).bind(main.module).call(m)
138
+ else
139
+ exit m.run
140
+ end
141
+ end
142
+ end
143
+ ensure
144
+ _, status = Process.waitpid2(pid)
145
+ unless status.success?
146
+ code = 1
147
+ end
148
+ end
149
+ end
150
+
151
+ exit code
152
+ end
153
+ end
154
+ end
data/lib/rgot/m.rb CHANGED
@@ -108,13 +108,13 @@ module Rgot
108
108
  start = Rgot.now
109
109
  example.module.extend(example.module)
110
110
  method = example.module.instance_method(example.name).bind(example.module)
111
- out, err = capture do
111
+ out, _ = capture do
112
112
  method.call
113
113
  end
114
114
  file = method.source_location[0]
115
115
  r = ExampleParser.new(File.read(file))
116
116
  r.parse
117
- e = r.examples.find { |e| e.name == example.name }
117
+ e = r.examples.find { |re| re.name == example.name }
118
118
 
119
119
  duration = Rgot.now - start
120
120
  if e && e.output.strip != out.strip
data/lib/rgot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rgot
2
- VERSION = "0.2.0"
2
+ VERSION = "1.1.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.2.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,8 +46,8 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - ".github/workflows/main.yml"
49
50
  - ".gitignore"
50
- - ".travis.yml"
51
51
  - Gemfile
52
52
  - LICENSE.txt
53
53
  - README.md
@@ -56,6 +56,7 @@ files:
56
56
  - lib/rgot.rb
57
57
  - lib/rgot/b.rb
58
58
  - lib/rgot/benchmark_result.rb
59
+ - lib/rgot/cli.rb
59
60
  - lib/rgot/common.rb
60
61
  - lib/rgot/example_parser.rb
61
62
  - lib/rgot/m.rb
@@ -67,7 +68,7 @@ homepage: https://github.com/ksss/rgot
67
68
  licenses:
68
69
  - MIT
69
70
  metadata: {}
70
- post_install_message:
71
+ post_install_message:
71
72
  rdoc_options: []
72
73
  require_paths:
73
74
  - lib
@@ -82,9 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  - !ruby/object:Gem::Version
83
84
  version: '0'
84
85
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.5.1
87
- signing_key:
86
+ rubygems_version: 3.4.0.dev
87
+ signing_key:
88
88
  specification_version: 4
89
89
  summary: Ruby + Golang Testing = Rgot
90
90
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.10
4
- - 2.2.4
5
- - 2.3.0
6
- notifications:
7
- email: false