diff options
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_io.rb | 33 | ||||
-rw-r--r-- | test/ruby/test_m17n.rb | 1 | ||||
-rw-r--r-- | test/ruby/test_process.rb | 18 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 32 | ||||
-rw-r--r-- | test/ruby/test_system.rb | 30 |
5 files changed, 90 insertions, 24 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 6cc2897f5f..6b8e6b58ce 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1776,4 +1776,37 @@ End end end end + + def test_fcntl_lock + return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform + + pad=0 + Tempfile.open(self.class.name) do |f| + r, w = IO.pipe + pid = fork do + r.close + lock = [Fcntl::F_WRLCK, IO::SEEK_SET, pad, 12, 34, 0].pack("s!s!i!L!L!i!") + f.fcntl Fcntl::F_SETLKW, lock + w.syswrite "." + sleep + end + w.close + assert_equal ".", r.read(1) + r.close + pad = 0 + getlock = [Fcntl::F_WRLCK, 0, pad, 0, 0, 0].pack("s!s!i!L!L!i!") + f.fcntl Fcntl::F_GETLK, getlock + + ptype, whence, pad, start, len, lockpid = getlock.unpack("s!s!i!L!L!i!") + + assert_equal(ptype, Fcntl::F_WRLCK) + assert_equal(whence, IO::SEEK_SET) + assert_equal(start, 12) + assert_equal(len, 34) + assert_equal(pid, lockpid) + + Process.kill :TERM, pid + Process.waitpid2(pid) + end + end end diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index a29d509fc4..c4bc9e6637 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -962,6 +962,7 @@ class TestM17N < Test::Unit::TestCase assert_equal("X\u3042\u3044X", "A\u3042\u3044\u3046".tr("^\u3042\u3044", "X")) assert_equal("\u3042\u3046" * 100, ("\u3042\u3044" * 100).tr("\u3044", "\u3046")) + assert_equal("Y", "\u3042".tr("^X", "Y")) end def test_tr_s diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index b45bfb9bb0..f3f3f9eb80 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -384,16 +384,20 @@ class TestProcess < Test::Unit::TestCase Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]) assert_equal("c", File.read("out").chomp) File.open("out", "w") {|f| - Process.wait Process.spawn(*ECHO["d"], f=>STDOUT, STDOUT=>f) + Process.wait Process.spawn(*ECHO["d"], STDOUT=>f) assert_equal("d", File.read("out").chomp) } - Process.wait Process.spawn(*ECHO["e"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], - 3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT) + opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} + if /mswin|mingw/ !~ RUBY_PLATFORM + opts.merge(3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT) + end + Process.wait Process.spawn(*ECHO["e"], opts) assert_equal("e", File.read("out").chomp) - Process.wait Process.spawn(*ECHO["ee"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], - 3=>0, 4=>:in, 5=>STDIN, - 6=>1, 7=>:out, 8=>STDOUT, - 9=>2, 10=>:err, 11=>STDERR) + opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} + if /mswin|mingw/ !~ RUBY_PLATFORM + opts.merge(3=>0, 4=>:in, 5=>STDIN, 6=>1, 7=>:out, 8=>STDOUT, 9=>2, 10=>:err, 11=>STDERR) + end + Process.wait Process.spawn(*ECHO["ee"], opts) assert_equal("ee", File.read("out").chomp) if /mswin|mingw/ !~ RUBY_PLATFORM # passing non-stdio fds is not supported on Windows diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index c5d3a53850..faa7bd670d 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1944,4 +1944,36 @@ class TestString < Test::Unit::TestCase assert_equal(S("hello world"), a) assert_equal(S("hello "), b) end + + def u(str) + str.force_encoding(Encoding::UTF_8) + end + + def test_byteslice + assert_equal("h", "hello".byteslice(0)) + assert_equal(nil, "hello".byteslice(5)) + assert_equal("o", "hello".byteslice(-1)) + assert_equal(nil, "hello".byteslice(-6)) + + assert_equal("", "hello".byteslice(0, 0)) + assert_equal("hello", "hello".byteslice(0, 6)) + assert_equal("hello", "hello".byteslice(0, 6)) + assert_equal("", "hello".byteslice(5, 1)) + assert_equal("o", "hello".byteslice(-1, 6)) + assert_equal(nil, "hello".byteslice(-6, 1)) + assert_equal(nil, "hello".byteslice(0, -1)) + + assert_equal("h", "hello".byteslice(0..0)) + assert_equal("", "hello".byteslice(5..0)) + assert_equal("o", "hello".byteslice(4..5)) + assert_equal(nil, "hello".byteslice(6..0)) + assert_equal("", "hello".byteslice(-1..0)) + assert_equal("llo", "hello".byteslice(-3..5)) + + assert_equal(u("\x81"), "\u3042".byteslice(1)) + assert_equal(u("\x81\x82"), "\u3042".byteslice(1, 2)) + assert_equal(u("\x81\x82"), "\u3042".byteslice(1..2)) + + assert_equal(u("\x82")+("\u3042"*9), ("\u3042"*10).byteslice(2, 28)) + end end diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb index bb77ad445e..f1372781cf 100644 --- a/test/ruby/test_system.rb +++ b/test/ruby/test_system.rb @@ -91,24 +91,13 @@ class TestSystem < Test::Unit::TestCase def test_system_at if /mswin|mingw/ =~ RUBY_PLATFORM bug4393 = '[ruby-core:35218]' - bug4396 = '[ruby-core:35227]' # @ + builtin command assert_equal("foo\n", `@echo foo`, bug4393); assert_equal("foo\n", `@@echo foo`, bug4393); assert_equal("@@foo\n", `@@echo @@foo`, bug4393); - # "" + @ + built-in - assert_equal("@@foo\n", `"echo" @@foo`, bug4396); - assert_equal("@@foo\n", `"@@echo" @@foo`, bug4396); - assert_equal("@@foo\n", `"@@echo @@foo"`, bug4396); - assert_equal('"@foo"\n', `"echo" "@foo"`, bug4396); - - # ^ + @ + built-in - assert_equal(nil, system('^@echo foo'), bug4396); - assert_equal(nil, system('"^@echo foo"'), bug4396); - assert_equal("@foo\n", `echo ^@foo`); - + # @ + non builtin command Dir.mktmpdir("ruby_script_tmp") {|tmpdir| tmpfilename = "#{tmpdir}/ruby_script_tmp.#{$$}" @@ -116,16 +105,23 @@ class TestSystem < Test::Unit::TestCase tmp.print "foo\nbar\nbaz\n@foo"; tmp.close - # @ + non builtin command assert_match(/\Abar\nbaz\n?\z/, `@@findstr "ba" #{tmpfilename.gsub("/", "\\")}`, bug4393); - - # "" + @ + non built-in - assert_match(/\Abar\nbaz\n?\z/, `"@@findstr" "ba" #{tmpfilename.gsub("/", "\\")}`, bug4396); - assert_match(/\A@foo\n?\z/, `"@@findstr" "@foo" #{tmpfilename.gsub("/", "\\")}`, bug4396); } end end + def test_system_redirect_win + if /mswin|mingw/ !~ RUBY_PLATFORM + return + end + + cmd = "%WINDIR%/system32/ping.exe \"BFI3CHL671\" > out.txt 2>NUL" + assert_equal(false, system(cmd), '[ruby-talk:258939]'); + + cmd = "\"%WINDIR%/system32/ping.exe BFI3CHL671\" > out.txt 2>NUL" + assert_equal(false, system(cmd), '[ruby-talk:258939]'); + end + def test_empty_evstr assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]") end |