Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/compiler/semantic/warnings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe "Semantic: warnings" do
# NOTE tempfile might be created in symlinked folder
# which affects how to match current dir /var/folders/...
# with the real path /private/var/folders/...
path = File.real_path(path)
path = File.realpath(path)

main_filename = File.join(path, "main.cr")
output_filename = File.join(path, "main")
Expand Down Expand Up @@ -416,7 +416,7 @@ describe "Semantic: warnings" do
# NOTE tempfile might be created in symlinked folder
# which affects how to match current dir /var/folders/...
# with the real path /private/var/folders/...
path = File.real_path(path)
path = File.realpath(path)

main_filename = File.join(path, "main.cr")
output_filename = File.join(path, "main")
Expand Down
2 changes: 1 addition & 1 deletion spec/std/benchmark_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe Benchmark::IPS::Job do
it "works in general / integration test" do
# test several things to avoid running a benchmark over and over again in
# the specs
j = Benchmark::IPS::Job.new(0.001, 0.001, interactive: false)
j = Benchmark::IPS::Job.new(1.millisecond, 1.millisecond, interactive: false)
a = j.report("a") { sleep 1.milliseconds }
b = j.report("b") { sleep 2.milliseconds }

Expand Down
2 changes: 1 addition & 1 deletion spec/std/dir_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ describe "Dir" do
Dir.mkdir_p path
# Resolve any symbolic links in path caused by tmpdir being a link.
# For example on macOS, /tmp is a symlink to /private/tmp.
path = File.real_path(path)
path = File.realpath(path)

target_path = File.join(path, "target")
link_path = File.join(path, "link")
Expand Down
269 changes: 136 additions & 133 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -236,136 +236,6 @@ describe "File" do
end
end

describe "executable?" do
it "gives true" do
crystal = Process.executable_path || pending! "Unable to locate compiler executable"
File.executable?(crystal).should be_true
end

it "gives false" do
File.executable?(datapath("test_file.txt")).should be_false
end

it "gives false when the file doesn't exist" do
File.executable?(datapath("non_existing_file.txt")).should be_false
end

it "gives false when a component of the path is a file" do
File.executable?(datapath("dir", "test_file.txt", "")).should be_false
end

it "follows symlinks" do
with_tempfile("good_symlink_x.txt", "bad_symlink_x.txt") do |good_path, bad_path|
crystal = Process.executable_path || pending! "Unable to locate compiler executable"
File.symlink(File.expand_path(crystal), good_path)
File.symlink(File.expand_path(datapath("non_existing_file.txt")), bad_path)

File.executable?(good_path).should be_true
File.executable?(bad_path).should be_false
end
end
end

describe "readable?" do
it "gives true" do
File.readable?(datapath("test_file.txt")).should be_true
end

it "gives false when the file doesn't exist" do
File.readable?(datapath("non_existing_file.txt")).should be_false
end

it "gives false when a component of the path is a file" do
File.readable?(datapath("dir", "test_file.txt", "")).should be_false
end

# win32 doesn't have a way to make files unreadable via chmod
{% unless flag?(:win32) %}
it "gives false when the file has no read permissions" do
with_tempfile("unreadable.txt") do |path|
File.write(path, "")
File.chmod(path, 0o222)
pending_if_superuser!
File.readable?(path).should be_false
end
end

it "gives false when the file has no permissions" do
with_tempfile("unaccessible.txt") do |path|
File.write(path, "")
File.chmod(path, 0o000)
pending_if_superuser!
File.readable?(path).should be_false
end
end

it "follows symlinks" do
with_tempfile("good_symlink_r.txt", "bad_symlink_r.txt", "unreadable.txt") do |good_path, bad_path, unreadable|
File.write(unreadable, "")
File.chmod(unreadable, 0o222)
pending_if_superuser!

File.symlink(File.expand_path(datapath("test_file.txt")), good_path)
File.symlink(File.expand_path(unreadable), bad_path)

File.readable?(good_path).should be_true
File.readable?(bad_path).should be_false
end
end
{% end %}

it "gives false when the symbolic link destination doesn't exist" do
with_tempfile("missing_symlink_r.txt") do |missing_path|
File.symlink(File.expand_path(datapath("non_existing_file.txt")), missing_path)
File.readable?(missing_path).should be_false
end
end
end

describe "writable?" do
it "gives true" do
File.writable?(datapath("test_file.txt")).should be_true
end

it "gives false when the file doesn't exist" do
File.writable?(datapath("non_existing_file.txt")).should be_false
end

it "gives false when a component of the path is a file" do
File.writable?(datapath("dir", "test_file.txt", "")).should be_false
end

it "gives false when the file has no write permissions" do
with_tempfile("readonly.txt") do |path|
File.write(path, "")
File.chmod(path, 0o444)
pending_if_superuser!
File.writable?(path).should be_false
end
end

it "follows symlinks" do
with_tempfile("good_symlink_w.txt", "bad_symlink_w.txt", "readonly.txt") do |good_path, bad_path, readonly|
File.write(readonly, "")
File.chmod(readonly, 0o444)
pending_if_superuser!

File.symlink(File.expand_path(datapath("test_file.txt")), good_path)
File.symlink(File.expand_path(readonly), bad_path)

File.writable?(good_path).should be_true
File.writable?(bad_path).should be_false
end
end

it "gives false when the symbolic link destination doesn't exist" do
with_tempfile("missing_symlink_w.txt") do |missing_path|
File.symlink(File.expand_path(datapath("non_existing_file.txt")), missing_path)
File.writable?(missing_path).should be_false
end
end
end

describe "file?" do
it "gives true" do
File.file?(datapath("test_file.txt")).should be_true
Expand Down Expand Up @@ -701,6 +571,139 @@ describe "File" do
it "tests unequal for file and directory" do
File.info(datapath("dir")).should_not eq(File.info(datapath("test_file.txt")))
end

describe ".executable?" do
it "gives true" do
crystal = Process.executable_path || pending! "Unable to locate compiler executable"
File::Info.executable?(crystal).should be_true
File.executable?(crystal).should be_true # deprecated
end

it "gives false" do
File::Info.executable?(datapath("test_file.txt")).should be_false
end

it "gives false when the file doesn't exist" do
File::Info.executable?(datapath("non_existing_file.txt")).should be_false
end

it "gives false when a component of the path is a file" do
File::Info.executable?(datapath("dir", "test_file.txt", "")).should be_false
end

it "follows symlinks" do
with_tempfile("good_symlink_x.txt", "bad_symlink_x.txt") do |good_path, bad_path|
crystal = Process.executable_path || pending! "Unable to locate compiler executable"
File.symlink(File.expand_path(crystal), good_path)
File.symlink(File.expand_path(datapath("non_existing_file.txt")), bad_path)

File::Info.executable?(good_path).should be_true
File::Info.executable?(bad_path).should be_false
end
end
end

describe ".readable?" do
it "gives true" do
File::Info.readable?(datapath("test_file.txt")).should be_true
File.readable?(datapath("test_file.txt")).should be_true # deprecated
end

it "gives false when the file doesn't exist" do
File::Info.readable?(datapath("non_existing_file.txt")).should be_false
end

it "gives false when a component of the path is a file" do
File::Info.readable?(datapath("dir", "test_file.txt", "")).should be_false
end

# win32 doesn't have a way to make files unreadable via chmod
{% unless flag?(:win32) %}
it "gives false when the file has no read permissions" do
with_tempfile("unreadable.txt") do |path|
File.write(path, "")
File.chmod(path, 0o222)
pending_if_superuser!
File::Info.readable?(path).should be_false
end
end

it "gives false when the file has no permissions" do
with_tempfile("unaccessible.txt") do |path|
File.write(path, "")
File.chmod(path, 0o000)
pending_if_superuser!
File::Info.readable?(path).should be_false
end
end

it "follows symlinks" do
with_tempfile("good_symlink_r.txt", "bad_symlink_r.txt", "unreadable.txt") do |good_path, bad_path, unreadable|
File.write(unreadable, "")
File.chmod(unreadable, 0o222)
pending_if_superuser!

File.symlink(File.expand_path(datapath("test_file.txt")), good_path)
File.symlink(File.expand_path(unreadable), bad_path)

File::Info.readable?(good_path).should be_true
File::Info.readable?(bad_path).should be_false
end
end
{% end %}

it "gives false when the symbolic link destination doesn't exist" do
with_tempfile("missing_symlink_r.txt") do |missing_path|
File.symlink(File.expand_path(datapath("non_existing_file.txt")), missing_path)
File::Info.readable?(missing_path).should be_false
end
end
end

describe ".writable?" do
it "gives true" do
File::Info.writable?(datapath("test_file.txt")).should be_true
File.writable?(datapath("test_file.txt")).should be_true # deprecated
end

it "gives false when the file doesn't exist" do
File::Info.writable?(datapath("non_existing_file.txt")).should be_false
end

it "gives false when a component of the path is a file" do
File::Info.writable?(datapath("dir", "test_file.txt", "")).should be_false
end

it "gives false when the file has no write permissions" do
with_tempfile("readonly.txt") do |path|
File.write(path, "")
File.chmod(path, 0o444)
pending_if_superuser!
File::Info.writable?(path).should be_false
end
end

it "follows symlinks" do
with_tempfile("good_symlink_w.txt", "bad_symlink_w.txt", "readonly.txt") do |good_path, bad_path, readonly|
File.write(readonly, "")
File.chmod(readonly, 0o444)
pending_if_superuser!

File.symlink(File.expand_path(datapath("test_file.txt")), good_path)
File.symlink(File.expand_path(readonly), bad_path)

File::Info.writable?(good_path).should be_true
File::Info.writable?(bad_path).should be_false
end
end

it "gives false when the symbolic link destination doesn't exist" do
with_tempfile("missing_symlink_w.txt") do |missing_path|
File.symlink(File.expand_path(datapath("non_existing_file.txt")), missing_path)
File::Info.writable?(missing_path).should be_false
end
end
end
end

describe "size" do
Expand Down Expand Up @@ -1372,15 +1375,15 @@ describe "File" do
end

it_raises_on_null_byte "readable?" do
File.readable?("foo\0bar")
File::Info.readable?("foo\0bar")
end

it_raises_on_null_byte "writable?" do
File.writable?("foo\0bar")
File::Info.writable?("foo\0bar")
end

it_raises_on_null_byte "executable?" do
File.executable?("foo\0bar")
File::Info.executable?("foo\0bar")
end

it_raises_on_null_byte "file?" do
Expand Down
6 changes: 3 additions & 3 deletions spec/std/http/client/client_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ module HTTP
test_server("localhost", 0, 0.5.seconds, write_response: false) do |server|
client = Client.new("localhost", server.local_address.port)
expect_raises(IO::TimeoutError, {% if flag?(:win32) %} "WSARecv timed out" {% else %} "Read timed out" {% end %}) do
client.read_timeout = 0.001
client.read_timeout = 1.millisecond
client.get("/?sleep=1")
end
end
Expand All @@ -365,7 +365,7 @@ module HTTP
test_server("localhost", 0, 0.seconds, write_response: false) do |server|
client = Client.new("localhost", server.local_address.port)
expect_raises(IO::TimeoutError, {% if flag?(:win32) %} "WSASend timed out" {% else %} "Write timed out" {% end %}) do
client.write_timeout = 0.001
client.write_timeout = 1.millisecond
client.post("/", body: "a" * 5_000_000)
end
end
Expand All @@ -374,7 +374,7 @@ module HTTP
it "tests connect_timeout" do
test_server("localhost", 0, 0.seconds) do |server|
client = Client.new("localhost", server.local_address.port)
client.connect_timeout = 0.5
client.connect_timeout = 0.5.seconds
client.get("/")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe HTTP::Server do
begin
ch.receive
client = HTTP::Client.new(address.address, address.port, client_context)
client.read_timeout = client.connect_timeout = 3
client.read_timeout = client.connect_timeout = 3.seconds
client.get("/").body.should eq "ok"
ensure
ch.send nil
Expand Down
4 changes: 2 additions & 2 deletions spec/std/io/io_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ describe IO do
write.puts "hello"
slice = Bytes.new 1024

read.read_timeout = 1
read.read_timeout = 1.second
read.read(slice).should eq(6)

expect_raises(IO::TimeoutError) do
read.read_timeout = 0.0000001
read.read_timeout = 0.1.microseconds
read.read(slice)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/socket/socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe Socket, tags: "network" do
server = Socket.new(Socket::Family::INET, Socket::Type::STREAM, Socket::Protocol::TCP)
port = unused_local_port
server.bind("0.0.0.0", port)
server.read_timeout = 0.1
server.read_timeout = 0.1.seconds
server.listen

expect_raises(IO::TimeoutError) { server.accept }
Expand Down
Loading