opal-test-unit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +4 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/opal/test-unit.rb +1 -0
- data/lib/opal/test/unit.rb +13 -0
- data/lib/opal/test/unit/assertions.rb +55 -0
- data/lib/opal/test/unit/rake_task.rb +19 -0
- data/lib/opal/test/unit/result_printer.rb +41 -0
- data/lib/opal/test/unit/runner.rb +65 -0
- data/lib/opal/test/unit/test_case.rb +63 -0
- data/lib/opal/test/unit/version.rb +7 -0
- data/opal-test-unit.gemspec +25 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d7821a8d09b132d0d858bf9fbd2402d6038c0ff
|
4
|
+
data.tar.gz: 300dfab9eb2c7a1abd450308b89141995b213b30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dee49385dbdc8936ddf1086ca41e822378f12cdb29a61b6660d762e62705b7e62389d98a843352414810a8e0cd49687e1ff5cfba218f0bfcfa60adee9d505238
|
7
|
+
data.tar.gz: 24c72fe9ff1c451dfa40396610b58ce14edb68535580b7bf9bf77b0502262b759e96abef2dae609d27945aa739aa0f12602974881f87405a6d336254528d9793
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 youchan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Opal::Test::Unit
|
2
|
+
|
3
|
+
A test suite for Opal. It has Unit::Test like APIs.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'opal-test-unit'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install opal-test-unit
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
**Rakefile**
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require "opal/test/unit/rake_task"
|
27
|
+
|
28
|
+
Opal::Test::Unit::RakeTask.new(:default, File.expand_path("../test", __FILE__))
|
29
|
+
```
|
30
|
+
|
31
|
+
A simple example.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# test/test_test.rb
|
35
|
+
|
36
|
+
require "opal/test-unit"
|
37
|
+
|
38
|
+
class TestTest < Opal::Test::Unit::TestCase
|
39
|
+
test "test successful" do
|
40
|
+
success = true
|
41
|
+
assert(success, "success")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
$ bundle exec rake
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/youchan/opal-test-unit.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "opal/test/unit"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "test/unit"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Opal::Test::Unit
|
2
|
+
class AssertFailed < RuntimeError
|
3
|
+
attr_reader :expected, :actual
|
4
|
+
|
5
|
+
def initialize(expected, actual)
|
6
|
+
@expected = expected
|
7
|
+
@actual = actual
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Assertions
|
12
|
+
def assert(cond, message="")
|
13
|
+
unless cond
|
14
|
+
raise AssertFailed.new(true, cond, message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def refute(cond, message="")
|
19
|
+
if cond
|
20
|
+
raise AssertFailed.new(true, cond, message)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_false(cond, message="")
|
25
|
+
unless cond == false
|
26
|
+
raise AssertFailed.new(true, cond, message)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_equal(expected, actual, message="")
|
31
|
+
unless expected == actual
|
32
|
+
raise AssertFailed.new(expected, actual, message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def assert_kind_of(klass, object, message="")
|
37
|
+
unless object.kind_of?(klass)
|
38
|
+
raise AssertFailed.new(klass, object.class, message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_raises(exception, message="", &block)
|
43
|
+
raises = false
|
44
|
+
begin
|
45
|
+
block.call
|
46
|
+
rescue exception => e
|
47
|
+
raises = true
|
48
|
+
end
|
49
|
+
|
50
|
+
unless raises
|
51
|
+
raise AssertFailed.new("#{exception} will raise.", "no excetion raises.")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "opal"
|
2
|
+
require "rake"
|
3
|
+
require_relative "runner"
|
4
|
+
|
5
|
+
module Opal::Test::Unit
|
6
|
+
class RakeTask
|
7
|
+
include Rake::DSL
|
8
|
+
DEFAULT_NAME = "test:opal"
|
9
|
+
attr_reader :rake_task
|
10
|
+
|
11
|
+
def initialize(name = DEFAULT_NAME, directory, **options)
|
12
|
+
runner = Opal::Test::Unit::Runner.new(directory, **options)
|
13
|
+
desc "Run test cases on opal"
|
14
|
+
@rake_task = task name do
|
15
|
+
runner.run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Opal::Test::Unit
|
2
|
+
class ResultPrinter
|
3
|
+
def self.print_summary(result)
|
4
|
+
result.failure_messages.each do |failure_message|
|
5
|
+
puts "\e[33m" + failure_message.desc + "\e[37m"
|
6
|
+
puts "\e[31massertion failed: " + failure_message.error.message + "\e[37m"
|
7
|
+
puts "expected: \e[32m" + failure_message.error.expected.to_s + "\e[37m"
|
8
|
+
puts "actual: \e[31m" + failure_message.error.actual.to_s + "\e[37m"
|
9
|
+
puts
|
10
|
+
end
|
11
|
+
|
12
|
+
result.errors.each do |error|
|
13
|
+
puts "\e[33m" + error.desc + "\e[37m"
|
14
|
+
print "\e[31m"
|
15
|
+
puts error.error.message
|
16
|
+
if error.error.backtrace.is_a?(Array)
|
17
|
+
puts error.error.backtrace.join("\n")
|
18
|
+
else
|
19
|
+
puts error.error.backtrace
|
20
|
+
end
|
21
|
+
puts "\e[37m"
|
22
|
+
end
|
23
|
+
|
24
|
+
print "\e[32m" if result.success_count > 0
|
25
|
+
print "#{result.success_count} success, "
|
26
|
+
if result.failure_messages.count > 0
|
27
|
+
print "\e[31m"
|
28
|
+
else
|
29
|
+
print "\e[37m"
|
30
|
+
end
|
31
|
+
print "#{result.failure_messages.count} failures, "
|
32
|
+
if result.errors.count > 0
|
33
|
+
print "\e[31m"
|
34
|
+
else
|
35
|
+
print "\e[37m"
|
36
|
+
end
|
37
|
+
print "#{result.errors.count} errors."
|
38
|
+
puts
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "opal/cli_options"
|
2
|
+
require "opal/cli"
|
3
|
+
require "tmpdir"
|
4
|
+
|
5
|
+
module Opal::Test::Unit
|
6
|
+
class Runner
|
7
|
+
def initialize(directory, **options)
|
8
|
+
@directory = directory
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
tmpfile_path = "#{Dir.tmpdir}/tmp.rb"
|
14
|
+
File.open(tmpfile_path, "w") do |tmpfile|
|
15
|
+
Dir.glob("#{@directory}/**/*test.rb").each do |filename|
|
16
|
+
tmpfile.write("require \"#{filename.sub(/^#{@directory}\//, "")}\"\n")
|
17
|
+
end
|
18
|
+
tmpfile.write(<<~SRC)
|
19
|
+
require "opal/platform"
|
20
|
+
|
21
|
+
run_test = Proc.new do
|
22
|
+
result = Opal::Test::Unit::TestCase.run
|
23
|
+
|
24
|
+
Opal::Test::Unit::ResultPrinter.print_summary(result)
|
25
|
+
if result.failure_messages.count > 0 || result.errors.count > 0
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
%x(
|
31
|
+
var isNode = (typeof process !== "undefined" && typeof require !== "undefined");
|
32
|
+
if (isNode) {
|
33
|
+
run_test();
|
34
|
+
} else {
|
35
|
+
window.onload = run_test;
|
36
|
+
}
|
37
|
+
)
|
38
|
+
SRC
|
39
|
+
end
|
40
|
+
run_on_opal @directory, tmpfile_path
|
41
|
+
|
42
|
+
File.delete tmpfile_path
|
43
|
+
|
44
|
+
puts "Done."
|
45
|
+
end
|
46
|
+
|
47
|
+
def run_on_opal(dir, filename)
|
48
|
+
options_hash = {
|
49
|
+
file: File.open(filename),
|
50
|
+
filename: File.basename(filename),
|
51
|
+
load_paths: $LOAD_PATH + ["./lib", dir]
|
52
|
+
}.merge(@options)
|
53
|
+
|
54
|
+
cli = Opal::CLI.new options_hash
|
55
|
+
|
56
|
+
begin
|
57
|
+
cli.run
|
58
|
+
exit cli.exit_status
|
59
|
+
rescue Opal::CliRunners::RunnerError => e
|
60
|
+
$stderr.puts e.message
|
61
|
+
exit 72
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module Opal::Test::Unit
|
4
|
+
class TestCase
|
5
|
+
include Assertions
|
6
|
+
|
7
|
+
def self.inherited(subclass)
|
8
|
+
(@test_cases ||= []) << subclass
|
9
|
+
subclass.define_singleton_method(:test) do |desc, &block|
|
10
|
+
TestCase.register_test subclass, OpenStruct.new({ desc: desc, block: block })
|
11
|
+
end
|
12
|
+
|
13
|
+
subclass.define_singleton_method(:setup) do |&block|
|
14
|
+
TestCase.register_setup subclass, OpenStruct.new({ block: block })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.register_test(subclass, test)
|
19
|
+
((@tests ||= {})[subclass] ||= []) << test
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.register_setup(subclass, setup)
|
23
|
+
((@setups ||= {})[subclass] ||= []) << setup
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.setup(setups)
|
27
|
+
setups.each do |setup|
|
28
|
+
setup.block.call
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.run
|
33
|
+
success_count = 0
|
34
|
+
failure_messages = []
|
35
|
+
errors = []
|
36
|
+
@test_cases&.each do |test_case|
|
37
|
+
instance = test_case.new
|
38
|
+
|
39
|
+
@tests[test_case]&.each do |test|
|
40
|
+
begin
|
41
|
+
if @setups&.has_key?(test_case)
|
42
|
+
self.setup(@setups[test_case])
|
43
|
+
end
|
44
|
+
|
45
|
+
print("\e[32m")
|
46
|
+
instance.instance_eval(&test.block)
|
47
|
+
print "."
|
48
|
+
success_count += 1
|
49
|
+
rescue AssertFailed => e
|
50
|
+
print "\e[31mF\e[32m"
|
51
|
+
failure_messages << OpenStruct.new({ desc: test.desc, error: e })
|
52
|
+
rescue Exception => e
|
53
|
+
print "\e[31mE\e[32m"
|
54
|
+
errors << OpenStruct.new({ desc: test.desc, error: e })
|
55
|
+
end
|
56
|
+
print( "\e[37m")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
puts
|
60
|
+
OpenStruct.new(success_count: success_count, failure_messages: failure_messages, errors: errors)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "opal/test/unit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "opal-test-unit"
|
7
|
+
spec.version = Opal::Test::Unit::VERSION
|
8
|
+
spec.authors = ["youchan"]
|
9
|
+
spec.email = ["youchan01@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{A unit test framework for Opal.}
|
12
|
+
spec.description = %q{A unit test framework for Opal.}
|
13
|
+
spec.homepage = "https://github.com/youchan/opal-unit-test"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test)/})
|
18
|
+
end
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency "opal"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opal-test-unit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- youchan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-03 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: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A unit test framework for Opal.
|
56
|
+
email:
|
57
|
+
- youchan01@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- lib/opal/test-unit.rb
|
70
|
+
- lib/opal/test/unit.rb
|
71
|
+
- lib/opal/test/unit/assertions.rb
|
72
|
+
- lib/opal/test/unit/rake_task.rb
|
73
|
+
- lib/opal/test/unit/result_printer.rb
|
74
|
+
- lib/opal/test/unit/runner.rb
|
75
|
+
- lib/opal/test/unit/test_case.rb
|
76
|
+
- lib/opal/test/unit/version.rb
|
77
|
+
- opal-test-unit.gemspec
|
78
|
+
homepage: https://github.com/youchan/opal-unit-test
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.13
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: A unit test framework for Opal.
|
102
|
+
test_files: []
|