diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-12-12 22:21:08 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-12-12 22:21:08 +0900 |
| commit | 25bee356b1d485f6f06fdbe1836d4512947f5443 (patch) | |
| tree | 82997eff86eca1409c6ff145ad1872d14036124b | |
| parent | bbb088234395efda23540d30ab5d1cb40f220d82 (diff) | |
| parent | 5ef8f18e9bab2f5855afe370c2c29df747ed199a (diff) | |
| download | mruby-25bee356b1d485f6f06fdbe1836d4512947f5443.tar.gz mruby-25bee356b1d485f6f06fdbe1836d4512947f5443.zip | |
Merge pull request #3884 from mimaki/mruby-io-test-on-windows
Fixed mruby-io test failure on Windows platform.
| -rw-r--r-- | mrbgems/mruby-io/test/file.rb | 9 | ||||
| -rw-r--r-- | mrbgems/mruby-io/test/io.rb | 10 | ||||
| -rw-r--r-- | mrbgems/mruby-io/test/mruby_io_test.c | 47 |
3 files changed, 38 insertions, 28 deletions
diff --git a/mrbgems/mruby-io/test/file.rb b/mrbgems/mruby-io/test/file.rb index da3e2aa11..e5c127746 100644 --- a/mrbgems/mruby-io/test/file.rb +++ b/mrbgems/mruby-io/test/file.rb @@ -106,6 +106,7 @@ assert("File.readlink") do end assert("File.readlink fails with non-symlink") do + skip "readlink is not supported on this platform" if MRubyIOTestUtil.win? begin e2 = nil assert_raise(RuntimeError) { @@ -126,10 +127,6 @@ assert("File.readlink fails with non-symlink") do end end -assert('File TEST CLEANUP') do - assert_nil MRubyIOTestUtil.io_test_cleanup -end - assert('File.expand_path') do assert_equal "/", File.expand_path("..", "/tmp"), "parent path with base_dir (1)" assert_equal "/tmp", File.expand_path("..", "/tmp/mruby"), "parent path with base_dir (2)" @@ -194,3 +191,7 @@ assert('File.chmod') do File.delete('chmod-test') end end + +assert('File TEST CLEANUP') do + assert_nil MRubyIOTestUtil.io_test_cleanup +end diff --git a/mrbgems/mruby-io/test/io.rb b/mrbgems/mruby-io/test/io.rb index df646977a..9a6328ea4 100644 --- a/mrbgems/mruby-io/test/io.rb +++ b/mrbgems/mruby-io/test/io.rb @@ -23,6 +23,7 @@ end assert('IO TEST SETUP') do MRubyIOTestUtil.io_test_setup + $cr = MRubyIOTestUtil.win? ? 1 : 0 # "\n" include CR or not end assert('IO', '15.2.20') do @@ -141,6 +142,7 @@ assert('IO#read', '15.2.20.5.14') do end assert "IO#read(n) with n > IO::BUF_SIZE" do + skip "pipe is not supported on this platform" if MRubyIOTestUtil.win? r,w = IO.pipe n = IO::BUF_SIZE+1 w.write 'a'*n @@ -308,6 +310,7 @@ assert('IO#_read_buf') do end assert('IO#isatty') do + skip "isatty is not supported on this platform" if MRubyIOTestUtil.win? f1 = File.open("/dev/tty") f2 = File.open($mrbtest_io_rfname) @@ -370,7 +373,7 @@ assert('IO#gets') do fd = IO.sysopen $mrbtest_io_wfname, "w" io = IO.new fd, "w" io.write "0123456789" * 2 + "\na" - assert_equal 22, io.pos + assert_equal 22 + $cr, io.pos io.close assert_equal true, io.closed? @@ -381,7 +384,7 @@ assert('IO#gets') do # gets first line assert_equal "0123456789" * 2 + "\n", line, "gets first line" assert_equal 21, line.size - assert_equal 21, io.pos + assert_equal 21 + $cr, io.pos # gets second line assert_equal "a", io.gets, "gets second line" @@ -399,7 +402,7 @@ assert('IO#gets - paragraph mode') do io.write "0" * 10 + "\n" io.write "1" * 10 + "\n\n" io.write "2" * 10 + "\n" - assert_equal 34, io.pos + assert_equal 34 + $cr * 4, io.pos io.close assert_equal true, io.closed? @@ -516,6 +519,7 @@ assert('IO#close_on_exec') do # IO.sysopen opens a file descripter with O_CLOEXEC flag. assert_true io.close_on_exec? rescue ScriptError + io.close skip "IO\#close_on_exec is not implemented." end diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c index 1b14b38d4..e0596e93d 100644 --- a/mrbgems/mruby-io/test/mruby_io_test.c +++ b/mrbgems/mruby-io/test/mruby_io_test.c @@ -18,19 +18,8 @@ typedef int mode_t; static int mkstemp(char *p) { - char *temp, *path; - int fd; - - temp = _strdup(p); - if (temp == NULL) return -1; - path = _mktemp(temp); - if (path[0] == 0) { - free(path); - return -1; - } - fd = _open(path, _O_CREAT|_O_BINARY|_O_RDWR|_O_TEMPORARY); - free(path); - return fd; + _mktemp(p); + return 0; } static char* @@ -63,30 +52,31 @@ mkdtemp(char *temp) static mrb_value mrb_io_test_io_setup(mrb_state *mrb, mrb_value self) { - char rfname[] = "tmp.mruby-io-test.XXXXXXXX"; - char wfname[] = "tmp.mruby-io-test.XXXXXXXX"; + char rfname[] = "tmp.mruby-io-test-r.XXXXXXXX"; + char wfname[] = "tmp.mruby-io-test-w.XXXXXXXX"; char symlinkname[] = "tmp.mruby-io-test.XXXXXXXX"; char socketname[] = "/tmp/mruby-io-test.XXXXXXXX"; char msg[] = "mruby io test\n"; mode_t mask; - int fd0, fd1, fd2, fd3; + int fd0, fd1; FILE *fp; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(_WIN64) + int fd2, fd3; struct sockaddr_un sun0; #endif mask = umask(077); fd0 = mkstemp(rfname); fd1 = mkstemp(wfname); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(_WIN64) fd2 = mkstemp(symlinkname); fd3 = mkstemp(socketname); -#endif if (fd0 == -1 || fd1 == -1 || fd2 == -1 || fd3 == -1) { mrb_raise(mrb, E_RUNTIME_ERROR, "can't create temporary file"); return mrb_nil_value(); } +#endif umask(mask); mrb_gv_set(mrb, mrb_intern_cstr(mrb, "$mrbtest_io_rfname"), mrb_str_new_cstr(mrb, rfname)); @@ -110,7 +100,7 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self) } fclose(fp); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(_WIN64) unlink(symlinkname); close(fd2); if (symlink(rfname, symlinkname) == -1) { @@ -170,7 +160,7 @@ static mrb_value mrb_io_test_file_setup(mrb_state *mrb, mrb_value self) { mrb_value ary = mrb_io_test_io_setup(mrb, self); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(_WIN64) if (symlink("/usr/bin", "test-bin") == -1) { mrb_raise(mrb, E_RUNTIME_ERROR, "can't make a symbolic link"); } @@ -216,6 +206,20 @@ mrb_io_test_rmdir(mrb_state *mrb, mrb_value klass) return mrb_true_value(); } +mrb_value +mrb_io_win_p(mrb_state *mrb, mrb_value klass) +{ +#if defined(_WIN32) || defined(_WIN64) +# if defined(__CYGWIN__) || defined(__CYGWIN32__) + return mrb_false_value(); +# else + return mrb_true_value(); +# endif +#else + return mrb_false_value(); +#endif +} + void mrb_mruby_io_gem_test(mrb_state* mrb) { @@ -228,4 +232,5 @@ mrb_mruby_io_gem_test(mrb_state* mrb) mrb_define_class_method(mrb, io_test, "mkdtemp", mrb_io_test_mkdtemp, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, io_test, "rmdir", mrb_io_test_rmdir, MRB_ARGS_REQ(1)); + mrb_define_class_method(mrb, io_test, "win?", mrb_io_win_p, MRB_ARGS_NONE()); } |
