From 9b377c3735ea7905131439e8c6edc5be8451118e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Sun, 15 Dec 2024 20:22:30 +0100 Subject: [PATCH] Use empty prelude for compiler tools specs (#15272) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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! 🎉🚀) --- spec/compiler/crystal/tools/context_spec.cr | 36 +++++++++---------- spec/compiler/crystal/tools/expand_spec.cr | 1 + .../crystal/tools/implementations_spec.cr | 8 ++--- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/spec/compiler/crystal/tools/context_spec.cr b/spec/compiler/crystal/tools/context_spec.cr index 84c711e8af53..87c2ad5902db 100644 --- a/spec/compiler/crystal/tools/context_spec.cr +++ b/spec/compiler/crystal/tools/context_spec.cr @@ -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) @@ -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 @@ -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 @@ -185,11 +195,7 @@ 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)"] @@ -197,11 +203,7 @@ describe "context" do 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| @@ -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| diff --git a/spec/compiler/crystal/tools/expand_spec.cr b/spec/compiler/crystal/tools/expand_spec.cr index 40a122587afd..e8f9b770f3ec 100644 --- a/spec/compiler/crystal/tools/expand_spec.cr +++ b/spec/compiler/crystal/tools/expand_spec.cr @@ -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) diff --git a/spec/compiler/crystal/tools/implementations_spec.cr b/spec/compiler/crystal/tools/implementations_spec.cr index 7d35659de2bb..3f275c671101 100644 --- a/spec/compiler/crystal/tools/implementations_spec.cr +++ b/spec/compiler/crystal/tools/implementations_spec.cr @@ -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) @@ -52,7 +53,7 @@ describe "implementations" do 1 end - puts f‸oo + f‸oo ) end @@ -117,7 +118,6 @@ describe "implementations" do end while f‸oo - puts 2 end ) end @@ -129,7 +129,6 @@ describe "implementations" do end if f‸oo - puts 2 end ) end @@ -140,7 +139,7 @@ describe "implementations" do 1 end - puts 2 if f‸oo + 2 if f‸oo ) end @@ -151,7 +150,6 @@ describe "implementations" do end begin - puts 2 rescue f‸oo end