mrubyc-test 0.7.2 → 0.8.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
2
  SHA256:
3
- metadata.gz: f7e34da056a7c335a8b3815ade20bfe827209f662b882db33a71123fbd49c288
4
- data.tar.gz: 71f6afa66472fec8af924fc5d30e19ed5a5a36c85554c023ba968ba87ac05fa2
3
+ metadata.gz: d22552c0a71b7399d7eae38faa8ae82b48b6553f8059e42f210dce7d75f127ae
4
+ data.tar.gz: 90bcd3c1c4c76f1f1db76582bf181dd2550e6a78230e9ced1f5ed9f96abfdca8
5
5
  SHA512:
6
- metadata.gz: 047d016d914acfd61668bfdd3a1c5acdba0555c88c535492274b98699f83751e7e649e2ed94dec92f502fcdf824f22af6686144b3d021f1dafd08a45eafa53e5
7
- data.tar.gz: 5f8bf78d93d90e77377bc1a66ce179df33ad4b04a9930e9dbf848452688d8ab10ef511250b2242abb6469948cdd5396eb7c3c8c7bfa7293074ca06df1e7b81aa
6
+ metadata.gz: 454e1ba5ee921f0829c5f44cf42f34c82c812585144ff703fee4042c1bba9f7953e0480ea21e14cc361c8acf75861f125299f3b4b2993c8c884b7a21d76b451a
7
+ data.tar.gz: db8fdcfbf31995e6c3c9ca9964ebf813c09f4ad0757f9b0d5ef69f19f09e68ceb431ee1111bf5f83ce2d5d48451f3fb0a6a04519d42d1d88a7a95cabc2d7e8c6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mrubyc-test (0.7.1)
4
+ mrubyc-test (0.7.4)
5
5
  activesupport (~> 7.0)
6
6
  rufo (~> 0.12)
7
7
  thor (~> 1.2)
@@ -9,16 +9,16 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.3)
12
+ activesupport (7.0.3.1)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
16
16
  tzinfo (~> 2.0)
17
17
  concurrent-ruby (1.1.10)
18
18
  diff-lcs (1.5.0)
19
- i18n (1.10.0)
19
+ i18n (1.12.0)
20
20
  concurrent-ruby (~> 1.0)
21
- minitest (5.15.0)
21
+ minitest (5.16.2)
22
22
  rake (13.0.6)
23
23
  rspec (3.11.0)
24
24
  rspec-core (~> 3.11.0)
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Mrubyc
2
2
  module Test
3
- VERSION = "0.7.2"
3
+ VERSION = "0.8.0"
4
4
  end
5
5
  end
@@ -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
@@ -4,6 +4,8 @@ class Object
4
4
  'nil [NilClass]'
5
5
  elsif self == ''
6
6
  '[NULL String]'
7
+ elsif self.class.to_s.end_with? "Error"
8
+ "#<#{self.class}: #{self.message}>"
7
9
  else
8
10
  self.to_s + ' [' + self.class_name + ']'
9
11
  end
data/lib/mrubyc-test.rb CHANGED
@@ -50,20 +50,23 @@ 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
56
+ cc = ENV['CC'].to_s.length > 0 ? ENV['CC'] : "gcc"
57
+ qemu = ENV['QEMU']
55
58
  begin
56
59
  FileUtils.ln_sf "#{pwd}/#{config['test_tmp_dir']}/hal", "#{pwd}/#{config['mrubyc_src_dir']}/hal"
57
60
  Dir.chdir(tmp_dir) do
58
61
  [
59
62
  "#{mrbc_path} -B test test.rb",
60
63
  "#{mrbc_path} -B models models.rb",
61
- "cc -O0 -g3 -Wall -I #{pwd}/#{config['mrubyc_src_dir']} -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"]}",
62
- "./test"
63
- ].each do |cmd|
64
- puts cmd
65
- puts
66
- exit_code = 1 unless system(cmd)
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"]}",
65
+ "#{qemu} ./test"
66
+ ].each do |cmd|
67
+ puts cmd
68
+ puts
69
+ exit_code = 1 unless Kernel.system(cmd)
67
70
  end
68
71
  end
69
72
  ensure
@@ -110,6 +113,7 @@ module Mrubyc::Test
110
113
  RBENV_VERSION will be ignored if you specify this option.
111
114
  DESC
112
115
  def test(testfilepath = "test/*.rb")
116
+ Mrubyc::Test::Init.init_main_c
113
117
  init_env
114
118
  config = Mrubyc::Test::Config.read
115
119
  method_name_pattern = (%r{\A/(.*)/\Z} =~ options[:name] ? Regexp.new($1) : options[:name])
@@ -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 c_exit(struct VM *vm, mrbc_value v[], int argc)
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 c_instance_variable_get(struct VM *vm, mrbc_value v[], int argc)
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 c_debugprint(struct VM *vm, mrbc_value v[], int argc)
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
- int main(void) {
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
- mrbc_create_task( models, 0 );
59
- mrbc_create_task( test, 0 );
60
- mrbc_run();
95
+ mrbc_load_model(models);
96
+ mrbc_load_model(test);
61
97
  return exit_code;
62
98
  }
@@ -1,3 +1,5 @@
1
1
  <% model_files.each do |file_name| -%>
2
2
  <%= File.read(file_name) %>
3
3
  <% end -%>
4
+
5
+ $mutex = true
@@ -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[:message] if failure[:message]
60
- puts " expected : " + failure[:expected]
61
- puts " actual : " + failure[:actual]
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
- my_case = <%= test_case[:information][:test_class_name] %>.new(information, <%= verbose.to_s %>)
140
- my_case.setup
141
- my_case.<%= test_case[:information][:method_name] %>
142
- <% if test_case[:mocks] -%>
143
- my_case.check_mock
144
- <% end -%>
145
- my_case.teardown
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.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASUMI Hitoshi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,7 +137,7 @@ homepage: https://github.com/mrubyc/mrubyc-test
137
137
  licenses:
138
138
  - BSD-3-Clause
139
139
  metadata: {}
140
- post_install_message:
140
+ post_install_message:
141
141
  rdoc_options: []
142
142
  require_paths:
143
143
  - lib
@@ -152,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.3.14
156
- signing_key:
155
+ rubygems_version: 3.3.7
156
+ signing_key:
157
157
  specification_version: 4
158
158
  summary: Test Framework for mruby/c
159
159
  test_files: []