Skip to content

Commit

Permalink
create method to clear temporary file used in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
take-cheeze committed Mar 8, 2014
1 parent 9fb955e commit bbf3e49
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions test/uv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def assert_uv(name, &block)
end
end

def remove_uv_test_tmpfile
UV::FS::unlink 'foo-bar/foo.txt' rescue nil
UV::FS::rmdir 'foo-bar' rescue nil
end

assert_uv('UV::getaddrinfo') do
UV::getaddrinfo("www.google.com", "http") do |x, a|
Expand Down Expand Up @@ -42,18 +46,15 @@ def assert_uv(name, &block)
end

assert_uv('UV::FS') do
remove_uv_test_tmpfile
UV::FS::mkdir("foo-bar") do
f = UV::FS::open("foo-bar/foo.txt", UV::FS::O_CREAT|UV::FS::O_WRONLY, UV::FS::S_IWRITE | UV::FS::S_IREAD)
f.write("helloworld") do
f.close do
f = UV::FS::open("foo-bar/foo.txt", UV::FS::O_RDONLY, UV::FS::S_IREAD) do
assert_equal 'hello', f.read(5)
assert_equal 'helloworld', f.read()
f.close() do
UV::FS::unlink("foo-bar/foo.txt") do
UV::FS::rmdir("foo-bar")
end
end
f.close { remove_uv_test_tmpfile }
end
end
end
Expand Down Expand Up @@ -142,29 +143,29 @@ def assert_uv(name, &block)
end

assert_uv('Process') do
remove_uv_test_tmpfile
UV::FS::mkdir 'foo-bar'

ps = UV::Process.new 'file' => 'grep', 'args' => []
ps.stdout_pipe = UV::Pipe.new 0

ps.spawn do |sig|
assert_equal 2, sig
UV::FS::rmdir 'foo-bar'
remove_uv_test_tmpfile
end
ps.stdout_pipe.read_start do |b|
assert_nil b
end
end

assert_uv('UV::FS::readdir') do
remove_uv_test_tmpfile
UV::FS::mkdir("foo-bar") do
f = UV::FS::open("foo-bar/foo.txt", UV::FS::O_CREAT|UV::FS::O_WRONLY, UV::FS::S_IWRITE | UV::FS::S_IREAD)
f.write("helloworld") do
UV::FS::readdir("foo-bar", 0) do |x,a|
assert_equal ['foo.txt'], a
UV::FS::unlink("foo-bar/foo.txt") do
UV::FS::rmdir("foo-bar")
end
remove_uv_test_tmpfile
end
end
end
Expand Down

0 comments on commit bbf3e49

Please sign in to comment.