mrubyc-test 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6b6e64b49572a4c4a90f6a5a43d25309c42c91e004f6b6fc4e31ad84555d9c8
4
- data.tar.gz: 1df134d8e5a19dc3b1c46e6ee97f5a25c89df2cf4287cac84589383b831dcb3b
3
+ metadata.gz: 134dba24482cd854d18c548f67c6884f29762de6c5cff34c8dd16b33349cfc49
4
+ data.tar.gz: 16c91f515cc2507629df555eef9222be0c92fccf0e5a11b72883854e99ceb7e7
5
5
  SHA512:
6
- metadata.gz: fcb5ed97c767cb27084ccb99b5108e9556f196be113770369162362391304b46997ead657bf290b91eacb0aced27dc06051a11848b2a2570a9d69a3928d714a2
7
- data.tar.gz: a7dc49998b925f0871819bcbd2d15eeb821d35ce2a7ebb48402a412f20cfa6c57012e8cd64cd556e8d91947ed96e4546e0a8400998d316f0832eca4deb99ed5c
6
+ metadata.gz: a83d79c076b05e91f452293501776ab70d590214c84169bdb65a5c329ff10a554135077ad814b91846361a7658a9b40f919ff765a333b5cbe2be9d95c13b173a
7
+ data.tar.gz: db81ffe8ca22180eb7ac156c39d3bbaeac5c2048c60f38aa9020c5a642c0fc9f8e48d5924accd81488828224383ec4dd754c88baeb9221b55677b9a5ec0904d4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mrubyc-test (0.6.0)
4
+ mrubyc-test (0.7.0)
5
5
  activesupport (~> 6.0)
6
6
  rufo (~> 0.12)
7
7
  thor (~> 1.0)
@@ -9,36 +9,36 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.1.1)
12
+ activesupport (6.1.6)
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
  zeitwerk (~> 2.3)
18
- concurrent-ruby (1.1.7)
19
- diff-lcs (1.4.4)
20
- i18n (1.8.7)
18
+ concurrent-ruby (1.1.10)
19
+ diff-lcs (1.5.0)
20
+ i18n (1.10.0)
21
21
  concurrent-ruby (~> 1.0)
22
- minitest (5.14.3)
23
- rake (13.0.3)
24
- rspec (3.10.0)
25
- rspec-core (~> 3.10.0)
26
- rspec-expectations (~> 3.10.0)
27
- rspec-mocks (~> 3.10.0)
28
- rspec-core (3.10.1)
29
- rspec-support (~> 3.10.0)
30
- rspec-expectations (3.10.1)
22
+ minitest (5.15.0)
23
+ rake (13.0.6)
24
+ rspec (3.11.0)
25
+ rspec-core (~> 3.11.0)
26
+ rspec-expectations (~> 3.11.0)
27
+ rspec-mocks (~> 3.11.0)
28
+ rspec-core (3.11.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-expectations (3.11.0)
31
31
  diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.10.0)
33
- rspec-mocks (3.10.1)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-mocks (3.11.1)
34
34
  diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.10.0)
36
- rspec-support (3.10.1)
37
- rufo (0.12.0)
38
- thor (1.0.1)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-support (3.11.0)
37
+ rufo (0.13.0)
38
+ thor (1.2.1)
39
39
  tzinfo (2.0.4)
40
40
  concurrent-ruby (~> 1.0)
41
- zeitwerk (2.4.2)
41
+ zeitwerk (2.5.4)
42
42
 
43
43
  PLATFORMS
44
44
  ruby
data/README.md CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  mrubyc-test is an unit test framework for [mruby/c](https://github.com/mrubyc/mrubyc), supporting basic assertions, stub and mock.
6
6
 
7
- ## Acknowledgements
7
+ ## Dependency
8
8
 
9
- The API design and implementation of this gem is greatly inspired by [test-unit](https://github.com/test-unit/test-unit). Thank the great work.
9
+ - mrubyc-test 0.7.0+ depends on mrubyc 3.0+
10
10
 
11
11
  ## Features
12
12
 
@@ -38,7 +38,7 @@ Or install it yourself as:
38
38
  ## Usage
39
39
 
40
40
  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.
41
- It means you have `.mrubycconfig` and `.ruby-version` in the top directory of your project.
41
+ It means you have `Mrubycfile` and `.ruby-version` in the top directory of your project.
42
42
 
43
43
  Besides, you have to locate mruby model files that are the target of testing like `mrblib/models/class_name.rb`
44
44
 
@@ -49,8 +49,8 @@ This is an example of ESP32 project:
49
49
  ```
50
50
  ~/your_project $ tree
51
51
  .
52
- ├── .mrubycconfig # Created by mrubyc-utils
53
- ├── .ruby-version # It should be mruby's version something like 'mruby-1.4.1'
52
+ ├── Mrubycfile # Created by mrubyc-utils
53
+ ├── .ruby-version # It should be mruby's version like 'mruby-3.0.0'
54
54
  ├── Makefile
55
55
  ├── build
56
56
  ├── components
@@ -119,17 +119,17 @@ end
119
119
  ```ruby
120
120
  class Sample
121
121
  def do_other_thing
122
- is_to_be_hit()
122
+ is_to_be_hit(1, 2) # Two args for example
123
123
  end
124
124
  end
125
125
  ```
126
126
 
127
- You can test whether `#is_to_be_hit` method will be called:
127
+ You can test whether `#is_to_be_hit(v1, v2)` method will be called:
128
128
 
129
129
  ```ruby
130
130
  def mock_case
131
131
  sample_obj = Sample.new
132
- mock(sample_obj).is_to_be_hit
132
+ mock(sample_obj).is_to_be_hit(2) # `2` should be count of parameters
133
133
  sample_obj.do_other_thing
134
134
  end
135
135
  ```
@@ -144,6 +144,10 @@ end
144
144
  - Other assertions like LT(<), GTE(>=), include?, ...etc.
145
145
  - bla bla bla
146
146
 
147
+ ## Acknowledgements
148
+
149
+ The API design and implementation of this gem is greatly inspired by [test-unit](https://github.com/test-unit/test-unit). Thank the great work.
150
+
147
151
  ## Contributing
148
152
 
149
153
  Bug reports and pull requests are welcome on GitHub at https://github.com/mrubyc/mrubyc-test. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -8,21 +8,31 @@ module Mrubyc
8
8
  class Config
9
9
  class << self
10
10
  def read(check: true)
11
- FileUtils.touch('.mrubycconfig')
12
- config = YAML.load_file('.mrubycconfig')
11
+ config = YAML.load_file(mrubycfile)
13
12
  if check
14
13
  if !config || config == [] || !config['test_dir']
15
- raise 'Check if `.mrubycconfig` exists.'
14
+ raise 'Check if `Mrubycfile or .mrubycconfig` exists.'
16
15
  end
17
16
  end
18
17
  config || {}
19
18
  end
20
19
 
21
20
  def write(config)
22
- File.open('.mrubycconfig', 'r+') do |file|
21
+ File.open(mrubycfile, 'r+') do |file|
23
22
  file.write(config.to_yaml)
24
23
  end
25
24
  end
25
+
26
+ def mrubycfile
27
+ if File.exists? 'Mrubycfile'
28
+ 'Mrubycfile'
29
+ elsif File.exists? '.mrubycconfig'
30
+ '.mrubycconfig'
31
+ else
32
+ FileUtils.touch 'Mrubycfile'
33
+ 'Mrubycfile'
34
+ end
35
+ end
26
36
  end
27
37
  end
28
38
  end
@@ -13,9 +13,12 @@ module Mrubyc
13
13
  puts "loading #{model_file}"
14
14
  load model_file
15
15
  class_name = File.basename(model_file, '.rb').camelize
16
- begin
17
- model_class = Module.const_get(class_name)
18
- rescue NameError => e
16
+ model_class = if Module.const_defined?(class_name)
17
+ Module.const_get(class_name)
18
+ elsif Module.const_defined?(class_name.upcase)
19
+ Module.const_get(class_name.upcase)
20
+ end
21
+ unless model_class
19
22
  print "\e[33m"
20
23
  puts "[WARN] #{model_file} doesn't have corresponding class `#{class_name}`."
21
24
  print "\e[m"
@@ -17,11 +17,13 @@ module Mrubyc
17
17
  end
18
18
 
19
19
  def method_missing(method_name, *args)
20
+ param_size = args[0] || 0
20
21
  @@double_method_locations << {
21
22
  type: @type,
22
23
  class: @klass,
23
24
  method_name: method_name,
24
25
  args: args.to_s,
26
+ method_parameters: Array.new(param_size).map.with_index{|_, i| ('a'.ord + i).chr }.join(','),
25
27
  block: (block_given? ? yield : nil),
26
28
  label: @location.label,
27
29
  path: @location.absolute_path || @location.path,
@@ -31,6 +31,7 @@ module Mrubyc
31
31
  instance_variables: nil, # TODO
32
32
  method_name: double[:method_name].to_s,
33
33
  args: double[:args],
34
+ method_parameters: double[:method_parameters],
34
35
  return_value: double[:block],
35
36
  line: double[:line]
36
37
  }
@@ -11,12 +11,12 @@ module Mrubyc
11
11
  puts 'Initializing...'
12
12
  puts
13
13
 
14
- puts ' touch .mrubycconfig'
14
+ puts ' touch Mrubycfile'
15
15
  config = Mrubyc::Test::Config.read(check: false)
16
16
  config['test_dir'] = 'test'
17
17
  config['test_tmp_dir'] = 'test/tmp'
18
18
  config['mruby_lib_dir'] = 'mrblib'
19
- puts ' add config to .mrubycconfig'
19
+ puts ' add config to Mrubycfile'
20
20
  Mrubyc::Test::Config.write(config)
21
21
 
22
22
  hal_dir = "#{config['test_tmp_dir']}/hal"
@@ -1,5 +1,5 @@
1
1
  module Mrubyc
2
2
  module Test
3
- VERSION = "0.6.1"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
@@ -86,9 +86,9 @@ class MrubycTestCase
86
86
  end
87
87
  end
88
88
 
89
- def self.description(text)
89
+ def description(text)
90
90
  end
91
- def self.desc(text)
91
+ def desc(text)
92
92
  end
93
93
  def setup
94
94
  end
@@ -16,8 +16,8 @@ class Object
16
16
  'Array'
17
17
  when FalseClass
18
18
  'FalseClass'
19
- when Fixnum
20
- 'Fixnum'
19
+ when Integer
20
+ 'Integer'
21
21
  when Float
22
22
  'Float'
23
23
  when Hash
data/lib/mrubyc-test.rb CHANGED
@@ -56,9 +56,9 @@ module Mrubyc::Test
56
56
  FileUtils.ln_s "#{pwd}/#{config['test_tmp_dir']}/hal", "#{pwd}/#{config['mrubyc_src_dir']}/hal"
57
57
  Dir.chdir(tmp_dir) do
58
58
  [
59
- "#{mrbc_path} -E -B test test.rb",
60
- "#{mrbc_path} -E -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 #{ENV["CFLAGS"]} #{ENV["LDFLAGS"]}",
59
+ "#{mrbc_path} -B test test.rb",
60
+ "#{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_HAL_POSIX #{ENV["CFLAGS"]} #{ENV["LDFLAGS"]}",
62
62
  "./test"].each do |cmd|
63
63
  puts cmd
64
64
  puts
@@ -115,15 +115,15 @@ module Mrubyc::Test
115
115
  DESC
116
116
  def test(testfilepath = "test/*.rb")
117
117
  init_env
118
+ config = Mrubyc::Test::Config.read
118
119
  method_name_pattern = (%r{\A/(.*)/\Z} =~ options[:name] ? Regexp.new($1) : options[:name])
119
120
  test_path = if testfilepath == ""
120
121
  File.join(Dir.pwd, config['test_dir'], "*.rb")
121
122
  else
122
123
  File.join(Dir.pwd, testfilepath)
123
124
  end
124
- mrbc_path = if options[:mrbc_path]
125
- options[:mrbc_path]
126
- else
125
+ mrbc_path = options[:mrbc_path] || config['mrbc_path']
126
+ unless mrbc_path
127
127
  mruby_version = File.read('.ruby-version').gsub("\n", '').chomp
128
128
  unless mruby_version.index('mruby')
129
129
  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`'
@@ -4,27 +4,47 @@
4
4
  #include "models.c"
5
5
  #include "test.c"
6
6
 
7
- #define MEMORY_SIZE (1024*64)-1
7
+ #define MEMORY_SIZE (1024*640)-1
8
8
  static uint8_t my_memory_pool[MEMORY_SIZE];
9
9
 
10
- int exit_code;
10
+ int exit_code = 0;
11
11
 
12
- static void c_exit(mrb_vm *vm, mrb_value *v, int argc){
12
+ static void c_exit(struct VM *vm, mrbc_value v[], int argc)
13
+ {
13
14
  exit_code = GET_INT_ARG(1);
14
15
  }
15
16
 
17
+ //================================================================
18
+ /*! Object#instance_variable_get
19
+ */
20
+ static void c_instance_variable_get(struct VM *vm, mrbc_value v[], int argc)
21
+ {
22
+ mrbc_kv_handle *kvh = &v[0].instance->ivar;
23
+ const char *name = (const char *)GET_STRING_ARG(1);
24
+ for(int i = 0; i < kvh->n_stored; i++) {
25
+ if (strncmp(&name[1], symid_to_str(kvh->data[i].sym_id), strlen(name) - 1) == 0) {
26
+ SET_RETURN(kvh->data[i].value);
27
+ mrbc_incref(&kvh->data[i].value);
28
+ return;
29
+ }
30
+ }
31
+ SET_NIL_RETURN();
32
+ }
33
+
16
34
  //================================================================
17
35
  /*! DEBUG PRINT
18
36
  */
19
- static void c_debugprint(mrb_vm *vm, mrb_value *v, int argc){
37
+ static void c_debugprint(struct VM *vm, mrbc_value v[], int argc)
38
+ {
20
39
  console_putchar('\n');
21
40
  for( int i = 0; i < 79; i++ ) { console_putchar('='); }
22
41
  console_putchar('\n');
23
42
  unsigned char *message = GET_STRING_ARG(1);
24
43
  console_printf("%s\n", message);
25
- int total, used, free, fragment;
26
- mrbc_alloc_statistics( &total, &used, &free, &fragment );
27
- console_printf("Memory total:%d, used:%d, free:%d, fragment:%d\n", total, used, free, fragment );
44
+
45
+ struct MRBC_ALLOC_STATISTICS mem;
46
+ mrbc_alloc_statistics( &mem );
47
+ console_printf("Memory total:%d, used:%d, free:%d, fragment:%d\n", mem.total, mem.used, mem.free, mem.fragmentation );
28
48
  for( int i = 0; i < 79; i++ ) { console_putchar('='); }
29
49
  console_putchar('\n');
30
50
  console_putchar('\n');
@@ -34,6 +54,7 @@ int main(void) {
34
54
  mrbc_init(my_memory_pool, MEMORY_SIZE);
35
55
  mrbc_define_method(0, mrbc_class_object, "debugprint", c_debugprint);
36
56
  mrbc_define_method(0, mrbc_class_object, "exit", c_exit);
57
+ mrbc_define_method(0, mrbc_class_object, "instance_variable_get", c_instance_variable_get);
37
58
  mrbc_create_task( models, 0 );
38
59
  mrbc_create_task( test, 0 );
39
60
  mrbc_run();
@@ -7,7 +7,7 @@
7
7
  # For more information, see <%= Gem.loaded_specs['mrubyc-test']&.homepage %>
8
8
  #
9
9
 
10
- if RUBY_VERSION == '1.9' && MRUBYC_VERSION
10
+ if RUBY_ENGINE == 'mruby/c'
11
11
  class Math
12
12
  end
13
13
  class Numeric
@@ -108,7 +108,7 @@ end
108
108
  <% end -%>
109
109
  <% test_case[:mocks].each do |mock| -%>
110
110
  class <%= mock[:class_name] %>
111
- def <%= mock[:method_name] %>
111
+ def <%= mock[:method_name] %>(<%= mock[:method_parameters] %>)
112
112
  $mock.actual.add_by_key :<%= mock[:method_name] %>
113
113
  end
114
114
  end
@@ -126,7 +126,7 @@ end
126
126
  end
127
127
  <% test_case[:mocks].each do |mock| -%>
128
128
  class <%= mock[:class_name] %>Double
129
- def <%= mock[:method_name] %>
129
+ def <%= mock[:method_name] %>(_param_size = 0)
130
130
  $mock.expected.add_by_key :<%= mock[:method_name] %>
131
131
  end
132
132
  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.6.1
4
+ version: 0.7.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: 2021-01-12 00:00:00.000000000 Z
11
+ date: 2022-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.2.3
155
+ rubygems_version: 3.3.3
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Test Framework for mruby/c