Skip to content

Commit

Permalink
Add pending_interpreted (#14386)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Mar 24, 2024
1 parent 5cefc9a commit 905039c
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 39 deletions.
2 changes: 1 addition & 1 deletion spec/generate_interpreter_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ echo "# $(date --rfc-3339 seconds) This file is autogenerated by \`${command% }\
run_spec () {
spec=$1
require="require \"./${spec##spec/}\""
timeout 150 $CRYSTAL_BIN i $spec > /dev/null; exit=$?
timeout --signal=KILL 150 $CRYSTAL_BIN i $spec > /dev/null; exit=$?

if [ $exit -eq 0 ] ; then
echo "$require" >> $OUT_FILE
Expand Down
35 changes: 19 additions & 16 deletions spec/interpreter_std_spec.cr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions spec/std/crystal/system_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "spec"
require "../spec_helper"

private def print_error_to_s(format, *args)
io = IO::Memory.new
Expand Down Expand Up @@ -26,15 +26,17 @@ describe "Crystal::System" do
print_error_to_s("%x,%x,%x,%x,%x", 0, 0x1234, UInt32::MAX, Int32::MIN, UInt64::MAX).should eq("0,1234,ffffffff,80000000,ffffffff")
end

it "supports %p" do
# TODO: investigate why this prints `(???)`
pending_interpreted "supports %p" do
print_error_to_s("%p,%p,%p", Pointer(Void).new(0x0), Pointer(Void).new(0x1234), Pointer(Void).new(UInt64::MAX)).should eq("0x0,0x1234,0xffffffffffffffff")
end

it "supports %s" do
print_error_to_s("%s,%s,%s", "abc\0def", "ghi".to_unsafe, Pointer(UInt8).null).should eq("abc\0def,ghi,(null)")
end

it "supports %l width" do
# BUG: missing downcast_distinct from Tuple(Int64 | UInt64, Int64 | UInt64, Int64 | UInt64, Int64 | UInt64) to Tuple(Int64, Int64, Int64, Int64)
pending_interpreted "supports %l width" do
values = {LibC::Long::MIN, LibC::Long::MAX, LibC::LongLong::MIN, LibC::LongLong::MAX}
print_error_to_s("%ld,%ld,%lld,%lld", *values).should eq(values.join(','))

Expand Down
3 changes: 2 additions & 1 deletion spec/std/dir_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ describe "Dir" do
end

describe ".current" do
it "matches shell" do
# can't use backtick in interpreted code (#12241)
pending_interpreted "matches shell" do
Dir.current.should eq(`#{{{ flag?(:win32) ? "cmd /c cd" : "pwd" }}}`.chomp)
end

Expand Down
7 changes: 3 additions & 4 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ describe "File" do
end
end

{% if LibC.has_method?(:mkfifo) && !flag?(:interpreted) %}
# spec is disabled when interpreted because the interpreter doesn't
# support threads
it "opens fifo file as non-blocking" do
{% if LibC.has_method?(:mkfifo) %}
# interpreter doesn't support threads yet (#14287)
pending_interpreted "opens fifo file as non-blocking" do
path = File.tempname("chardev")
ret = LibC.mkfifo(path, File::DEFAULT_CREATE_PERMISSIONS)
raise RuntimeError.from_errno("mkfifo") unless ret == 0
Expand Down
6 changes: 3 additions & 3 deletions spec/std/file_utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,9 @@ describe "FileUtils" do
end
end

# FIXME: `Process.run` and backtick don't work in the interpreter (#12241)
{% if flag?(:unix) && !flag?(:interpreted) %}
it "overwrites a destination named pipe" do
{% if flag?(:unix) %}
# can't use backtick in interpreted code (#12241)
pending_interpreted "overwrites a destination named pipe" do
with_tempfile("ln_sf_src", "ln_sf_dst_pipe_exists") do |path1, path2|
test_with_string_and_path(path1, path2) do |arg1, arg2|
FileUtils.touch([path1])
Expand Down
3 changes: 2 additions & 1 deletion spec/std/process_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ private def newline
{% end %}
end

describe Process do
# interpreted code doesn't receive SIGCHLD for `#wait` to work (#12241)
pending_interpreted describe: Process do
describe ".new" do
it "raises if command doesn't exist" do
expect_raises(File::NotFoundError, "Error executing process: 'foobarbaz'") do
Expand Down
5 changes: 3 additions & 2 deletions spec/std/signal_spec.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% skip_file if flag?(:wasm32) %}

require "spec"
require "./spec_helper"
require "signal"

describe "Signal" do
# interpreted code never receives signals (#12241)
pending_interpreted describe: "Signal" do
typeof(Signal::ABRT.reset)
typeof(Signal::ABRT.ignore)
typeof(Signal::ABRT.trap { 1 })
Expand Down
4 changes: 4 additions & 0 deletions spec/std/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "../support/tempfile"
require "../support/fibers"
require "../support/win32"
require "../support/wasm32"
require "../support/interpreted"

def datapath(*components)
File.join("spec", "std", "data", *components)
Expand Down Expand Up @@ -77,6 +78,9 @@ def spawn_and_check(before : Proc(_), file = __FILE__, line = __LINE__, &block :
end

def compile_file(source_file, *, bin_name = "executable_file", flags = %w(), file = __FILE__, &)
# can't use backtick in interpreted code (#12241)
pending_interpreted! "Unable to compile Crystal code in interpreted code"

with_temp_executable(bin_name, file: file) do |executable_file|
compiler = ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal"
args = ["build"] + flags + ["-o", executable_file, source_file]
Expand Down
6 changes: 4 additions & 2 deletions spec/std/system_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ require "system"

describe System do
describe "hostname" do
it "returns current hostname" do
# can't use backtick in interpreted code (#12241)
pending_interpreted "returns current hostname" do
shell_hostname = `hostname`.strip
pending! "`hostname` command was unsuccessful" unless $?.success?

Expand All @@ -13,7 +14,8 @@ describe System do
end

describe "cpu_count" do
it "returns current CPU count" do
# can't use backtick in interpreted code (#12241)
pending_interpreted "returns current CPU count" do
shell_cpus =
{% if flag?(:win32) %}
ENV["NUMBER_OF_PROCESSORS"].to_i
Expand Down
5 changes: 3 additions & 2 deletions spec/std/thread/condition_variable_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
{% skip_file %}
{% end %}

require "spec"
require "../spec_helper"

describe Thread::ConditionVariable do
# interpreter doesn't support threads yet (#14287)
pending_interpreted describe: Thread::ConditionVariable do
it "signals" do
mutex = Thread::Mutex.new
cond = Thread::ConditionVariable.new
Expand Down
5 changes: 3 additions & 2 deletions spec/std/thread/mutex_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
{% skip_file %}
{% end %}

require "spec"
require "../spec_helper"

describe Thread::Mutex do
# interpreter doesn't support threads yet (#14287)
pending_interpreted describe: Thread::Mutex do
it "synchronizes" do
a = 0
mutex = Thread::Mutex.new
Expand Down
5 changes: 3 additions & 2 deletions spec/std/thread_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "spec"
require "./spec_helper"

{% if flag?(:musl) %}
# FIXME: These thread specs occasionally fail on musl/alpine based ci, so
Expand All @@ -8,7 +8,8 @@ require "spec"
{% skip_file %}
{% end %}

describe Thread do
# interpreter doesn't support threads yet (#14287)
pending_interpreted describe: Thread do
it "allows passing an argumentless fun to execute" do
a = 0
thread = Thread.new { a = 1; 10 }
Expand Down
26 changes: 26 additions & 0 deletions spec/support/interpreted.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "spec"

{% if flag?(:interpreted) %}
def pending_interpreted(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
pending("#{description} [interpreted]", file, line, end_line)
end

def pending_interpreted(*, describe, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
pending_interpreted(describe, file, line, end_line) { }
end

def pending_interpreted!(msg = "Cannot run example", file = __FILE__, line = __LINE__)
pending!(msg, file, line)
end
{% else %}
def pending_interpreted(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
it(description, file, line, end_line, &block)
end

def pending_interpreted(*, describe, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
describe(describe, file, line, end_line, &block)
end

def pending_interpreted!(msg = "Cannot run example", file = __FILE__, line = __LINE__)
end
{% end %}
4 changes: 4 additions & 0 deletions spec/support/tempfile.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "file_utils"
require "./interpreted"
{% if flag?(:msvc) %}
require "crystal/system/win32/visual_studio"
{% end %}
Expand Down Expand Up @@ -47,6 +48,9 @@ def with_temp_executable(name, file = __FILE__, &)
end

def with_temp_c_object_file(c_code, *, filename = "temp_c", file = __FILE__, &)
# can't use backtick in interpreted code (#12241)
pending_interpreted! "Unable to compile C code in interpreted code"

obj_ext = {{ flag?(:msvc) ? ".obj" : ".o" }}
with_tempfile("#{filename}.c", "#{filename}#{obj_ext}", file: file) do |c_filename, o_filename|
File.write(c_filename, c_code)
Expand Down

0 comments on commit 905039c

Please sign in to comment.