mrubyc-test 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +14 -11
- data/lib/mrubyc-ext/mrubyc_test_case.rb +62 -24
- data/lib/mrubyc-test.rb +87 -48
- data/lib/mrubyc/test/generator/attribute.rb +9 -1
- data/lib/mrubyc/test/generator/script.rb +1 -1
- data/lib/mrubyc/test/init.rb +15 -6
- data/lib/mrubyc/test/version.rb +1 -1
- data/lib/mrubyc_test_case/mrubyc_test_case.rb +6 -7
- data/lib/templates/main.c.erb +1 -1
- data/lib/templates/test.rb.erb +58 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc5bc4e134fa8b9f118adf8aaa0048fa728524e2add9d4b1563115a0829f1c23
|
4
|
+
data.tar.gz: 1cf62ac75d14e2c2dfaf43f4081152665310b319348a95fc40fede060e831aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 767dceb63110ea84b2a817c8762f6939ebf65adcf066f73ee31a53322ad30898467ad2ec5a64c586288ac7e94973c8b96c2d34864ddbd6142740cdee9b7f3a8b
|
7
|
+
data.tar.gz: 96e922f553d5e8eeda9fb1e96c1909375b778c87264ec3e98376ddf55631366441c0e55c770e57154d7ef57c41750d17755c9fdec5f711d1b0bcd484767ce4af
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,11 +8,12 @@ The API design and implementation of this gem is greatly inspired by [test-unit]
|
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
11
|
-
- Tests are applicable to
|
11
|
+
- Tests are applicable to class and its instance methods written with mruby
|
12
|
+
- C code will not be covered directly though, you can test your C implementation if you write mruby wrapper class. In this case, your test class (it also written with mruby) will test an integrated circumstance of C and mruby
|
12
13
|
- Tests will run on your PC (POSIX) hereby you can write *business logic* with mruby/c apart from C API matters like microcontroler peripherals
|
13
14
|
- Simple assertions ... enough for almost firmware development though, I will increase the number of assertion
|
14
15
|
- Stub ... You can write your mruby code without peripheral implementation by C
|
15
|
-
- Mock ... You can call any method
|
16
|
+
- Mock ... You can call any method still doesn't exist
|
16
17
|
- The implementation of your application and test code will be analyzed by CRuby program, then comlpiled into mruby byte code and executed on mruby/c VM
|
17
18
|
|
18
19
|
## Installation
|
@@ -31,19 +32,23 @@ Or install it yourself as:
|
|
31
32
|
|
32
33
|
$ gem install mrubyc-test
|
33
34
|
|
35
|
+
|
34
36
|
## Usage
|
35
37
|
|
36
38
|
Assuming you are using [mrubyc-utils](https://github.com/hasumikin/mrubyc-utils) to manage your project and [rbenv](https://github.com/rbenv/rbenv) to manage Ruby versions.
|
37
|
-
It means you have `.mrubycconfig`
|
39
|
+
It means you have `.mrubycconfig` and `.ruby-version` in the top directory of your project.
|
38
40
|
|
39
41
|
Besides, you have to locate mruby model files that are the target of testing like `mrblib/models/class_name.rb`
|
40
42
|
|
43
|
+
And read [here](https://github.com/hasumikin/mrubyc-utils#wrapper-of-gem-mrubyc-test-and-mrubyc-debugger) about why you should use mrubyc-utils.
|
44
|
+
|
41
45
|
This is an example of ESP32 project:
|
42
46
|
|
43
47
|
```
|
44
48
|
~/your_project $ tree
|
45
49
|
.
|
46
|
-
├── .mrubycconfig
|
50
|
+
├── .mrubycconfig # Created by mrubyc-utils
|
51
|
+
├── .ruby-version # It should be mruby's version something like 'mruby-1.4.1'
|
47
52
|
├── Makefile
|
48
53
|
├── build
|
49
54
|
├── components
|
@@ -52,7 +57,7 @@ This is an example of ESP32 project:
|
|
52
57
|
│ └── models # Place your model class files here
|
53
58
|
│ ├── class_name.rb # The testing target `ClassName`
|
54
59
|
│ └── my_class.rb # The testing target `MyClass`
|
55
|
-
│ └──
|
60
|
+
│ └── loops
|
56
61
|
│ ├── main.rb # Loop script isn't covered by mrubyc-test. use mrubyc-debugger
|
57
62
|
│ └── sub.rb # Loop script isn't covered by mrubyc-test. use mrubyc-debugger
|
58
63
|
└── sdkconfig
|
@@ -60,15 +65,15 @@ This is an example of ESP32 project:
|
|
60
65
|
|
61
66
|
In the same directory:
|
62
67
|
|
63
|
-
$ mrubyc-test init
|
68
|
+
$ mrubyc-utils test init
|
64
69
|
|
65
70
|
Then, some directories and files will be created in your project.
|
66
71
|
Now you can run test because a sample test code was also created.
|
67
72
|
|
68
|
-
$ mrubyc-
|
73
|
+
$ mrubyc-utils test
|
69
74
|
|
70
|
-
You should get some assertion
|
71
|
-
Take a look at `test/sample_test.rb` to handle the failures and
|
75
|
+
You should get some assertion failures.
|
76
|
+
Take a look at `test/sample_test.rb` to handle the failures and find how to write your own test.
|
72
77
|
|
73
78
|
### Asserions
|
74
79
|
|
@@ -131,12 +136,10 @@ end
|
|
131
136
|
|
132
137
|
## Known problems
|
133
138
|
|
134
|
-
- `.ruby-version` should be set to a veriosn of CRuby to use mrubyc-test command although mruby/c developers want to set it like mruby-1.4.1
|
135
139
|
- You have to write stub or mock test fot all the methods still do not exist otherwise your test won't turn green
|
136
140
|
|
137
141
|
## TODO (possibly)
|
138
142
|
|
139
|
-
- Better solution of coexistence of CRuby and mruby. May be a kind of wrapper tool or rbenv plugin?
|
140
143
|
- Assertion against arguments of mock
|
141
144
|
- Other assertions like LT(<), GTE(>=), include?, ...etc.
|
142
145
|
- bla bla bla
|
@@ -1,51 +1,91 @@
|
|
1
1
|
class MrubycTestCase
|
2
|
-
def initialize(information)
|
2
|
+
def initialize(information, verbose = true)
|
3
3
|
@information = information
|
4
4
|
$mock ||= Mock.new
|
5
|
-
@puts_success_message =
|
6
|
-
@puts_failure_message =
|
7
|
-
end
|
8
|
-
def puts_information
|
9
|
-
puts
|
10
|
-
puts @information[:test_class_name] + '#' + @information[:method_name]
|
5
|
+
@puts_success_message = verbose
|
6
|
+
@puts_failure_message = verbose
|
11
7
|
end
|
8
|
+
|
12
9
|
def success(assertion, expected, actual)
|
13
|
-
puts_information
|
14
10
|
$success_count += 1
|
15
11
|
if @puts_success_message
|
16
|
-
puts $colors[:success] + '
|
17
|
-
puts $colors[:success] + ' result : ' + actual.to_ss + $colors[:normal]
|
12
|
+
puts $colors[:success] + ' ' + actual.to_ss + " (:" + assertion.to_s + ")" + $colors[:reset]
|
18
13
|
else
|
19
|
-
print $colors[:success] + '.' + $colors[:
|
14
|
+
print $colors[:success] + '.' + $colors[:reset]
|
20
15
|
end
|
21
16
|
end
|
22
17
|
def failure(assertion, expected, actual, message)
|
23
|
-
|
24
|
-
|
18
|
+
$failures << {
|
19
|
+
class_and_method: $current_class_and_method,
|
20
|
+
path: @information[:path].to_s,
|
21
|
+
line: @information[:line].to_s,
|
22
|
+
description: @information[:description].to_s,
|
23
|
+
message: message,
|
24
|
+
assertion: assertion.to_s,
|
25
|
+
expected: expected.to_s,
|
26
|
+
actual: actual.to_ss
|
27
|
+
}
|
25
28
|
if @puts_failure_message
|
26
|
-
puts $colors[:failure] + '
|
27
|
-
puts $colors[:failure] + ' line : ' + @information[:line].to_s
|
28
|
-
puts $colors[:failure] + ' description: ' + @information[:description].to_s
|
29
|
-
puts $colors[:failure] + ' ' + message if message
|
30
|
-
puts $colors[:failure] + ' assertion : ' + assertion.to_s + $colors[:normal]
|
31
|
-
puts $colors[:failure] + ' expected : ' + expected.to_ss + $colors[:normal]
|
32
|
-
puts $colors[:failure] + ' actual : ' + actual.to_ss + $colors[:normal]
|
29
|
+
puts $colors[:failure] + ' ' + actual.to_ss + " (:" + assertion.to_s + ")" + $colors[:reset]
|
33
30
|
else
|
34
|
-
print $colors[:failure] + '.' + $colors[:
|
31
|
+
print $colors[:failure] + '.' + $colors[:reset]
|
35
32
|
end
|
36
33
|
end
|
34
|
+
|
35
|
+
def pend
|
36
|
+
$pendings << {
|
37
|
+
class_and_method: $current_class_and_method,
|
38
|
+
path: @information[:path].to_s,
|
39
|
+
line: @information[:line].to_s,
|
40
|
+
}
|
41
|
+
print $colors[:pending] + '.' + $colors[:reset]
|
42
|
+
end
|
43
|
+
|
37
44
|
def assert_equal(expected, actual, message = nil)
|
38
45
|
assertion = :assert_equal
|
39
46
|
actual == expected ? success(assertion, expected, actual) : failure(assertion, expected, actual, message)
|
40
47
|
end
|
48
|
+
|
41
49
|
def assert_not_equal(expected, actual, message = nil)
|
42
50
|
assertion = :assert_not_equal
|
43
51
|
actual != expected ? success(assertion, expected, actual) : failure(assertion, expected, actual, message)
|
44
52
|
end
|
53
|
+
|
54
|
+
def assert_nil(expression, message = nil)
|
55
|
+
assertion = :assert_not_nil
|
56
|
+
expression == nil ? success(assertion, nil, expression) : failure(assertion, "nil", expression, message)
|
57
|
+
end
|
58
|
+
|
45
59
|
def assert_not_nil(expression, message = nil)
|
46
60
|
assertion = :assert_not_nil
|
47
|
-
expression != nil ? success(assertion, nil, expression) : failure(assertion, nil, expression, message)
|
61
|
+
expression != nil ? success(assertion, nil, expression) : failure(assertion, "!nil", expression, message)
|
62
|
+
end
|
63
|
+
|
64
|
+
def assert(expression, message = nil)
|
65
|
+
assertion = :assert
|
66
|
+
expression ? success(assertion, nil, expression) : failure(assertion, "!nil && !false", expression, message)
|
48
67
|
end
|
68
|
+
|
69
|
+
def assert_true(expression, message = nil)
|
70
|
+
assertion = :assert_true
|
71
|
+
expression == true ? success(assertion, nil, expression) : failure(assertion, "true", expression, message)
|
72
|
+
end
|
73
|
+
|
74
|
+
def assert_false(expression, message = nil)
|
75
|
+
assertion = :assert_false
|
76
|
+
expression == false ? success(assertion, nil, expression) : failure(assertion, "false", expression, message)
|
77
|
+
end
|
78
|
+
|
79
|
+
def assert_in_delta(expected, actual, message = nil, delta = 0.001)
|
80
|
+
assertion = :assert_in_delta
|
81
|
+
dt = actual - expected
|
82
|
+
if -delta <= dt && dt <= delta
|
83
|
+
success(assertion, expected, actual)
|
84
|
+
else
|
85
|
+
failure(assertion, expected, actual, message)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
49
89
|
def self.description(text)
|
50
90
|
end
|
51
91
|
def self.desc(text)
|
@@ -68,5 +108,3 @@ class MrubycTestCase
|
|
68
108
|
end
|
69
109
|
end
|
70
110
|
end
|
71
|
-
|
72
|
-
|
data/lib/mrubyc-test.rb
CHANGED
@@ -14,68 +14,107 @@ module Mrubyc::Test
|
|
14
14
|
class Error < StandardError; end
|
15
15
|
|
16
16
|
class Tool < Thor
|
17
|
+
default_command :test
|
18
|
+
|
17
19
|
desc 'init', 'Initialize requirements for unit test of mruby/c. Some directories and files will be created. Note that existing objects may be overridden'
|
18
20
|
def init
|
19
21
|
Mrubyc::Test::Init.run
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
no_commands do
|
25
|
+
def prepare(test_files, verbose, method_name_pattern)
|
26
|
+
config = Mrubyc::Test::Config.read
|
27
|
+
model_files = Dir.glob(File.join(Dir.pwd, config['mruby_lib_dir'], 'models', '*.rb'))
|
28
|
+
|
29
|
+
# gather attributes from your implementations and tests
|
30
|
+
attributes = Mrubyc::Test::Generator::Attribute.run(model_files: model_files, test_files: test_files)
|
31
|
+
|
32
|
+
# convert attributes into tast_cases
|
33
|
+
test_cases = Mrubyc::Test::Generator::TestCase.run(attributes)
|
34
|
+
|
35
|
+
# generate a ruby script that will be compiled by mrbc and executed in mruby/c VM
|
36
|
+
Mrubyc::Test::Generator::Script.run(model_files: model_files, test_files: test_files, test_cases: test_cases, verbose: verbose, method_name_pattern: method_name_pattern)
|
32
37
|
end
|
33
38
|
|
34
|
-
|
35
|
-
|
39
|
+
def make
|
40
|
+
config = Mrubyc::Test::Config.read
|
41
|
+
tmp_dir = File.join(Dir.pwd, config['test_tmp_dir'])
|
42
|
+
puts "cd #{tmp_dir}"
|
43
|
+
puts
|
44
|
+
exit_code = 0
|
45
|
+
pwd = Dir.pwd
|
46
|
+
mruby_version = File.read('.ruby-version').gsub("\n", '').chomp
|
47
|
+
unless mruby_version.index('mruby')
|
48
|
+
puts '.ruby-version doesn\'t set `mruby-x.x.x It is recommended to use the latest version of https://github.com/hasumikin/mrubyc-utils`'
|
49
|
+
print 'You can specify the version name of mruby [mruby-x.x.x]: '
|
50
|
+
mruby_version = STDIN.gets.chomp
|
51
|
+
end
|
52
|
+
FileUtils.mv "#{pwd}/#{config['mrubyc_src_dir']}/hal", "#{pwd}/#{config['mrubyc_src_dir']}/~hal"
|
53
|
+
begin
|
54
|
+
FileUtils.ln_s "#{pwd}/#{config['test_tmp_dir']}/hal", "#{pwd}/#{config['mrubyc_src_dir']}/hal"
|
55
|
+
Dir.chdir(tmp_dir) do
|
56
|
+
[
|
57
|
+
"RBENV_VERSION=#{mruby_version} mrbc -E -B test test.rb",
|
58
|
+
"cc #{ENV["CFLAGS"]} #{ENV["LDFLAGS"]} -I #{pwd}/#{config['mrubyc_src_dir']} -o test main.c #{pwd}/#{config['mrubyc_src_dir']}/*.c #{pwd}/#{config['mrubyc_src_dir']}/hal/*.c",
|
59
|
+
"./test"].each do |cmd|
|
60
|
+
puts cmd
|
61
|
+
puts
|
62
|
+
exit_code = system(cmd) ? 0 : 1
|
63
|
+
exit(exit_code) if exit_code > 0
|
64
|
+
end
|
65
|
+
end
|
66
|
+
ensure
|
67
|
+
FileUtils.rm "#{pwd}/#{config['mrubyc_src_dir']}/hal"
|
68
|
+
FileUtils.mv "#{pwd}/#{config['mrubyc_src_dir']}/~hal", "#{pwd}/#{config['mrubyc_src_dir']}/hal"
|
69
|
+
end
|
70
|
+
end
|
36
71
|
|
37
|
-
|
38
|
-
|
72
|
+
def init_env
|
73
|
+
ENV["CFLAGS"] ||= "-std=gnu99 -DMRBC_DEBUG -DMRBC_USE_MATH=1 -Wall"
|
74
|
+
ENV["LDFLAGS"] ||= "-Wl,--no-as-needed -lm"
|
75
|
+
end
|
39
76
|
|
40
|
-
# generate a ruby script that will be compiled by mrbc and executed in mruby/c VM
|
41
|
-
Mrubyc::Test::Generator::Script.run(model_files: model_files, test_files: test_files, test_cases: test_cases)
|
42
77
|
end
|
43
78
|
|
44
|
-
desc '
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
puts cmd
|
60
|
-
puts
|
61
|
-
exit_code = system(cmd) ? 0 : 1
|
62
|
-
end
|
63
|
-
puts
|
64
|
-
puts "cd -"
|
65
|
-
puts
|
66
|
-
end
|
67
|
-
ensure
|
68
|
-
FileUtils.rm "#{pwd}/#{config['mrubyc_src_dir']}/hal"
|
69
|
-
FileUtils.mv "#{pwd}/#{config['mrubyc_src_dir']}/~hal", "#{pwd}/#{config['mrubyc_src_dir']}/hal"
|
79
|
+
desc 'test', '[Default command] Execute test. You can specify a test file like `mrubyc-test test test/array_test.rb`'
|
80
|
+
option :every, type: :numeric, default: 10, aliases: "-e", banner: "NUMBER - To avoid Out of Memory, test will be devided up to every specified NUMBER of xxx_test.rb files"
|
81
|
+
option :verbose, type: :boolean, default: false, aliases: "-v", banner: "[true/false] - Show test result verbosely"
|
82
|
+
option :name, type: :string, aliases: "-n", banner: "NAME - Specify the NAME of tests you want to run. If you write --name='/PATTERN/', it will be processed as a regular expression. It must be single-quoted and doubled-backslash. eg) --name='/a\\\\db/' will create Regexp object `/a\\db/` and match strings like `a1b`"
|
83
|
+
def test(testfilepath = "test/*.rb")
|
84
|
+
init_env
|
85
|
+
method_name_pattern = (%r{\A/(.*)/\Z} =~ options[:name] ? Regexp.new($1) : options[:name])
|
86
|
+
test_path = if testfilepath == ""
|
87
|
+
File.join(Dir.pwd, config['test_dir'], "*.rb")
|
88
|
+
else
|
89
|
+
File.join(Dir.pwd, testfilepath)
|
90
|
+
end
|
91
|
+
Dir.glob(test_path).each_slice(options[:every]) do |test_files|
|
92
|
+
prepare(test_files, options[:verbose], method_name_pattern)
|
93
|
+
make
|
70
94
|
end
|
71
|
-
exit(exit_code)
|
72
95
|
end
|
73
96
|
|
74
|
-
desc
|
75
|
-
def
|
76
|
-
|
77
|
-
make
|
97
|
+
desc "version", "Print the version"
|
98
|
+
def version
|
99
|
+
puts "mrubyc-test v#{Mrubyc::Test::VERSION}"
|
78
100
|
end
|
101
|
+
|
102
|
+
def help(arg = nil)
|
103
|
+
super(arg)
|
104
|
+
init_env
|
105
|
+
if arg == "test"
|
106
|
+
puts
|
107
|
+
puts "Default environment variables you can change:"
|
108
|
+
puts " CFLAGS='#{ENV['CFLAGS']}'"
|
109
|
+
puts " LDFLAGS='#{ENV['LDFLAGS']}'"
|
110
|
+
puts
|
111
|
+
end
|
112
|
+
exit if arg
|
113
|
+
puts "\e[33m Note:"
|
114
|
+
puts ' It is recommended to use mrubyc-utils as a wrapper of this gem'
|
115
|
+
puts ' see https://github.com/hasumikin/mrubyc-utils#wrapper-of-gem-mrubyc-test-and-mrubyc-debugger'
|
116
|
+
puts "\e[0m"
|
117
|
+
end
|
118
|
+
|
79
119
|
end
|
80
120
|
end
|
81
|
-
|
@@ -11,7 +11,14 @@ module Mrubyc
|
|
11
11
|
# get information from model files(application code)
|
12
12
|
model_files.each do |model_file|
|
13
13
|
load model_file
|
14
|
-
|
14
|
+
class_name = File.basename(model_file, '.rb').camelize
|
15
|
+
begin
|
16
|
+
model_class = Module.const_get(class_name)
|
17
|
+
rescue NameError => e
|
18
|
+
print "\e[33;1m"
|
19
|
+
puts "Could not find class named `#{class_name}`. The file #{model_file} will be ignored"
|
20
|
+
print "\e[m"
|
21
|
+
end
|
15
22
|
model_class.class_eval do
|
16
23
|
def method_missing(_method_name, *_args)
|
17
24
|
# do nothing
|
@@ -22,6 +29,7 @@ module Mrubyc
|
|
22
29
|
method_locations = {}
|
23
30
|
description_locations = {}
|
24
31
|
double_method_locations = {}
|
32
|
+
MrubycTestCase.init_class_variables
|
25
33
|
test_files.each do |test_file|
|
26
34
|
load test_file
|
27
35
|
test_class = Module.const_get(File.basename(test_file, '.rb').camelize)
|
@@ -8,7 +8,7 @@ module Mrubyc
|
|
8
8
|
module Generator
|
9
9
|
class Script
|
10
10
|
class << self
|
11
|
-
def run(model_files: [], test_files:, test_cases:)
|
11
|
+
def run(model_files: [], test_files:, test_cases:, verbose:, method_name_pattern:)
|
12
12
|
config = Mrubyc::Test::Config.read
|
13
13
|
erb = ERB.new(File.read(File.expand_path('../../../../templates/test.rb.erb', __FILE__)), nil, '-')
|
14
14
|
mrubyc_class_dir = File.expand_path('../../../../mrubyc-ext/', __FILE__)
|
data/lib/mrubyc/test/init.rb
CHANGED
@@ -23,6 +23,20 @@ module Mrubyc
|
|
23
23
|
puts " mikdir -p #{hal_dir}"
|
24
24
|
FileUtils.mkdir_p(hal_dir)
|
25
25
|
|
26
|
+
puts " write #{config['test_tmp_dir']}/.gitignore"
|
27
|
+
File.open("#{config['test_tmp_dir']}/.gitignore", "w") do |f|
|
28
|
+
f.puts "test"
|
29
|
+
f.puts "test.rb"
|
30
|
+
f.puts "test.c"
|
31
|
+
end
|
32
|
+
|
33
|
+
if config["cruby_version"]
|
34
|
+
puts " write #{config['test_tmp_dir']}/.ruby-version"
|
35
|
+
File.open("#{config['test_tmp_dir']}/.ruby-version", "w") do |f|
|
36
|
+
f.puts config["cruby_version"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
26
40
|
Dir.chdir(hal_dir) do
|
27
41
|
puts " download from https://raw.githubusercontent.com/mrubyc/mrubyc/master/src/hal_posix/hal.h"
|
28
42
|
system 'wget https://raw.githubusercontent.com/mrubyc/mrubyc/master/src/hal_posix/hal.h'
|
@@ -43,12 +57,7 @@ module Mrubyc
|
|
43
57
|
File.write(File.join(config['test_tmp_dir'], 'main.c'), erb.result(binding))
|
44
58
|
|
45
59
|
puts
|
46
|
-
puts "\e[32mWelcome to mrubyc-test, the world\'s first TDD tool for mruby/c microcontroller development.\e[
|
47
|
-
puts "\e[33m"
|
48
|
-
puts 'Caution:'
|
49
|
-
puts 'For the time being, mrubyc-test assumes you installed mruby-1.4.1 by rbenv. So you should have `~/.rbenv/versions/mruby-1.4.1/bin.mrbc`'
|
50
|
-
puts 'Sorry for the inconvenience. It will be fixed soon!'
|
51
|
-
puts "\e[37m"
|
60
|
+
puts "\e[32mWelcome to mrubyc-test, the world\'s first TDD tool for mruby/c microcontroller development.\e[0m"
|
52
61
|
end
|
53
62
|
end
|
54
63
|
end
|
data/lib/mrubyc/test/version.rb
CHANGED
@@ -41,14 +41,13 @@ class MrubycTestCase
|
|
41
41
|
(@@added_method_names[self] ||= {}).keys
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
def init_class_variables
|
45
|
+
@@description_locations = {}
|
46
|
+
@@method_locations = {}
|
47
|
+
@@added_method_names = {}
|
48
|
+
end
|
45
49
|
|
46
|
-
|
47
|
-
def init_class_variables
|
48
|
-
@@description_locations = {}
|
49
|
-
@@method_locations = {}
|
50
|
-
@@added_method_names = {}
|
51
|
-
end
|
50
|
+
private
|
52
51
|
|
53
52
|
def method_locations
|
54
53
|
@@method_locations[self] ||= []
|
data/lib/templates/main.c.erb
CHANGED
data/lib/templates/test.rb.erb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# Genarated at: <%= Time.now %>
|
5
5
|
# Your RUBY_DESCRIPTION: <%= RUBY_DESCRIPTION %>
|
6
6
|
#
|
7
|
-
# For more information, see <%= Gem.loaded_specs['
|
7
|
+
# For more information, see <%= Gem.loaded_specs['mrubyc-test']&.homepage %>
|
8
8
|
#
|
9
9
|
|
10
10
|
if RUBY_VERSION == '1.9' && MRUBYC_VERSION
|
@@ -26,20 +26,56 @@ else
|
|
26
26
|
end
|
27
27
|
debugprint(RUBY_DESCRIPTION)
|
28
28
|
$success_count = 0
|
29
|
-
$
|
29
|
+
$failures = Array.new
|
30
|
+
$pendings = Array.new
|
30
31
|
$colors = {
|
31
|
-
|
32
|
+
reset: "\e[0m",
|
32
33
|
success: "\e[32m",
|
33
|
-
failure: "\e[31m"
|
34
|
+
failure: "\e[31m",
|
35
|
+
pending: "\e[33m",
|
36
|
+
info: "\e[36m"
|
34
37
|
}
|
35
38
|
def summerize
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
failure_count = $failures.count
|
40
|
+
pending_count = $pendings.count
|
41
|
+
if pending_count > 0
|
42
|
+
puts "Pendings:\n"
|
43
|
+
$pendings.each_with_index do |pending, index|
|
44
|
+
puts $colors[:pending]
|
45
|
+
puts "#{index+1}) " + pending[:class_and_method]
|
46
|
+
print $colors[:info]
|
47
|
+
puts " # " + pending[:path] + ":" + pending[:line]
|
48
|
+
puts $colors[:reset]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
color = if failure_count > 0
|
52
|
+
puts "Failures:\n"
|
53
|
+
$failures.each_with_index do |failure, index|
|
54
|
+
puts
|
55
|
+
puts "#{index+1}) " + failure[:class_and_method] + " (:" + failure[:assertion] + ")"
|
56
|
+
print $colors[:failure]
|
57
|
+
puts " description : " + failure[:description]
|
58
|
+
puts " " + failure[:message] if failure[:message]
|
59
|
+
puts " expected : " + failure[:expected]
|
60
|
+
puts " actual : " + failure[:actual]
|
61
|
+
print $colors[:info]
|
62
|
+
puts " # " + failure[:path] + ":" + failure[:line]
|
63
|
+
print $colors[:reset]
|
64
|
+
end
|
65
|
+
$colors[:failure]
|
66
|
+
elsif pending_count > 0
|
67
|
+
$colors[:pending]
|
68
|
+
else
|
69
|
+
$colors[:success]
|
70
|
+
end
|
71
|
+
puts "\nFinished\n"
|
72
|
+
print color
|
73
|
+
print ($success_count + failure_count).to_s + ' examples, '
|
74
|
+
print failure_count.to_s + ' failures, '
|
75
|
+
print pending_count.to_s + ' (or more) pendings'
|
76
|
+
puts $colors[:reset]
|
41
77
|
puts
|
42
|
-
(
|
78
|
+
(failure_count > 0) ? 1 : 0
|
43
79
|
end
|
44
80
|
|
45
81
|
<% %w(object hash mock mrubyc_test_case).each do |basename| -%>
|
@@ -51,10 +87,16 @@ end
|
|
51
87
|
<% end -%>
|
52
88
|
|
53
89
|
<% test_files.each do |file_name| -%>
|
54
|
-
<%= File.read(file_name)
|
90
|
+
<%= File.read(file_name).gsub(/(\bpend\b)/, '\1;return') -%>
|
55
91
|
<% end -%>
|
56
92
|
|
57
93
|
<% test_cases.each do |test_case| -%>
|
94
|
+
<% case method_name_pattern
|
95
|
+
when Regexp
|
96
|
+
next unless method_name_pattern.match?(test_case[:information][:method_name])
|
97
|
+
when String
|
98
|
+
next unless method_name_pattern == test_case[:information][:method_name]
|
99
|
+
end -%>
|
58
100
|
<% test_case[:stubs].each do |stub| -%>
|
59
101
|
class <%= stub[:class_name] %>
|
60
102
|
attr_accessor <%= stub[:instance_variables] %>
|
@@ -94,13 +136,17 @@ end
|
|
94
136
|
<% end -%>
|
95
137
|
<% end -%>
|
96
138
|
information = <%= test_case[:information].to_s %>
|
97
|
-
|
139
|
+
puts
|
140
|
+
$current_class_and_method = "<%= test_case[:information][:test_class_name] %>#<%= test_case[:information][:method_name] %>"
|
141
|
+
puts $current_class_and_method
|
142
|
+
my_case = <%= test_case[:information][:test_class_name] %>.new(information, <%= verbose.to_s %>)
|
98
143
|
my_case.setup
|
99
144
|
my_case.<%= test_case[:information][:method_name] %>
|
100
145
|
<% if test_case[:mocks] -%>
|
101
146
|
my_case.check_mock
|
102
147
|
<% end -%>
|
103
148
|
my_case.teardown
|
149
|
+
puts
|
104
150
|
|
105
151
|
<% end -%>
|
106
152
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mrubyc-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HASUMI Hitoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|