Skip to content

Commit

Permalink
Use empty prelude for compiler tools specs (#15272)
Browse files Browse the repository at this point in the history
Apply some tiny refactors to specs that rely on features from the stdlib prelude. These seem to be not particularly relevant for the test scenario because we're testing compiler features, not stdlib implementations.

These changes allow using the compiler with the empty prelude which results in significantly less compilation effort.

The spec runtime for these tests reduces from 3:06 minutes to 13.81 seconds (over 90% reduction! 🎉🚀)
  • Loading branch information
straight-shoota authored Dec 15, 2024
1 parent c878d22 commit 9b377c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
36 changes: 17 additions & 19 deletions spec/compiler/crystal/tools/context_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "../../../spec_helper"
private def processed_context_visitor(code, cursor_location)
compiler = Compiler.new
compiler.no_codegen = true
compiler.prelude = "empty"
result = compiler.compile(Compiler::Source.new(".", code), "fake-no-build")

visitor = ContextVisitor.new(cursor_location)
Expand Down Expand Up @@ -118,15 +119,20 @@ describe "context" do
it "includes last call" do
assert_context_includes %(
class Foo
property lorem
def lorem
@lorem
end
def initialize(@lorem : Int64)
end
end
def foo(f)
end
f = Foo.new(1i64)
puts f.lo‸rem
foo f.lo‸rem
1
), "f.lorem", ["Int64"]
end
Expand All @@ -141,9 +147,13 @@ describe "context" do

it "does includes regex special variables" do
assert_context_keys %(
def match
$~ = "match"
end
def foo
s = "string"
s =~ /s/
s = "foo"
match
0
end
Expand Down Expand Up @@ -185,23 +195,15 @@ describe "context" do

it "can handle union types" do
assert_context_includes %(
a = if rand() > 0
1i64
else
"foo"
end
a = 1_i64.as(Int64 | String)
0
), "a", ["(Int64 | String)"]
end

it "can display text output" do
run_context_tool(%(
a = if rand() > 0
1i64
else
"foo"
end
a = 1_i64.as(Int64 | String)
0
)) do |result|
Expand All @@ -218,11 +220,7 @@ describe "context" do

it "can display json output" do
run_context_tool(%(
a = if rand() > 0
1i64
else
"foo"
end
a = 1_i64.as(Int64 | String)
0
)) do |result|
Expand Down
1 change: 1 addition & 0 deletions spec/compiler/crystal/tools/expand_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ private def processed_expand_visitor(code, cursor_location)
compiler.no_codegen = true
compiler.no_cleanup = true
compiler.wants_doc = true
compiler.prelude = "empty"
result = compiler.compile(Compiler::Source.new(".", code), "fake-no-build")

visitor = ExpandVisitor.new(cursor_location)
Expand Down
8 changes: 3 additions & 5 deletions spec/compiler/crystal/tools/implementations_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "../../../spec_helper"
private def processed_implementation_visitor(code, cursor_location)
compiler = Compiler.new
compiler.no_codegen = true
compiler.prelude = "empty"
result = compiler.compile(Compiler::Source.new(".", code), "fake-no-build")

visitor = ImplementationsVisitor.new(cursor_location)
Expand Down Expand Up @@ -52,7 +53,7 @@ describe "implementations" do
1
end
puts f‸oo
f‸oo
)
end

Expand Down Expand Up @@ -117,7 +118,6 @@ describe "implementations" do
end
while f‸oo
puts 2
end
)
end
Expand All @@ -129,7 +129,6 @@ describe "implementations" do
end
if f‸oo
puts 2
end
)
end
Expand All @@ -140,7 +139,7 @@ describe "implementations" do
1
end
puts 2 if f‸oo
2 if f‸oo
)
end

Expand All @@ -151,7 +150,6 @@ describe "implementations" do
end
begin
puts 2
rescue
f‸oo
end
Expand Down

0 comments on commit 9b377c3

Please sign in to comment.