rgot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57d8f9ab92c4012ef3961c16b85282ff90a56e10
4
+ data.tar.gz: bd531b85de9472e12bd858619b9438915ab8fcdb
5
+ SHA512:
6
+ metadata.gz: 745a54c2504ef26f67a1bbcdbc54ee87d42eeab98edefefb56f8b477833a34f078aa7aff5c2ab732464bd782d1f18b0b61fd7f2b8f383a5eb4c60c59a7b45cfa
7
+ data.tar.gz: bd09b0e3dc34cb369144ef7154eb8032c38b75b3a75b8ebd22bbd1269df1e4760c728ef3139f220ed84898a57b1d264740143c8109c85e68727f729039d93fc7
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ pkg
3
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ - 2.2.2
5
+ notifications:
6
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 ksss
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ rgot
2
+ ===
3
+
4
+ [![Build Status](https://travis-ci.org/ksss/rgot.svg)](https://travis-ci.org/ksss/rgot)
5
+
6
+ RGOT is a Ruby Golang like Testing package.
7
+
8
+ ### usage
9
+
10
+ test/sample.rb
11
+ ```ruby
12
+ class Sample
13
+ def sum(i, j)
14
+ i + j
15
+ end
16
+ end
17
+ ```
18
+
19
+ test/pass_test.rb
20
+ ```ruby
21
+ require_relative './sample'
22
+
23
+ module SampleTest
24
+ class TypeSum < Struct.new(:left, :right, :expect)
25
+ end
26
+
27
+ DATA = [
28
+ TypeSum.new(2, 3, 5),
29
+ TypeSum.new(12, 9, 21),
30
+ TypeSum.new(85, 42, 127),
31
+ ]
32
+
33
+ def test_pass(t)
34
+ s = Sample.new
35
+ DATA.each do |ts|
36
+ sum = s.sum(ts.left, ts.right)
37
+ unless sum.kind_of?(Fixnum)
38
+ t.error("expect Fixnum got #{sum.class}")
39
+ end
40
+ unless sum == ts.expect
41
+ t.error("expect 5 got #{sum}")
42
+ end
43
+ end
44
+ end
45
+ end
46
+ ```
47
+
48
+ ```
49
+ $ rgot -v test/pass_test.rb
50
+ === RUN test_pass
51
+ --- PASS: test_pass (0.00003s)
52
+ PASS
53
+ ok 0.001s
54
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "test to rgot"
4
+ task :test do |t|
5
+ target = "test/rgot_test.rb"
6
+ ruby "bin/rgot #{target}"
7
+ end
8
+
9
+ task :default => [:test]
data/bin/rgot ADDED
@@ -0,0 +1,64 @@
1
+ #! /usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rgot'
4
+
5
+ opts = {}
6
+ parser = OptionParser.new do |o|
7
+ o.on '-v', '--verbose', "log all tests" do
8
+ opts[:verbose] = true
9
+ end
10
+ end
11
+ parser.parse!(ARGV)
12
+
13
+ target = ARGV[0]
14
+
15
+ if target
16
+ if File.file?(target)
17
+ require File.expand_path(target)
18
+ elsif File.directory?(target)
19
+ Dir.glob("./#{target}/**/*_test.rb") do |i|
20
+ require i
21
+ end
22
+ else
23
+ puts USAGE
24
+ end
25
+ else
26
+ Dir.glob("./**/*_test.rb") do |i|
27
+ require i
28
+ end
29
+ end
30
+
31
+ modules = Object.constants.select { |c|
32
+ next if c == :FileTest
33
+ /.*Test\z/ =~ c
34
+ }
35
+
36
+ if 1 != modules.length
37
+ puts "can not load module. found #{modules.join(', ')}"
38
+ exit 1
39
+ end
40
+
41
+ cases = []
42
+ main = nil
43
+ c = modules.first
44
+
45
+ test_module = Object.const_get(c)
46
+ test_module.instance_methods.grep(/\Atest_.*/).sort.each do |m|
47
+ if m == :test_main && main.nil?
48
+ main = Rgot::InternalTestType.new(test_module, m)
49
+ else
50
+ cases << Rgot::InternalTestType.new(test_module, m)
51
+ end
52
+ end
53
+
54
+ m = Rgot::M.new(cases, opts)
55
+ duration = Rgot.now
56
+ at_exit {
57
+ puts sprintf("ok\t%.3fs", Rgot.now - duration)
58
+ }
59
+ if main
60
+ main.module.extend main.module
61
+ main.module.instance_method(main.name).bind(main.module).call(m)
62
+ else
63
+ exit m.run
64
+ end
data/lib/rgot.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Rgot
2
+ autoload :VERSION, 'rgot/version'
3
+ autoload :Common, 'rgot/common'
4
+ autoload :T, 'rgot/t'
5
+ autoload :M, 'rgot/m'
6
+
7
+ class InternalTestType < Struct.new(:module, :name)
8
+ end
9
+
10
+ class << self
11
+ def now
12
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,69 @@
1
+ module Rgot
2
+ class Common
3
+ def initialize
4
+ @output = ""
5
+ @failed = false
6
+ @skipped = false
7
+ @finished = false
8
+ @start = Rgot.now
9
+ end
10
+
11
+ def failed?
12
+ @failed
13
+ end
14
+
15
+ def skipped?
16
+ @skipped
17
+ end
18
+
19
+ def finished?
20
+ @finished
21
+ end
22
+
23
+ def fail!
24
+ @failed = true
25
+ end
26
+
27
+ def skip!
28
+ @skipped = true
29
+ end
30
+
31
+ def finished!
32
+ @finished = true
33
+ end
34
+
35
+ def log(*args)
36
+ internal_log(sprintf(*args))
37
+ end
38
+
39
+ def error(*args)
40
+ internal_log(sprintf(*args))
41
+ fail!
42
+ end
43
+
44
+ def fatal(msg)
45
+ internal_log(msg)
46
+ fail_now!
47
+ end
48
+
49
+ def fail_now!
50
+ fail!
51
+ @finished = true
52
+ exit 1
53
+ end
54
+
55
+ private
56
+
57
+ def decorate(str)
58
+ c = caller[2] # internal_log -> other log -> running method
59
+ path = c.sub(/:.*/, '')
60
+ line = c.match(/:(\d+?):/)[1]
61
+ relative_path = Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s
62
+ "\t#{relative_path}:#{line}: #{str}\n"
63
+ end
64
+
65
+ def internal_log(msg)
66
+ @output << decorate(msg)
67
+ end
68
+ end
69
+ end
data/lib/rgot/m.rb ADDED
@@ -0,0 +1,37 @@
1
+ module Rgot
2
+ class M
3
+ def initialize(cases, opts)
4
+ @cases = cases
5
+ @opts = opts
6
+ end
7
+
8
+ def run
9
+ test_ok = run_tests
10
+ if !test_ok
11
+ puts "FAIL"
12
+ 1
13
+ else
14
+ puts "PASS"
15
+ 0
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def run_tests
22
+ ok = true
23
+ @cases.each do |test|
24
+ t = Rgot::T.new(test.module, test.name.to_sym, @opts)
25
+ if @opts[:verbose]
26
+ puts "=== RUN #{test.name}\n"
27
+ end
28
+ t.run
29
+ t.report
30
+ if t.failed?
31
+ ok = false
32
+ end
33
+ end
34
+ ok
35
+ end
36
+ end
37
+ end
data/lib/rgot/t.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Rgot
2
+ class T < Common
3
+ def initialize(test_module, name, opts={})
4
+ super()
5
+ @module = test_module
6
+ @name = name
7
+ @opts = opts
8
+ end
9
+
10
+ def run
11
+ begin
12
+ @module.extend @module
13
+ @module.instance_method(@name).bind(@module).call(self)
14
+ finished!
15
+ rescue => e
16
+ fail!
17
+ report
18
+ raise e
19
+ end
20
+ end
21
+
22
+ def report
23
+ duration = Rgot.now - @start
24
+ template = "--- %s: %s (%.5fs)\n%s"
25
+ if failed?
26
+ printf template, "FAIL", @name, duration, @output
27
+ elsif @opts[:verbose]
28
+ if skipped?
29
+ printf template, "SKIP", @name, duration, @output
30
+ else
31
+ printf template, "PASS", @name, duration, @output
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Rgot
2
+ VERSION = "0.0.1"
3
+ end
data/rgot.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rgot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rgot"
8
+ spec.version = Rgot::VERSION
9
+ spec.authors = ["ksss"]
10
+ spec.email = ["co000ri@gmail.com"]
11
+
12
+ spec.summary = %q{The Ruby GOlang like Testing module}
13
+ spec.description = %q{rgot is golang like testing module in ruby}
14
+ spec.homepage = "https://github.com/ksss/rgot"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rgot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ksss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: rgot is golang like testing module in ruby
42
+ email:
43
+ - co000ri@gmail.com
44
+ executables:
45
+ - rgot
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/rgot
56
+ - lib/rgot.rb
57
+ - lib/rgot/common.rb
58
+ - lib/rgot/m.rb
59
+ - lib/rgot/t.rb
60
+ - lib/rgot/version.rb
61
+ - rgot.gemspec
62
+ homepage: https://github.com/ksss/rgot
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.5
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: The Ruby GOlang like Testing module
86
+ test_files: []