Commit 5ef8f18e authored by Hiroshi Mimaki's avatar Hiroshi Mimaki

Fixed mruby-io test failure on Windows platform.

parent 9c0426c9
...@@ -106,6 +106,7 @@ assert("File.readlink") do ...@@ -106,6 +106,7 @@ assert("File.readlink") do
end end
assert("File.readlink fails with non-symlink") do assert("File.readlink fails with non-symlink") do
skip "readlink is not supported on this platform" if MRubyIOTestUtil.win?
begin begin
e2 = nil e2 = nil
assert_raise(RuntimeError) { assert_raise(RuntimeError) {
...@@ -126,10 +127,6 @@ assert("File.readlink fails with non-symlink") do ...@@ -126,10 +127,6 @@ assert("File.readlink fails with non-symlink") do
end end
end end
assert('File TEST CLEANUP') do
assert_nil MRubyIOTestUtil.io_test_cleanup
end
assert('File.expand_path') do assert('File.expand_path') do
assert_equal "/", File.expand_path("..", "/tmp"), "parent path with base_dir (1)" 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)" assert_equal "/tmp", File.expand_path("..", "/tmp/mruby"), "parent path with base_dir (2)"
...@@ -194,3 +191,7 @@ assert('File.chmod') do ...@@ -194,3 +191,7 @@ assert('File.chmod') do
File.delete('chmod-test') File.delete('chmod-test')
end end
end end
assert('File TEST CLEANUP') do
assert_nil MRubyIOTestUtil.io_test_cleanup
end
...@@ -23,6 +23,7 @@ end ...@@ -23,6 +23,7 @@ end
assert('IO TEST SETUP') do assert('IO TEST SETUP') do
MRubyIOTestUtil.io_test_setup MRubyIOTestUtil.io_test_setup
$cr = MRubyIOTestUtil.win? ? 1 : 0 # "\n" include CR or not
end end
assert('IO', '15.2.20') do assert('IO', '15.2.20') do
...@@ -141,6 +142,7 @@ assert('IO#read', '15.2.20.5.14') do ...@@ -141,6 +142,7 @@ assert('IO#read', '15.2.20.5.14') do
end end
assert "IO#read(n) with n > IO::BUF_SIZE" do 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 r,w = IO.pipe
n = IO::BUF_SIZE+1 n = IO::BUF_SIZE+1
w.write 'a'*n w.write 'a'*n
...@@ -308,6 +310,7 @@ assert('IO#_read_buf') do ...@@ -308,6 +310,7 @@ assert('IO#_read_buf') do
end end
assert('IO#isatty') do assert('IO#isatty') do
skip "isatty is not supported on this platform" if MRubyIOTestUtil.win?
f1 = File.open("/dev/tty") f1 = File.open("/dev/tty")
f2 = File.open($mrbtest_io_rfname) f2 = File.open($mrbtest_io_rfname)
...@@ -370,7 +373,7 @@ assert('IO#gets') do ...@@ -370,7 +373,7 @@ assert('IO#gets') do
fd = IO.sysopen $mrbtest_io_wfname, "w" fd = IO.sysopen $mrbtest_io_wfname, "w"
io = IO.new fd, "w" io = IO.new fd, "w"
io.write "0123456789" * 2 + "\na" io.write "0123456789" * 2 + "\na"
assert_equal 22, io.pos assert_equal 22 + $cr, io.pos
io.close io.close
assert_equal true, io.closed? assert_equal true, io.closed?
...@@ -381,7 +384,7 @@ assert('IO#gets') do ...@@ -381,7 +384,7 @@ assert('IO#gets') do
# gets first line # gets first line
assert_equal "0123456789" * 2 + "\n", line, "gets first line" assert_equal "0123456789" * 2 + "\n", line, "gets first line"
assert_equal 21, line.size assert_equal 21, line.size
assert_equal 21, io.pos assert_equal 21 + $cr, io.pos
# gets second line # gets second line
assert_equal "a", io.gets, "gets second line" assert_equal "a", io.gets, "gets second line"
...@@ -399,7 +402,7 @@ assert('IO#gets - paragraph mode') do ...@@ -399,7 +402,7 @@ assert('IO#gets - paragraph mode') do
io.write "0" * 10 + "\n" io.write "0" * 10 + "\n"
io.write "1" * 10 + "\n\n" io.write "1" * 10 + "\n\n"
io.write "2" * 10 + "\n" io.write "2" * 10 + "\n"
assert_equal 34, io.pos assert_equal 34 + $cr * 4, io.pos
io.close io.close
assert_equal true, io.closed? assert_equal true, io.closed?
...@@ -516,6 +519,7 @@ assert('IO#close_on_exec') do ...@@ -516,6 +519,7 @@ assert('IO#close_on_exec') do
# IO.sysopen opens a file descripter with O_CLOEXEC flag. # IO.sysopen opens a file descripter with O_CLOEXEC flag.
assert_true io.close_on_exec? assert_true io.close_on_exec?
rescue ScriptError rescue ScriptError
io.close
skip "IO\#close_on_exec is not implemented." skip "IO\#close_on_exec is not implemented."
end end
......
...@@ -18,19 +18,8 @@ typedef int mode_t; ...@@ -18,19 +18,8 @@ typedef int mode_t;
static int static int
mkstemp(char *p) mkstemp(char *p)
{ {
char *temp, *path; _mktemp(p);
int fd; return 0;
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;
} }
static char* static char*
...@@ -63,30 +52,31 @@ mkdtemp(char *temp) ...@@ -63,30 +52,31 @@ mkdtemp(char *temp)
static mrb_value static mrb_value
mrb_io_test_io_setup(mrb_state *mrb, mrb_value self) mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
{ {
char rfname[] = "tmp.mruby-io-test.XXXXXXXX"; char rfname[] = "tmp.mruby-io-test-r.XXXXXXXX";
char wfname[] = "tmp.mruby-io-test.XXXXXXXX"; char wfname[] = "tmp.mruby-io-test-w.XXXXXXXX";
char symlinkname[] = "tmp.mruby-io-test.XXXXXXXX"; char symlinkname[] = "tmp.mruby-io-test.XXXXXXXX";
char socketname[] = "/tmp/mruby-io-test.XXXXXXXX"; char socketname[] = "/tmp/mruby-io-test.XXXXXXXX";
char msg[] = "mruby io test\n"; char msg[] = "mruby io test\n";
mode_t mask; mode_t mask;
int fd0, fd1, fd2, fd3; int fd0, fd1;
FILE *fp; FILE *fp;
#ifndef _WIN32 #if !defined(_WIN32) && !defined(_WIN64)
int fd2, fd3;
struct sockaddr_un sun0; struct sockaddr_un sun0;
#endif #endif
mask = umask(077); mask = umask(077);
fd0 = mkstemp(rfname); fd0 = mkstemp(rfname);
fd1 = mkstemp(wfname); fd1 = mkstemp(wfname);
#ifndef _WIN32 #if !defined(_WIN32) && !defined(_WIN64)
fd2 = mkstemp(symlinkname); fd2 = mkstemp(symlinkname);
fd3 = mkstemp(socketname); fd3 = mkstemp(socketname);
#endif
if (fd0 == -1 || fd1 == -1 || fd2 == -1 || fd3 == -1) { if (fd0 == -1 || fd1 == -1 || fd2 == -1 || fd3 == -1) {
mrb_raise(mrb, E_RUNTIME_ERROR, "can't create temporary file"); mrb_raise(mrb, E_RUNTIME_ERROR, "can't create temporary file");
return mrb_nil_value(); return mrb_nil_value();
} }
#endif
umask(mask); umask(mask);
mrb_gv_set(mrb, mrb_intern_cstr(mrb, "$mrbtest_io_rfname"), mrb_str_new_cstr(mrb, rfname)); 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) ...@@ -110,7 +100,7 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
} }
fclose(fp); fclose(fp);
#ifndef _WIN32 #if !defined(_WIN32) && !defined(_WIN64)
unlink(symlinkname); unlink(symlinkname);
close(fd2); close(fd2);
if (symlink(rfname, symlinkname) == -1) { if (symlink(rfname, symlinkname) == -1) {
...@@ -170,7 +160,7 @@ static mrb_value ...@@ -170,7 +160,7 @@ static mrb_value
mrb_io_test_file_setup(mrb_state *mrb, mrb_value self) mrb_io_test_file_setup(mrb_state *mrb, mrb_value self)
{ {
mrb_value ary = mrb_io_test_io_setup(mrb, 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) { if (symlink("/usr/bin", "test-bin") == -1) {
mrb_raise(mrb, E_RUNTIME_ERROR, "can't make a symbolic link"); 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) ...@@ -216,6 +206,20 @@ mrb_io_test_rmdir(mrb_state *mrb, mrb_value klass)
return mrb_true_value(); 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 void
mrb_mruby_io_gem_test(mrb_state* mrb) mrb_mruby_io_gem_test(mrb_state* mrb)
{ {
...@@ -228,4 +232,5 @@ 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, "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, "rmdir", mrb_io_test_rmdir, MRB_ARGS_REQ(1));
mrb_define_class_method(mrb, io_test, "win?", mrb_io_win_p, MRB_ARGS_NONE());
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment