Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specs on win32 #8670

Merged
merged 10 commits into from
Jan 13, 2020
39 changes: 20 additions & 19 deletions spec/std/concurrent_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "spec"
require "./spec_helper"

private def method_with_named_args(chan, x = 1, y = 2)
chan.send(x + y)
Expand All @@ -18,32 +18,33 @@ private def raising_job : String
end

describe "concurrent" do
{% unless flag?(:win32) %}
describe "parallel" do
it "does four things concurrently" do
a, b, c, d = parallel(1 + 2, "hello".size, [1, 2, 3, 4].size, nil)
a.should eq(3)
b.should eq(5)
c.should eq(4)
d.should be_nil
end

it "re-raises errors from Fibers as ConcurrentExecutionException" do
exception = expect_raises(ConcurrentExecutionException) do
a, b = parallel(raising_job, raising_job)
end
describe "parallel" do
pending_win32 "does four things concurrently" do
a, b, c, d = parallel(1 + 2, "hello".size, [1, 2, 3, 4].size, nil)
a.should eq(3)
b.should eq(5)
c.should eq(4)
d.should be_nil
end

exception.cause.should be_a(SomeParallelJobException)
pending_win32 "re-raises errors from Fibers as ConcurrentExecutionException" do
exception = expect_raises(ConcurrentExecutionException) do
a, b = parallel(raising_job, raising_job)
end

it "is strict about the return value type" do
exception.cause.should be_a(SomeParallelJobException)
end

# FIXME: Compiler bug with typeof inside an unused block https://github.com/crystal-lang/crystal/issues/8669
{% unless flag?(:win32) %}
pending_win32 "is strict about the return value type" do
a, b = parallel(1 + 2, "hello")

typeof(a).should eq(Int32)
typeof(b).should eq(String)
end
end
{% end %}
{% end %}
end

describe "spawn" do
it "uses spawn macro" do
Expand Down
20 changes: 9 additions & 11 deletions spec/std/crystal/hasher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,16 @@ describe "Crystal::Hasher" do
1_i32.hash.should eq(1_f64.hash)
end

{% unless flag?(:win32) %}
it "should 1_f32 and 1.to_big_f hashes equal" do
1_f32.hash.should eq(1.to_big_f.hash)
end
pending_win32 "should 1_f32 and 1.to_big_f hashes equal" do
1_f32.hash.should eq(1.to_big_f.hash)
end

it "should 1_f32 and 1.to_big_r hashes equal" do
1_f32.hash.should eq(1.to_big_r.hash)
end
pending_win32 "should 1_f32 and 1.to_big_r hashes equal" do
1_f32.hash.should eq(1.to_big_r.hash)
end

it "should 1_f32 and 1.to_big_i hashes equal" do
1_f32.hash.should eq(1.to_big_i.hash)
end
{% end %}
pending_win32 "should 1_f32 and 1.to_big_i hashes equal" do
1_f32.hash.should eq(1.to_big_i.hash)
end
end
end
83 changes: 59 additions & 24 deletions spec/std/dir_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
require "./spec_helper"
require "../support/errno"

private def unset_tempdir
{% if flag?(:windows) %}
old_tempdirs = {ENV["TMP"]?, ENV["TEMP"]?, ENV["USERPROFILE"]?}
begin
ENV.delete("TMP")
ENV.delete("TEMP")
ENV.delete("USERPROFILE")

yield
ensure
ENV["TMP"], ENV["TEMP"], ENV["USERPROFILE"] = old_tempdirs
end
{% else %}
begin
old_tempdir = ENV["TMPDIR"]?
ENV.delete("TMPDIR")

yield
ensure
ENV["TMPDIR"] = old_tempdir
end
{% end %}
end

private def it_raises_on_null_byte(operation, &block)
it "errors on #{operation}" do
expect_raises(ArgumentError, "String contains null byte") do
Expand Down Expand Up @@ -233,25 +257,24 @@ describe "Dir" do

it "tests with relative path (starts with ..)" do
Dir.cd(datapath) do
base_path = "../data/dir"
base_path = Path["..", "data", "dir"]
Dir["#{base_path}/*/"].sort.should eq [
File.join(base_path, "dots", ""),
File.join(base_path, "subdir", ""),
File.join(base_path, "subdir2", ""),
base_path.join("dots", "").to_s,
base_path.join("subdir", "").to_s,
base_path.join("subdir2", "").to_s,
].sort
end
end

# TODO: This spec is broken on win32 because of `raise` weirdness on windows
pending_win32 "tests with relative path starting recursive" do
it "tests with relative path starting recursive" do
Dir["**/dir/*/"].sort.should eq [
datapath("dir", "dots", ""),
datapath("dir", "subdir", ""),
datapath("dir", "subdir2", ""),
].sort
end

it "matches symlinks" do
pending_win32 "matches symlinks" do
RX14 marked this conversation as resolved.
Show resolved Hide resolved
link = datapath("f1_link.txt")
non_link = datapath("non_link.txt")

Expand All @@ -274,36 +297,40 @@ describe "Dir" do
Dir[""].should eq [] of String
end

pending_win32 "root pattern" do
Dir["/"].should eq ["/"]
it "root pattern" do
{% if flag?(:windows) %}
Dir["C:/"].should eq ["C:\\"]
{% else %}
Dir["/"].should eq ["/"]
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
{% end %}
end

it "pattern ending with .." do
Dir["#{datapath}/dir/.."].sort.should eq [
datapath("dir", ".."),
]
].sort
end

it "pattern ending with */.." do
Dir["#{datapath}/dir/*/.."].sort.should eq [
datapath("dir", "dots", ".."),
datapath("dir", "subdir", ".."),
datapath("dir", "subdir2", ".."),
]
].sort
end

it "pattern ending with ." do
Dir["#{datapath}/dir/."].sort.should eq [
datapath("dir", "."),
]
].sort
end

it "pattern ending with */." do
Dir["#{datapath}/dir/*/."].sort.should eq [
datapath("dir", "dots", "."),
datapath("dir", "subdir", "."),
datapath("dir", "subdir2", "."),
]
].sort
end

context "match_hidden: true" do
Expand Down Expand Up @@ -337,7 +364,7 @@ describe "Dir" do
end

it "raises" do
expect_raises_errno(Errno::ENOENT, "Error while changing directory to '/nope'") do
expect_raises_errno(Errno::ENOENT, {{ flag?(:win32) ? /SetCurrentDirectory: .* No such file or directory/ : "Error while changing directory to '/nope'" }}) do
RX14 marked this conversation as resolved.
Show resolved Hide resolved
Dir.cd("/nope")
end
end
Expand All @@ -355,19 +382,27 @@ describe "Dir" do

describe ".tempdir" do
it "returns default directory for tempfiles" do
old_tmpdir = ENV["TMPDIR"]?
ENV.delete("TMPDIR")
Dir.tempdir.should eq("/tmp")
ensure
ENV["TMPDIR"] = old_tmpdir
unset_tempdir do
{% if flag?(:windows) %}
# GetTempPathW defaults to the Windows directory when %TMP%, %TEMP%
# and %USERPROFILE% are not set.
# Without going further into the implementation details, simply
# verifying that the directory exits is sufficient.
Dir.exists?(Dir.tempdir).should be_true
{% else %}
# POSIX implementation is in Crystal::System::Dir and defaults to
# `/tmp` when $TMPDIR is not set.
Dir.tempdir.should eq "/tmp"
{% end %}
end
end

it "returns configure directory for tempfiles" do
old_tmpdir = ENV["TMPDIR"]?
ENV["TMPDIR"] = "/my/tmp"
Dir.tempdir.should eq("/my/tmp")
ensure
ENV["TMPDIR"] = old_tmpdir
unset_tempdir do
tmp_path = Path["my_temporary_path"].expand.to_s
ENV[{{ flag?(:windows) ? "TMP" : "TMPDIR" }}] = tmp_path
Dir.tempdir.should eq tmp_path
end
end
end

Expand Down
58 changes: 28 additions & 30 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1077,48 +1077,46 @@ describe "File" do
end

# TODO: these specs don't compile on win32 because iconv isn't implemented
{% unless flag?(:win32) %}
describe "encoding" do
it "writes with encoding" do
with_tempfile("encoding-write.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.read(path).to_slice.should eq("hello".encode("UCS-2LE"))
end
describe "encoding" do
pending_win32 "writes with encoding" do
with_tempfile("encoding-write.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.read(path).to_slice.should eq("hello".encode("UCS-2LE"))
end
end

it "reads with encoding" do
with_tempfile("encoding-read.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.read(path, encoding: "UCS-2LE").should eq("hello")
end
pending_win32 "reads with encoding" do
with_tempfile("encoding-read.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.read(path, encoding: "UCS-2LE").should eq("hello")
end
end

it "opens with encoding" do
with_tempfile("encoding-open.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.open(path, encoding: "UCS-2LE") do |file|
file.gets_to_end.should eq("hello")
end
pending_win32 "opens with encoding" do
with_tempfile("encoding-open.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.open(path, encoding: "UCS-2LE") do |file|
file.gets_to_end.should eq("hello")
end
end
end

it "does each line with encoding" do
with_tempfile("encoding-each_line.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.each_line(path, encoding: "UCS-2LE") do |line|
line.should eq("hello")
end
pending_win32 "does each line with encoding" do
with_tempfile("encoding-each_line.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.each_line(path, encoding: "UCS-2LE") do |line|
line.should eq("hello")
end
end
end

it "reads lines with encoding" do
with_tempfile("encoding-read_lines.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.read_lines(path, encoding: "UCS-2LE").should eq(["hello"])
end
pending_win32 "reads lines with encoding" do
with_tempfile("encoding-read_lines.txt") do |path|
File.write(path, "hello", encoding: "UCS-2LE")
File.read_lines(path, encoding: "UCS-2LE").should eq(["hello"])
end
end
{% end %}
end

describe "closed stream" do
it "raises if writing on a closed stream" do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/float_printer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe "#print Float64" do
test_pair 5.5626846462680035e-309, "5.562684646268003e-309"
end

it "falure case" do
pending_win32 "failure case" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this broken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea. It returns a different result. Maybe that's expected? IDK. Needs investigation into the win32 libs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there is something fundamentally broken with floating point numbers on win32:

"%f" % 1.0 # => "0.000000"

# grisu cannot do this number, so it should fall back to libc
test_pair 3.5844466002796428e+298, "3.5844466002796428e+298"
end
Expand Down
4 changes: 1 addition & 3 deletions spec/std/int_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,7 @@ describe "Int" do
{% end %}
end

{% unless flag?(:win32) %}
it "compares signed vs. unsigned integers" do
pending_win32 "compares signed vs. unsigned integers" do
signed_ints = [Int8::MAX, Int16::MAX, Int32::MAX, Int64::MAX, Int8::MIN, Int16::MIN, Int32::MIN, Int64::MIN, 0_i8, 0_i16, 0_i32, 0_i64]
unsigned_ints = [UInt8::MAX, UInt16::MAX, UInt32::MAX, UInt64::MAX, 0_u8, 0_u16, 0_u32, 0_u64]

Expand All @@ -749,7 +748,6 @@ describe "Int" do
end
end
end
{% end %}

{% if compare_versions(Crystal::VERSION, "0.26.1") > 0 %}
it "compares equality and inequality of signed vs. unsigned integers" do
Expand Down
3 changes: 1 addition & 2 deletions spec/std/path_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,7 @@ describe Path do
end

it "doesn't expand ~" do
["~", "~/foo"].each do |path|
path = Path[path]
[Path["~"], Path["~", "foo"]].each do |path|
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
path.expand(base: "", expand_base: false).should eq path
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/std/raise_spec.cr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require "spec"
require "./spec_helper"

describe "raise" do
callstack_on_rescue = nil

it "should set exception's callstack" do
pending_win32 "should set exception's callstack" do
RX14 marked this conversation as resolved.
Show resolved Hide resolved
exception = expect_raises Exception, "without callstack" do
raise "without callstack"
end
exception.callstack.should_not be_nil
end

it "shouldn't overwrite the callstack on re-raise" do
pending_win32 "shouldn't overwrite the callstack on re-raise" do
exception_after_reraise = expect_raises Exception, "exception to be rescued" do
begin
raise "exception to be rescued"
Expand Down
2 changes: 1 addition & 1 deletion spec/std/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end

{% if flag?(:win32) %}
def pending_win32(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
pending(description, file, line, end_line, &block)
pending("#{description} [win32]", file, line, end_line)
end
{% else %}
def pending_win32(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
Expand Down
Loading