-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tempfile and datapath helpers to specs (#5951)
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.36.1
- 0.36.0
- 0.35.1
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.1
- 0.32.0
- 0.31.1
- 0.31.0
- 0.30.1
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.1
- 0.26.0
- 0.25.1
1 parent
5c22fb3
commit 750258d
Showing
27 changed files
with
785 additions
and
832 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
require "../spec_helper" | ||
require "tempfile" | ||
require "./spec_helper" | ||
|
||
describe "Compiler" do | ||
it "compiles a file" do | ||
tempfile = Tempfile.new "compiler_spec_output" | ||
tempfile.close | ||
with_tempfile "compiler_spec_output" do |path| | ||
Crystal::Command.run ["build", datapath("compiler_sample"), "-o", path] | ||
|
||
Crystal::Command.run ["build", "#{__DIR__}/data/compiler_sample", "-o", tempfile.path] | ||
File.exists?(path).should be_true | ||
|
||
File.exists?(tempfile.path).should be_true | ||
|
||
`#{tempfile.path}`.should eq("Hello!") | ||
ensure | ||
File.delete(tempfile.path) if tempfile | ||
`#{path}`.should eq("Hello!") | ||
end | ||
end | ||
|
||
it "runs subcommand in preference to a filename " do | ||
Dir.cd "#{__DIR__}/data/" do | ||
tempfile = Tempfile.new "compiler_spec_output" | ||
tempfile.close | ||
|
||
Crystal::Command.run ["build", "#{__DIR__}/data/compiler_sample", "-o", tempfile.path] | ||
Dir.cd datapath do | ||
with_tempfile "compiler_spec_output" do |path| | ||
Crystal::Command.run ["build", "compiler_sample", "-o", path] | ||
|
||
File.exists?(tempfile.path).should be_true | ||
File.exists?(path).should be_true | ||
|
||
`#{tempfile.path}`.should eq("Hello!") | ||
ensure | ||
File.delete(tempfile.path) if tempfile | ||
`#{path}`.should eq("Hello!") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "../spec_helper" | ||
require "../support/tempfile" | ||
|
||
def datapath(*components) | ||
File.join("spec", "compiler", "data", *components) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,68 @@ | ||
require "spec" | ||
require "tempfile" | ||
require "./spec_helper" | ||
|
||
describe "Backtrace" do | ||
it "prints file line:colunm" do | ||
tempfile = Tempfile.new("compiler_spec_output") | ||
tempfile.close | ||
sample = "#{__DIR__}/data/backtrace_sample" | ||
with_tempfile("compiler_spec_output") do |path| | ||
sample = datapath("backtrace_sample") | ||
|
||
# CallStack tries to make files relative to the current dir, | ||
# so we do the same for tests | ||
current_dir = Dir.current | ||
current_dir += File::SEPARATOR unless current_dir.ends_with?(File::SEPARATOR) | ||
sample = sample.lchop(current_dir) | ||
# CallStack tries to make files relative to the current dir, | ||
# so we do the same for tests | ||
current_dir = Dir.current | ||
current_dir += File::SEPARATOR unless current_dir.ends_with?(File::SEPARATOR) | ||
sample = sample.lchop(current_dir) | ||
|
||
`bin/crystal build --debug #{sample.inspect} -o #{tempfile.path.inspect}` | ||
File.exists?(tempfile.path).should be_true | ||
`bin/crystal build --debug #{sample.inspect} -o #{path.inspect}` | ||
File.exists?(path).should be_true | ||
|
||
{% if flag?(:darwin) %} | ||
`dsymutil --flat #{tempfile.path}` | ||
{% end %} | ||
{% if flag?(:darwin) %} | ||
`dsymutil --flat #{path}` | ||
{% end %} | ||
|
||
output = `#{tempfile.path}` | ||
output = `#{path}` | ||
|
||
# resolved file line:column | ||
output.should match(/#{sample}:3:10 in 'callee1'/) | ||
# resolved file line:column | ||
output.should match(/#{sample}:3:10 in 'callee1'/) | ||
|
||
unless output =~ /#{sample}:13:5 in 'callee3'/ | ||
fail "didn't find callee3 in the backtrace" | ||
end | ||
unless output =~ /#{sample}:13:5 in 'callee3'/ | ||
fail "didn't find callee3 in the backtrace" | ||
end | ||
|
||
# skipped internal details | ||
output.should_not match(/src\/callstack\.cr/) | ||
output.should_not match(/src\/exception\.cr/) | ||
output.should_not match(/src\/raise\.cr/) | ||
ensure | ||
File.delete(tempfile.path) if tempfile | ||
# skipped internal details | ||
output.should_not match(/src\/callstack\.cr/) | ||
output.should_not match(/src\/exception\.cr/) | ||
output.should_not match(/src\/raise\.cr/) | ||
end | ||
end | ||
|
||
it "prints exception backtrace to stderr" do | ||
tempfile = Tempfile.new("compiler_spec_output") | ||
tempfile.close | ||
sample = "#{__DIR__}/data/exception_backtrace_sample" | ||
with_tempfile("compiler_spec_output") do |path| | ||
sample = datapath("exception_backtrace_sample") | ||
|
||
`bin/crystal build --debug #{sample.inspect} -o #{tempfile.path.inspect}` | ||
File.exists?(tempfile.path).should be_true | ||
`bin/crystal build --debug #{sample.inspect} -o #{path.inspect}` | ||
File.exists?(path).should be_true | ||
|
||
output, error = {IO::Memory.new, IO::Memory.new}.tap do |outio, errio| | ||
Process.run tempfile.path, output: outio, error: errio | ||
end | ||
output, error = {IO::Memory.new, IO::Memory.new}.tap do |outio, errio| | ||
Process.run path, output: outio, error: errio | ||
end | ||
|
||
output.to_s.empty?.should be_true | ||
error.to_s.should contain("IndexError") | ||
ensure | ||
File.delete(tempfile.path) if tempfile | ||
output.to_s.empty?.should be_true | ||
error.to_s.should contain("IndexError") | ||
end | ||
end | ||
|
||
it "prints crash backtrace to stderr" do | ||
tempfile = Tempfile.new("compiler_spec_output") | ||
tempfile.close | ||
sample = "#{__DIR__}/data/crash_backtrace_sample" | ||
with_tempfile("compiler_spec_output") do |path| | ||
sample = datapath("crash_backtrace_sample") | ||
|
||
`bin/crystal build --debug #{sample.inspect} -o #{tempfile.path.inspect}` | ||
File.exists?(tempfile.path).should be_true | ||
`bin/crystal build --debug #{sample.inspect} -o #{path.inspect}` | ||
File.exists?(path).should be_true | ||
|
||
output, error = {IO::Memory.new, IO::Memory.new}.tap do |outio, errio| | ||
Process.run tempfile.path, output: outio, error: errio | ||
end | ||
output, error = {IO::Memory.new, IO::Memory.new}.tap do |outio, errio| | ||
Process.run path, output: outio, error: errio | ||
end | ||
|
||
output.to_s.empty?.should be_true | ||
error.to_s.should contain("Invalid memory access") | ||
ensure | ||
File.delete(tempfile.path) if tempfile | ||
output.to_s.empty?.should be_true | ||
error.to_s.should contain("Invalid memory access") | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.