run mrbtest outside of source tree.
MODIFY
test/file.rb
test/file.rb
@@ -86,14 +86,20 @@ assert('File.realpath') do
readme_path = File._getwd + File::ALT_SEPARATOR + "README.md"
assert_equal readme_path, File.realpath("README.md")
else
- usrbin = IO.popen("cd bin; /bin/pwd -P") { |f| f.read.chomp }
- assert_equal usrbin, File.realpath("bin")
+ dir = MRubyIOTestUtil.mkdtemp("mruby-io-test.XXXXXX")
+ begin
+ dir1 = File.realpath($mrbtest_io_rfname)
+ dir2 = File.realpath("./#{dir}//./../#{$mrbtest_io_symlinkname}")
+ assert_equal dir1, dir2
+ ensure
+ MRubyIOTestUtil.rmdir dir
+ end
end
end
assert("File.readlink") do
begin
- assert_equal 'hoge', File.readlink($mrbtest_io_symlinkname)
+ assert_equal $mrbtest_io_rfname, File.readlink($mrbtest_io_symlinkname)
rescue NotImplementedError => e
skip e.message
end
@@ -101,7 +107,16 @@ end
assert("File.readlink fails with non-symlink") do
begin
- assert_raise(RuntimeError) { File.readlink($mrbtest_io_rfname) }
+ assert_raise(RuntimeError) {
+ begin
+ File.readlink($mrbtest_io_rfname)
+ rescue => e
+ if Object.const_defined?(:SystemCallError) and e.kind_of?(SystemCallError)
+ raise RuntimeError, "SystemCallError converted to RuntimeError"
+ end
+ raise e
+ end
+ }
rescue NotImplementedError => e
skip e.message
end

MODIFY
test/file_test.rb
test/file_test.rb
@@ -6,8 +6,13 @@ assert('FileTest TEST SETUP') do
end
assert("FileTest.directory?") do
- assert_equal true, FileTest.directory?(File.join(File._getwd, "mrblib"))
- assert_equal false, FileTest.directory?(File.join(File._getwd, "README.md"))
+ dir = MRubyIOTestUtil.mkdtemp("mruby-io-test.XXXXXX")
+ begin
+ assert_true FileTest.directory?(dir)
+ assert_false FileTest.directory?($mrbtest_io_rfname)
+ ensure
+ MRubyIOTestUtil.rmdir dir
+ end
end
assert("FileTest.exist?") do
@@ -23,8 +28,13 @@ assert("FileTest.exist?") do
end
assert("FileTest.file?") do
- assert_equal false, FileTest.file?(File.join(File._getwd, "mrblib"))
- assert_equal true, FileTest.file?(File.join(File._getwd, "README.md"))
+ dir = MRubyIOTestUtil.mkdtemp("mruby-io-test.XXXXXX")
+ begin
+ assert_true FileTest.file?($mrbtest_io_rfname)
+ assert_false FileTest.file?(dir)
+ ensure
+ MRubyIOTestUtil.rmdir dir
+ end
end
assert("FileTest.pipe?") do

MODIFY
test/io.rb
test/io.rb
@@ -387,13 +387,13 @@ end
assert('IO.popen') do
begin
$? = nil
- io = IO.popen("ls")
+ io = IO.popen("echo mruby-io")
assert_true io.close_on_exec?
assert_equal Fixnum, io.pid.class
- ls = io.read
- assert_equal ls.class, String
- assert_include ls, 'AUTHORS'
- assert_include ls, 'mrblib'
+
+ out = io.read
+ assert_equal out.class, String
+ assert_include out, 'mruby-io'
io.close
if Object.const_defined? :Process
@@ -401,7 +401,8 @@ assert('IO.popen') do
else
assert_equal 0, $?
end
- io.closed?
+
+ assert_true io.closed?
rescue NotImplementedError => e
skip e.message
end

MODIFY
test/mruby_io_test.c
test/mruby_io_test.c
#include "mruby.h"
#include "mruby/array.h"
+#include "mruby/error.h"
#include "mruby/string.h"
#include "mruby/variable.h"
@@ -72,7 +73,7 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
#ifndef _WIN32
unlink(symlinkname);
close(fd2);
- if (symlink("hoge", symlinkname) == -1) {
+ if (symlink(rfname, symlinkname) == -1) {
mrb_raise(mrb, E_RUNTIME_ERROR, "can't make a symbolic link");
}
@@ -147,6 +148,34 @@ mrb_io_test_file_cleanup(mrb_state *mrb, mrb_value self)
return mrb_nil_value();
}
+static mrb_value
+mrb_io_test_mkdtemp(mrb_state *mrb, mrb_value klass)
+{
+ mrb_value str;
+ char *cp;
+
+ mrb_get_args(mrb, "S", &str);
+ cp = mrb_str_to_cstr(mrb, str);
+ if (mkdtemp(cp) == NULL) {
+ mrb_sys_fail(mrb, "mkdtemp");
+ }
+ return mrb_str_new_cstr(mrb, cp);
+}
+
+static mrb_value
+mrb_io_test_rmdir(mrb_state *mrb, mrb_value klass)
+{
+ mrb_value str;
+ char *cp;
+
+ mrb_get_args(mrb, "S", &str);
+ cp = mrb_str_to_cstr(mrb, str);
+ if (rmdir(cp) == -1) {
+ mrb_sys_fail(mrb, "rmdir");
+ }
+ return mrb_true_value();
+}
+
void
mrb_mruby_io_gem_test(mrb_state* mrb)
{
@@ -157,4 +186,6 @@ mrb_mruby_io_gem_test(mrb_state* mrb)
mrb_define_class_method(mrb, io_test, "file_test_setup", mrb_io_test_file_setup, MRB_ARGS_NONE());
mrb_define_class_method(mrb, io_test, "file_test_cleanup", mrb_io_test_file_cleanup, MRB_ARGS_NONE());
+ 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));
}

run mrbtest outside of source tree.