mrubyc-test 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mrubyc/test/generator/attribute.rb +3 -4
- data/lib/mrubyc/test/init.rb +8 -2
- data/lib/mrubyc/test/version.rb +1 -1
- data/lib/mrubyc-ext/mrubyc_test_case.rb +24 -4
- data/lib/mrubyc-ext/object.rb +2 -0
- data/lib/mrubyc-test.rb +7 -5
- data/lib/templates/main.c.erb +43 -7
- data/lib/templates/models.rb.erb +2 -0
- data/lib/templates/test.rb.erb +15 -10
- 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: d22552c0a71b7399d7eae38faa8ae82b48b6553f8059e42f210dce7d75f127ae
|
4
|
+
data.tar.gz: 90bcd3c1c4c76f1f1db76582bf181dd2550e6a78230e9ced1f5ed9f96abfdca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454e1ba5ee921f0829c5f44cf42f34c82c812585144ff703fee4042c1bba9f7953e0480ea21e14cc361c8acf75861f125299f3b4b2993c8c884b7a21d76b451a
|
7
|
+
data.tar.gz: db8fdcfbf31995e6c3c9ca9964ebf813c09f4ad0757f9b0d5ef69f19f09e68ceb431ee1111bf5f83ce2d5d48451f3fb0a6a04519d42d1d88a7a95cabc2d7e8c6
|
@@ -19,16 +19,15 @@ module Mrubyc
|
|
19
19
|
Module.const_get(class_name.upcase)
|
20
20
|
end
|
21
21
|
unless model_class
|
22
|
-
# Deprecate 2022-06-01
|
23
|
-
#print "\e[33m"
|
24
|
-
#puts "[WARN] #{model_file} doesn't have corresponding class `#{class_name}`."
|
25
|
-
#print "\e[m"
|
26
22
|
next
|
27
23
|
end
|
28
24
|
model_class.class_eval do
|
29
25
|
def method_missing(_method_name, *_args)
|
30
26
|
# do nothing
|
31
27
|
end
|
28
|
+
def respond_to_missing?(_sym, _include_private)
|
29
|
+
super
|
30
|
+
end
|
32
31
|
end
|
33
32
|
end
|
34
33
|
# get information from test files
|
data/lib/mrubyc/test/init.rb
CHANGED
@@ -54,12 +54,18 @@ module Mrubyc
|
|
54
54
|
erb = ERB.new(File.read(File.expand_path('../../../templates/sample_test.rb.erb', __FILE__)), nil, '-')
|
55
55
|
File.write(File.join(config['test_dir'], 'sample_test.rb'), erb.result(binding))
|
56
56
|
|
57
|
+
init_main_c
|
58
|
+
|
59
|
+
puts
|
60
|
+
puts "\e[32mWelcome to mrubyc-test, the world\'s first TDD tool for mruby/c microcontroller development.\e[0m"
|
61
|
+
end
|
62
|
+
|
63
|
+
def init_main_c
|
64
|
+
config = Mrubyc::Test::Config.read(check: false)
|
57
65
|
puts ' cp test/tmp/main.c'
|
58
66
|
erb = ERB.new(File.read(File.expand_path('../../../templates/main.c.erb', __FILE__)), nil, '-')
|
59
67
|
File.write(File.join(config['test_tmp_dir'], 'main.c'), erb.result(binding))
|
60
68
|
|
61
|
-
puts
|
62
|
-
puts "\e[32mWelcome to mrubyc-test, the world\'s first TDD tool for mruby/c microcontroller development.\e[0m"
|
63
69
|
end
|
64
70
|
end
|
65
71
|
end
|
data/lib/mrubyc/test/version.rb
CHANGED
@@ -14,7 +14,7 @@ class MrubycTestCase
|
|
14
14
|
print $colors[:success] + '.' + $colors[:reset]
|
15
15
|
end
|
16
16
|
end
|
17
|
-
def failure(assertion, expected, actual, message)
|
17
|
+
def failure(assertion, expected, actual, message, error = nil)
|
18
18
|
$failures << {
|
19
19
|
class_and_method: $current_class_and_method,
|
20
20
|
path: @information[:path].to_s,
|
@@ -23,7 +23,8 @@ class MrubycTestCase
|
|
23
23
|
message: message,
|
24
24
|
assertion: assertion.to_s,
|
25
25
|
expected: expected.to_s,
|
26
|
-
actual: actual.to_ss
|
26
|
+
actual: actual.to_ss,
|
27
|
+
error: error
|
27
28
|
}
|
28
29
|
if @puts_failure_message
|
29
30
|
puts $colors[:failure] + ' ' + actual.to_ss + " (:" + assertion.to_s + ")" + $colors[:reset]
|
@@ -41,6 +42,25 @@ class MrubycTestCase
|
|
41
42
|
print $colors[:pending] + '.' + $colors[:reset]
|
42
43
|
end
|
43
44
|
|
45
|
+
def assert_raise(*errors, &block)
|
46
|
+
assertion = :assert_raise
|
47
|
+
e = nil
|
48
|
+
begin
|
49
|
+
block.call
|
50
|
+
rescue => e
|
51
|
+
errors.each do |error|
|
52
|
+
if error == e.class || (error.class == e.class && error.message == e.message)
|
53
|
+
success(assertion, errors, error)
|
54
|
+
return
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
expected = errors.map {|error|
|
59
|
+
error.message.length > 0 ? "#<#{error.class}: #{error.message}>" : "#{error.class}"
|
60
|
+
}.join(" || ")
|
61
|
+
failure(assertion, expected, (e || "[No error]"), "")
|
62
|
+
end
|
63
|
+
|
44
64
|
def assert_equal(expected, actual, message = nil)
|
45
65
|
assertion = :assert_equal
|
46
66
|
actual == expected ? success(assertion, expected, actual) : failure(assertion, expected, actual, message)
|
@@ -86,9 +106,9 @@ class MrubycTestCase
|
|
86
106
|
end
|
87
107
|
end
|
88
108
|
|
89
|
-
def description(text)
|
109
|
+
def self.description(text)
|
90
110
|
end
|
91
|
-
def desc(text)
|
111
|
+
def self.desc(text)
|
92
112
|
end
|
93
113
|
def setup
|
94
114
|
end
|
data/lib/mrubyc-ext/object.rb
CHANGED
data/lib/mrubyc-test.rb
CHANGED
@@ -50,6 +50,7 @@ module Mrubyc::Test
|
|
50
50
|
pwd = Dir.pwd
|
51
51
|
hal_path = "#{pwd}/#{config['mrubyc_src_dir']}/hal"
|
52
52
|
hal_bak_path = "#{pwd}/#{config['mrubyc_src_dir']}/~hal"
|
53
|
+
FileUtils.rm_rf hal_bak_path
|
53
54
|
FileUtils.mv(hal_path, hal_bak_path) if FileTest.exist?(hal_path)
|
54
55
|
exit_code = 0
|
55
56
|
cc = ENV['CC'].to_s.length > 0 ? ENV['CC'] : "gcc"
|
@@ -60,12 +61,12 @@ module Mrubyc::Test
|
|
60
61
|
[
|
61
62
|
"#{mrbc_path} -B test test.rb",
|
62
63
|
"#{mrbc_path} -B models models.rb",
|
63
|
-
"#{cc} -O0 -g3 -Wall -I #{pwd}/#{config['mrubyc_src_dir']} -static -o test main.c #{pwd}/#{config['mrubyc_src_dir']}/*.c #{pwd}/#{config['mrubyc_src_dir']}/hal/*.c -DMRBC_USE_MATH=1 -DMRBC_USE_HAL_POSIX #{ENV["CFLAGS"]} #{ENV["LDFLAGS"]}",
|
64
|
+
"#{cc} -O0 -g3 -Wall -I #{pwd}/#{config['mrubyc_src_dir']} -static -o test main.c #{pwd}/#{config['mrubyc_src_dir']}/*.c #{pwd}/#{config['mrubyc_src_dir']}/hal/*.c -DMRBC_INT64 -DMAX_SYMBOLS_COUNT=1000 -DMRBC_USE_MATH=1 -DMRBC_USE_HAL_POSIX #{ENV["CFLAGS"]} #{ENV["LDFLAGS"]}",
|
64
65
|
"#{qemu} ./test"
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
].each do |cmd|
|
67
|
+
puts cmd
|
68
|
+
puts
|
69
|
+
exit_code = 1 unless Kernel.system(cmd)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
ensure
|
@@ -112,6 +113,7 @@ module Mrubyc::Test
|
|
112
113
|
RBENV_VERSION will be ignored if you specify this option.
|
113
114
|
DESC
|
114
115
|
def test(testfilepath = "test/*.rb")
|
116
|
+
Mrubyc::Test::Init.init_main_c
|
115
117
|
init_env
|
116
118
|
config = Mrubyc::Test::Config.read
|
117
119
|
method_name_pattern = (%r{\A/(.*)/\Z} =~ options[:name] ? Regexp.new($1) : options[:name])
|
data/lib/templates/main.c.erb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "mrubyc.h"
|
2
2
|
#include <stdio.h>
|
3
3
|
#include <stdlib.h>
|
4
|
+
#include <stdbool.h>
|
4
5
|
#include "models.c"
|
5
6
|
#include "test.c"
|
6
7
|
|
@@ -9,15 +10,28 @@ static uint8_t my_memory_pool[MEMORY_SIZE];
|
|
9
10
|
|
10
11
|
int exit_code = 0;
|
11
12
|
|
12
|
-
static void
|
13
|
+
static void
|
14
|
+
c_exit(struct VM *vm, mrbc_value v[], int argc)
|
13
15
|
{
|
14
16
|
exit_code = GET_INT_ARG(1);
|
15
17
|
}
|
16
18
|
|
19
|
+
//================================================================
|
20
|
+
/*! Object#require
|
21
|
+
* (for PRK Firmware)
|
22
|
+
*/
|
23
|
+
static void
|
24
|
+
c_require(struct VM *vm, mrbc_value v[], int argc)
|
25
|
+
{
|
26
|
+
/* Nothing to do */
|
27
|
+
SET_NIL_RETURN();
|
28
|
+
}
|
29
|
+
|
17
30
|
//================================================================
|
18
31
|
/*! Object#instance_variable_get
|
19
32
|
*/
|
20
|
-
static void
|
33
|
+
static void
|
34
|
+
c_instance_variable_get(struct VM *vm, mrbc_value v[], int argc)
|
21
35
|
{
|
22
36
|
mrbc_kv_handle *kvh = &v[0].instance->ivar;
|
23
37
|
const char *name = (const char *)GET_STRING_ARG(1);
|
@@ -34,7 +48,8 @@ static void c_instance_variable_get(struct VM *vm, mrbc_value v[], int argc)
|
|
34
48
|
//================================================================
|
35
49
|
/*! DEBUG PRINT
|
36
50
|
*/
|
37
|
-
static void
|
51
|
+
static void
|
52
|
+
c_debugprint(struct VM *vm, mrbc_value v[], int argc)
|
38
53
|
{
|
39
54
|
console_putchar('\n');
|
40
55
|
for( int i = 0; i < 79; i++ ) { console_putchar('='); }
|
@@ -50,13 +65,34 @@ static void c_debugprint(struct VM *vm, mrbc_value v[], int argc)
|
|
50
65
|
console_putchar('\n');
|
51
66
|
}
|
52
67
|
|
53
|
-
|
68
|
+
bool
|
69
|
+
mrbc_load_model(const uint8_t *mrb)
|
70
|
+
{
|
71
|
+
mrbc_vm *vm = mrbc_vm_open(NULL);
|
72
|
+
if( vm == 0 ) {
|
73
|
+
console_printf("Error: Can't open VM.\n");
|
74
|
+
exit_code++;
|
75
|
+
return false;
|
76
|
+
}
|
77
|
+
if( mrbc_load_mrb(vm, mrb) != 0 ) {
|
78
|
+
mrbc_print_exception(&vm->exception);
|
79
|
+
exit_code++;
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
mrbc_vm_begin(vm);
|
83
|
+
mrbc_vm_run(vm);
|
84
|
+
mrbc_raw_free(vm);
|
85
|
+
return true;
|
86
|
+
}
|
87
|
+
|
88
|
+
int
|
89
|
+
main(void) {
|
54
90
|
mrbc_init(my_memory_pool, MEMORY_SIZE);
|
91
|
+
mrbc_define_method(0, mrbc_class_object, "require", c_require);
|
55
92
|
mrbc_define_method(0, mrbc_class_object, "debugprint", c_debugprint);
|
56
93
|
mrbc_define_method(0, mrbc_class_object, "exit", c_exit);
|
57
94
|
mrbc_define_method(0, mrbc_class_object, "instance_variable_get", c_instance_variable_get);
|
58
|
-
|
59
|
-
|
60
|
-
mrbc_run();
|
95
|
+
mrbc_load_model(models);
|
96
|
+
mrbc_load_model(test);
|
61
97
|
return exit_code;
|
62
98
|
}
|
data/lib/templates/models.rb.erb
CHANGED
data/lib/templates/test.rb.erb
CHANGED
@@ -56,9 +56,10 @@ def summerize
|
|
56
56
|
puts "#{index+1}) " + failure[:class_and_method] + " (:" + failure[:assertion] + ")"
|
57
57
|
print $colors[:failure]
|
58
58
|
puts " description : " + failure[:description]
|
59
|
-
puts " " + failure[:
|
60
|
-
puts "
|
61
|
-
puts "
|
59
|
+
puts " expected : " + failure[:expected] if failure[:expected].length > 0
|
60
|
+
puts " actual : " + failure[:actual] if failure[:actual]
|
61
|
+
puts " error : " + failure[:error] if failure[:error]
|
62
|
+
puts " message : " + failure[:message] if failure[:message]
|
62
63
|
print $colors[:info]
|
63
64
|
puts " # " + failure[:path] + ":" + failure[:line]
|
64
65
|
print $colors[:reset]
|
@@ -136,13 +137,17 @@ end
|
|
136
137
|
puts
|
137
138
|
$current_class_and_method = "<%= test_case[:information][:test_class_name] %>#<%= test_case[:information][:method_name] %>"
|
138
139
|
puts $current_class_and_method
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
140
|
+
begin
|
141
|
+
my_case = <%= test_case[:information][:test_class_name] %>.new(information, <%= verbose.to_s %>)
|
142
|
+
my_case.setup
|
143
|
+
my_case.<%= test_case[:information][:method_name] %>
|
144
|
+
<% if test_case[:mocks] -%>
|
145
|
+
my_case.check_mock
|
146
|
+
<% end -%>
|
147
|
+
my_case.teardown
|
148
|
+
rescue => e
|
149
|
+
my_case.failure(nil, nil, "", e.message, e.class.to_s)
|
150
|
+
end
|
146
151
|
puts
|
147
152
|
|
148
153
|
<% end -%>
|
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.8.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: 2022-07-
|
11
|
+
date: 2022-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|