mrubyc-test 0.7.3 → 0.8.1

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: d0754b794384ceb6dd0975a285e733bbaa317ab99ffb81454e296ae592c85ad5
4
- data.tar.gz: d385cfcfcfb3aa74017f57605327e303a670081434319a1be73eb39fc7661283
3
+ metadata.gz: c0b7fb6ef6a6220b2a6036c4ba3425c3f723ebf5354d9b8683b400d40215e07d
4
+ data.tar.gz: 81222c6532836e95f7b605a146136cfebc6f127f85554a121e7c9ac2b33689eb
5
5
  SHA512:
6
- metadata.gz: c26a4910cf0a6c30ca47e9b780003f0b4bc2df4ab047e80213b81b19deec7d1ac758334130adec6c3a34eb1d422b1df3347114dce6b7795c893cf02bfb4bba4e
7
- data.tar.gz: ee926222993eecf35bdc6243d161629a513d494cd4c02fd540e45890757dddc262eff1a673bce5744405123a196457ab119374a6a2223e3dd007f09b74b6a947
6
+ metadata.gz: df96b7eccca91fdbf41c01ee891d3b0399226ad72d81219d5241ed3efb77c51230d9530849dd648d2ac820cab3a010e2bd1af510b29906cbeffc7c57a45c373b
7
+ data.tar.gz: 77448b29e6bb4186c2f427c2159b0cb19e1cba3035d88ed711b2c16feb60a77906b31a17c65747179f781f5e816351f3ad83f88dde7e2cbc0cd6d56e680e4fbd
data/.gitignore CHANGED
@@ -15,3 +15,5 @@
15
15
  /test/
16
16
  /mrblib/
17
17
  /mrubyc_src/
18
+
19
+ .rake_tasks~
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.3"
3
+ VERSION = "0.8.1"
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,9 +50,10 @@ 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
- cc = ENV['CC'].length > 0 ? ENV['CC'] : "gcc"
56
+ cc = ENV['CC'].to_s.length > 0 ? ENV['CC'] : "gcc"
56
57
  qemu = ENV['QEMU']
57
58
  begin
58
59
  FileUtils.ln_sf "#{pwd}/#{config['test_tmp_dir']}/hal", "#{pwd}/#{config['mrubyc_src_dir']}/hal"
@@ -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
- ].each do |cmd|
66
- puts cmd
67
- puts
68
- exit_code = 1 unless system(cmd)
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])
@@ -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,37 @@ 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 );
95
+ mrbc_load_model(models);
96
+ mrbc_load_model(test);
97
+ /* test should be a task so that methods like sleep work */
98
+ mrbc_create_task(test, 0);
60
99
  mrbc_run();
61
100
  return exit_code;
62
101
  }
@@ -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
@@ -43,7 +43,8 @@ def summerize
43
43
  puts "Pendings:\n"
44
44
  $pendings.each_with_index do |pending, index|
45
45
  puts $colors[:pending]
46
- puts "#{index+1}) " + pending[:class_and_method]
46
+ print index # FIXME: picorbc's bug :thinking_face:
47
+ puts ") " + pending[:class_and_method]
47
48
  print $colors[:info]
48
49
  puts " # " + pending[:path] + ":" + pending[:line]
49
50
  puts $colors[:reset]
@@ -53,12 +54,14 @@ def summerize
53
54
  puts "Failures:\n"
54
55
  $failures.each_with_index do |failure, index|
55
56
  puts
56
- puts "#{index+1}) " + failure[:class_and_method] + " (:" + failure[:assertion] + ")"
57
+ print index # FIXME: picorbc's bug :thinking_face:
58
+ puts ") " + failure[:class_and_method] + " (:" + failure[:assertion] + ")"
57
59
  print $colors[:failure]
58
60
  puts " description : " + failure[:description]
59
- puts " " + failure[:message] if failure[:message]
60
- puts " expected : " + failure[:expected]
61
- puts " actual : " + failure[:actual]
61
+ puts " expected : " + failure[:expected] if failure[:expected].length > 0
62
+ puts " actual : " + failure[:actual] if failure[:actual]
63
+ puts " error : " + failure[:error] if failure[:error]
64
+ puts " message : " + failure[:message] if failure[:message]
62
65
  print $colors[:info]
63
66
  puts " # " + failure[:path] + ":" + failure[:line]
64
67
  print $colors[:reset]
@@ -136,13 +139,17 @@ end
136
139
  puts
137
140
  $current_class_and_method = "<%= test_case[:information][:test_class_name] %>#<%= test_case[:information][:method_name] %>"
138
141
  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
142
+ begin
143
+ my_case = <%= test_case[:information][:test_class_name] %>.new(information, <%= verbose.to_s %>)
144
+ my_case.setup
145
+ my_case.<%= test_case[:information][:method_name] %>
146
+ <% if test_case[:mocks] -%>
147
+ my_case.check_mock
148
+ <% end -%>
149
+ my_case.teardown
150
+ rescue => e
151
+ my_case.failure(nil, nil, "", e.message, e.class.to_s)
152
+ end
146
153
  puts
147
154
 
148
155
  <% 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.3
4
+ version: 0.8.1
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-27 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: []