diff options
Diffstat (limited to 'debian/vendor-h2o/deps/mruby-dir/test')
-rw-r--r-- | debian/vendor-h2o/deps/mruby-dir/test/dir.rb | 128 | ||||
-rw-r--r-- | debian/vendor-h2o/deps/mruby-dir/test/dirtest.c | 114 |
2 files changed, 0 insertions, 242 deletions
diff --git a/debian/vendor-h2o/deps/mruby-dir/test/dir.rb b/debian/vendor-h2o/deps/mruby-dir/test/dir.rb deleted file mode 100644 index cb1f1e3..0000000 --- a/debian/vendor-h2o/deps/mruby-dir/test/dir.rb +++ /dev/null @@ -1,128 +0,0 @@ -assert('Dir') do - assert_equal(Class, Dir.class) -end - -assert('DirTest.setup') do - DirTest.setup -end - -assert('Dir.chdir') do - assert_equal 0, Dir.chdir(DirTest.sandbox) -end - -assert('Dir.entries') do - a = Dir.entries(DirTest.sandbox) - assert_true a.include? "a" - assert_true a.include? "b" -end - -assert('Dir.exist?') do - assert_true Dir.exist?(DirTest.sandbox) - assert_false Dir.exist?(DirTest.sandbox + "/nosuchdir") -end - -assert('Dir.foreach') do - a = [] - Dir.foreach(DirTest.sandbox) { |s| a << s } - assert_true a.include? "a" - assert_true a.include? "b" -end - -assert('Dir.getwd') do - s = Dir.getwd - assert_true s.kind_of? String -end - -assert('Dir.mkdir') do - m1 = DirTest.sandbox + "/mkdir1" - m2 = DirTest.sandbox + "/mkdir2" - assert_equal 0, Dir.mkdir(m1) - assert_equal 0, Dir.mkdir(m2, 0765) -end - -assert('Dir.delete') do - s = DirTest.sandbox + "/delete" - Dir.mkdir(s) - assert_true Dir.exist?(s) - - Dir.delete(s) - assert_false Dir.exist?(s) -end - -assert('Dir.open') do - a = [] - Dir.open(DirTest.sandbox) { |d| - d.each { |s| a << s } - } - assert_true a.include? "a" - assert_true a.include? "b" -end - -assert('Dir#initialize and Dir#close') do - d = Dir.new(".") - assert_true d.instance_of? Dir - assert_nil d.close -end - -assert('Dir#close') do - d = Dir.new(".") -end - -assert('Dir#each') do - a = [] - d = Dir.open(DirTest.sandbox) - d.each { |s| a << s } - d.close - assert_true a.include? "a" - assert_true a.include? "b" -end - -assert('Dir#read') do - a = [] - d = Dir.open(DirTest.sandbox) - while s = d.read - a << s - end - d.close - assert_true a.include? "a" - assert_true a.include? "b" -end - -assert('Dir#rewind') do - d = Dir.open(DirTest.sandbox) - while d.read; end - - assert_equal d, d.rewind - - a = [] - while s = d.read - a << s - end - d.close - assert_true a.include? "a" - assert_true a.include? "b" -end - -# Note: behaviors of seekdir(3) and telldir(3) are so platform-dependent -# that we cannot write portable tests here. - -assert('Dir#tell') do - n = nil - Dir.open(DirTest.sandbox) { |d| - n = d.tell - } - assert_true n.is_a? Integer -end - -assert('Dir#seek') do - d1 = Dir.open(DirTest.sandbox) - d1.read - n = d1.tell - d1.read - d2 = d1.seek(n) - assert_equal d1, d2 -end - -assert('DirTest.teardown') do - DirTest.teardown -end diff --git a/debian/vendor-h2o/deps/mruby-dir/test/dirtest.c b/debian/vendor-h2o/deps/mruby-dir/test/dirtest.c deleted file mode 100644 index 070f23a..0000000 --- a/debian/vendor-h2o/deps/mruby-dir/test/dirtest.c +++ /dev/null @@ -1,114 +0,0 @@ -#include <sys/types.h> -#include <sys/stat.h> - -#include <dirent.h> -#include <unistd.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "mruby.h" -#include "mruby/string.h" -#include "mruby/variable.h" - - -mrb_value -mrb_dirtest_setup(mrb_state *mrb, mrb_value klass) -{ - mrb_value s; - char buf[1024]; - const char *aname = "a"; - const char *bname = "b"; - - /* save current working directory */ - if (getcwd(buf, sizeof(buf)) == NULL) { - mrb_raise(mrb, E_RUNTIME_ERROR, "getcwd() failed"); - } - mrb_cv_set(mrb, klass, mrb_intern_cstr(mrb, "pwd"), mrb_str_new_cstr(mrb, buf)); - - /* create sandbox */ - snprintf(buf, sizeof(buf), "%s/mruby-dir-test.XXXXXX", P_tmpdir); - if (mkdtemp(buf) == NULL) { - mrb_raisef(mrb, E_RUNTIME_ERROR, "mkdtemp(%S) failed", mrb_str_new_cstr(mrb, buf)); - } - s = mrb_str_new_cstr(mrb, buf); - mrb_cv_set(mrb, klass, mrb_intern_cstr(mrb, "sandbox"), s); - - /* go to sandbox */ - if (chdir(buf) == -1) { - rmdir(buf); - mrb_raisef(mrb, E_RUNTIME_ERROR, "chdir(%S) failed", s); - } - - /* make some directories in the sandbox */ - if (mkdir(aname, 0) == -1) { - chdir(".."); - rmdir(buf); - mrb_raisef(mrb, E_RUNTIME_ERROR, "mkdir(%S) failed", mrb_str_new_cstr(mrb, aname)); - } - if (mkdir(bname, 0) == -1) { - rmdir(aname); - chdir(".."); - rmdir(buf); - mrb_raisef(mrb, E_RUNTIME_ERROR, "mkdir(%S) failed", mrb_str_new_cstr(mrb, bname)); - } - - return mrb_true_value(); -} - -mrb_value -mrb_dirtest_teardown(mrb_state *mrb, mrb_value klass) -{ - mrb_value d, sandbox; - DIR *dirp; - struct dirent *dp; - const char *path; - - /* cleanup sandbox */ - sandbox = mrb_cv_get(mrb, klass, mrb_intern_cstr(mrb, "sandbox")); - path = mrb_str_to_cstr(mrb, sandbox); - - dirp = opendir(path); - while ((dp = readdir(dirp)) != NULL) { - if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) - continue; - if (rmdir(dp->d_name) == -1) { - mrb_raisef(mrb, E_RUNTIME_ERROR, "rmdir(%S) failed", mrb_str_new_cstr(mrb, dp->d_name)); - } - } - closedir(dirp); - - /* back to original pwd */ - d = mrb_cv_get(mrb, klass, mrb_intern_cstr(mrb, "pwd")); - path = mrb_str_to_cstr(mrb, d); - if (chdir(path) == -1) { - mrb_raisef(mrb, E_RUNTIME_ERROR, "chdir(%S) failed", d); - } - - /* remove sandbox directory */ - sandbox = mrb_cv_get(mrb, klass, mrb_intern_cstr(mrb, "sandbox")); - path = mrb_str_to_cstr(mrb, sandbox); - if (rmdir(path) == -1) { - mrb_raisef(mrb, E_RUNTIME_ERROR, "rmdir(%S) failed", sandbox); - } - - return mrb_true_value(); -} - -mrb_value -mrb_dirtest_sandbox(mrb_state *mrb, mrb_value klass) -{ - return mrb_cv_get(mrb, klass, mrb_intern_cstr(mrb, "sandbox")); -} - -void -mrb_mruby_dir_gem_test(mrb_state *mrb) -{ - struct RClass *c = mrb_define_module(mrb, "DirTest"); - - mrb_define_class_method(mrb, c, "sandbox", mrb_dirtest_sandbox, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, c, "setup", mrb_dirtest_setup, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, c, "teardown", mrb_dirtest_teardown, MRB_ARGS_NONE()); -} - |