diff options
| -rw-r--r-- | Rakefile | 17 | ||||
| -rw-r--r-- | benchmark/bm_app_lc_fizzbuzz.rb | 3 | ||||
| -rw-r--r-- | include/mruby/data.h | 5 | ||||
| -rw-r--r-- | mrbgems/mruby-io/test/file.rb | 16 | ||||
| -rw-r--r-- | mrbgems/mruby-io/test/gc_filedes.sh | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-io/test/io.rb | 20 | ||||
| -rw-r--r-- | mrbgems/mruby-print/mrblib/print.rb | 3 | ||||
| -rw-r--r-- | mrbgems/mruby-print/src/print.c | 1 | ||||
| -rw-r--r-- | mrbgems/mruby-sleep/src/mrb_sleep.c | 6 | ||||
| -rw-r--r-- | mrbgems/mruby-sleep/test/sleep_test.rb | 41 |
10 files changed, 42 insertions, 74 deletions
@@ -32,20 +32,25 @@ load "#{MRUBY_ROOT}/tasks/benchmark.rake" load "#{MRUBY_ROOT}/tasks/gitlab.rake" +def install_D(src, dst) + opts = { :verbose => $verbose } + FileUtils.rm_f dst, opts + FileUtils.mkdir_p File.dirname(dst), opts + FileUtils.cp src, dst, opts +end + ############################## # generic build targets, rules task :default => :all bin_path = ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin" -FileUtils.mkdir_p bin_path, { :verbose => $verbose } depfiles = MRuby.targets['host'].bins.map do |bin| install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}") source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}") file install_path => source_path do |t| - FileUtils.rm_f t.name, { :verbose => $verbose } - FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose } + install_D t.prerequisites.first, t.name end install_path @@ -78,8 +83,7 @@ MRuby.each_target do |target| install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}") file install_path => exec do |t| - FileUtils.rm_f t.name, { :verbose => $verbose } - FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose } + install_D t.prerequisites.first, t.name end depfiles += [ install_path ] elsif target == MRuby.targets['host-debug'] @@ -87,8 +91,7 @@ MRuby.each_target do |target| install_path = MRuby.targets['host-debug'].exefile("#{bin_path}/#{bin}") file install_path => exec do |t| - FileUtils.rm_f t.name, { :verbose => $verbose } - FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose } + install_D t.prerequisites.first, t.name end depfiles += [ install_path ] end diff --git a/benchmark/bm_app_lc_fizzbuzz.rb b/benchmark/bm_app_lc_fizzbuzz.rb index 26283cc3f..de8268577 100644 --- a/benchmark/bm_app_lc_fizzbuzz.rb +++ b/benchmark/bm_app_lc_fizzbuzz.rb @@ -48,5 +48,4 @@ answer = to_array(solution).map do |p| to_string(p) end -answer_str = answer.to_a -# puts answer_str +# puts answer diff --git a/include/mruby/data.h b/include/mruby/data.h index 31d6bd8fb..415684342 100644 --- a/include/mruby/data.h +++ b/include/mruby/data.h @@ -39,10 +39,11 @@ MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass #define Data_Wrap_Struct(mrb,klass,type,ptr)\ mrb_data_object_alloc(mrb,klass,ptr,type) -#define Data_Make_Struct(mrb,klass,strct,type,sval,data) do { \ +#define Data_Make_Struct(mrb,klass,strct,type,sval,data_obj) do { \ + (data_obj) = Data_Wrap_Struct(mrb,klass,type,NULL);\ (sval) = mrb_malloc(mrb, sizeof(strct)); \ { static const strct zero = { 0 }; *(sval) = zero; };\ - (data) = Data_Wrap_Struct(mrb,klass,type,sval);\ + (data_obj)->data = (sval);\ } while (0) #define RDATA(obj) ((struct RData *)(mrb_ptr(obj))) diff --git a/mrbgems/mruby-io/test/file.rb b/mrbgems/mruby-io/test/file.rb index 8d2be04c8..7b67ded26 100644 --- a/mrbgems/mruby-io/test/file.rb +++ b/mrbgems/mruby-io/test/file.rb @@ -1,16 +1,16 @@ ## -# IO Test +# File Test -assert('File', '15.2.21') do - File.class == Class +assert('File TEST SETUP') do + MRubyIOTestUtil.io_test_setup end -assert('File', '15.2.21.2') do - File.superclass == IO +assert('File', '15.2.21') do + assert_equal Class, File.class end -assert('File TEST SETUP') do - MRubyIOTestUtil.io_test_setup +assert('File', '15.2.21.2') do + assert_equal IO, File.superclass end assert('File#initialize', '15.2.21.4.1') do @@ -27,7 +27,7 @@ assert('File#path', '15.2.21.4.2') do assert_equal $mrbtest_io_rfname, io.path io.close assert_equal $mrbtest_io_rfname, io.path - io.closed? + assert_true io.closed? end assert('File.basename') do diff --git a/mrbgems/mruby-io/test/gc_filedes.sh b/mrbgems/mruby-io/test/gc_filedes.sh deleted file mode 100644 index 6e5d1bbf1..000000000 --- a/mrbgems/mruby-io/test/gc_filedes.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -ulimit -n 20 -mruby -e '100.times { File.open "'$0'" }' diff --git a/mrbgems/mruby-io/test/io.rb b/mrbgems/mruby-io/test/io.rb index e4a449696..881e94185 100644 --- a/mrbgems/mruby-io/test/io.rb +++ b/mrbgems/mruby-io/test/io.rb @@ -1,26 +1,6 @@ ## # IO Test -unless Object.respond_to? :assert_nothing_raised - def assert_nothing_raised(*exp) - ret = true - if $mrbtest_assert - $mrbtest_assert_idx += 1 - msg = exp.last.class == String ? exp.pop : "" - begin - yield - rescue Exception => e - msg = "#{msg} exception raised." - diff = " Class: <#{e.class}>\n" + - " Message: #{e.message}" - $mrbtest_assert.push([$mrbtest_assert_idx, msg, diff]) - ret = false - end - end - ret - end -end - assert('IO TEST SETUP') do MRubyIOTestUtil.io_test_setup $cr = MRubyIOTestUtil.win? ? 1 : 0 # "\n" include CR or not diff --git a/mrbgems/mruby-print/mrblib/print.rb b/mrbgems/mruby-print/mrblib/print.rb index fa83c47de..27567d858 100644 --- a/mrbgems/mruby-print/mrblib/print.rb +++ b/mrbgems/mruby-print/mrblib/print.rb @@ -52,9 +52,6 @@ module Kernel def printf(*args) raise NotImplementedError.new('printf not available') end - def sprintf(*args) - raise NotImplementedError.new('sprintf not available') - end else def printf(*args) __printstr__(sprintf(*args)) diff --git a/mrbgems/mruby-print/src/print.c b/mrbgems/mruby-print/src/print.c index e181b06e0..f7f99fc77 100644 --- a/mrbgems/mruby-print/src/print.c +++ b/mrbgems/mruby-print/src/print.c @@ -23,7 +23,6 @@ printstr(mrb_state *mrb, mrb_value obj) char* utf8 = RSTRING_PTR(obj); int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8, mlen, NULL, 0); wchar_t* utf16 = (wchar_t*)mrb_malloc(mrb, (wlen+1) * sizeof(wchar_t)); - if (utf16 == NULL) return; if (MultiByteToWideChar(CP_UTF8, 0, utf8, mlen, utf16, wlen) > 0) { utf16[wlen] = 0; WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), diff --git a/mrbgems/mruby-sleep/src/mrb_sleep.c b/mrbgems/mruby-sleep/src/mrb_sleep.c index 0428f29eb..3f8ef90cf 100644 --- a/mrbgems/mruby-sleep/src/mrb_sleep.c +++ b/mrbgems/mruby-sleep/src/mrb_sleep.c @@ -51,7 +51,7 @@ mrb_f_sleep(mrb_state *mrb, mrb_value self) usleep(sec * 1000000); } else { - mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must be positive integer"); + mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must not be negative"); } #else mrb_int sec; @@ -60,7 +60,7 @@ mrb_f_sleep(mrb_state *mrb, mrb_value self) if (sec >= 0) { sleep(sec); } else { - mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must be positive integer"); + mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must not be negative"); } #endif end = time(0) - beg; @@ -94,7 +94,7 @@ mrb_f_usleep(mrb_state *mrb, mrb_value self) if (usec >= 0) { usleep(usec); } else { - mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must be positive integer"); + mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must not be negative integer"); } #ifdef _WIN32 diff --git a/mrbgems/mruby-sleep/test/sleep_test.rb b/mrbgems/mruby-sleep/test/sleep_test.rb index 349f169b3..f05b7a30b 100644 --- a/mrbgems/mruby-sleep/test/sleep_test.rb +++ b/mrbgems/mruby-sleep/test/sleep_test.rb @@ -1,36 +1,29 @@ -def run_with_catching_error &b - e = nil - begin - b.call - rescue => _e - e = _e - end - - return e -end - assert("sleep works") do - e = run_with_catching_error { sleep 1 } + assert_nothing_raised { sleep(1) } + assert_nothing_raised { sleep(0) } +end - assert_nil e +assert("sleep would accept non-negative float value") do + skip unless Object.const_defined?(:Float) + assert_nothing_raised { sleep(0.01) } + assert_nothing_raised { sleep(0.0) } + assert_nothing_raised { sleep(-0.0) } end -assert("sleep would not accept negative value") do - e = run_with_catching_error{ sleep(-1) } +assert("sleep would not accept negative integer value") do + assert_raise(ArgumentError) { sleep(-1) } +end - assert_not_equal e, nil - assert_equal e.class, ArgumentError +assert("sleep would not accept negative float value") do + skip unless Object.const_defined?(:Float) + assert_raise(ArgumentError) { sleep(-0.1) } end assert("usleep works") do - e = run_with_catching_error { usleep 100 } - - assert_nil e + assert_nothing_raised { usleep(100) } + assert_nothing_raised { usleep(0) } end assert("usleep would not accept negative value") do - e = run_with_catching_error{ usleep(-100) } - - assert_not_equal e, nil - assert_equal e.class, ArgumentError + assert_raise(ArgumentError) { usleep(-100) } end |
