diff --git a/spec/compiler/semantic/abstract_def_spec.cr b/spec/compiler/semantic/abstract_def_spec.cr index a0de9c62f85f..9a467aa3518c 100644 --- a/spec/compiler/semantic/abstract_def_spec.cr +++ b/spec/compiler/semantic/abstract_def_spec.cr @@ -190,7 +190,7 @@ describe "Semantic: abstract def" do end it "doesn't error if abstract method is implemented by subclass" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo end @@ -199,11 +199,11 @@ describe "Semantic: abstract def" do def foo end end - ) + CR end it "doesn't error if abstract method with args is implemented by subclass" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(x, y) end @@ -212,11 +212,11 @@ describe "Semantic: abstract def" do def foo(x, y) end end - ) + CR end it "doesn't error if abstract method with args is implemented by subclass (restriction -> no restriction)" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(x, y : Int32) end @@ -225,11 +225,11 @@ describe "Semantic: abstract def" do def foo(x, y) end end - ) + CR end it "doesn't error if abstract method with args is implemented by subclass (don't check subclasses)" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo end @@ -241,7 +241,7 @@ describe "Semantic: abstract def" do class Baz < Bar end - ) + CR end it "errors if abstract method is not implemented by subclass of subclass" do @@ -260,7 +260,7 @@ describe "Semantic: abstract def" do end it "doesn't error if abstract method is implemented by subclass via module inclusion" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo end @@ -273,7 +273,7 @@ describe "Semantic: abstract def" do class Bar < Foo include Moo end - ) + CR end it "errors if abstract method is not implemented by including class" do @@ -290,7 +290,7 @@ describe "Semantic: abstract def" do end it "doesn't error if abstract method is implemented by including class" do - semantic %( + assert_no_errors <<-CR module Foo abstract def foo end @@ -301,11 +301,11 @@ describe "Semantic: abstract def" do def foo end end - ) + CR end it "doesn't error if abstract method is not implemented by including module" do - semantic %( + assert_no_errors <<-CR module Foo abstract def foo end @@ -313,7 +313,7 @@ describe "Semantic: abstract def" do module Bar include Foo end - ) + CR end it "errors if abstract method is not implemented by subclass (nested in module)" do @@ -331,7 +331,7 @@ describe "Semantic: abstract def" do end it "doesn't error if abstract method with args is implemented by subclass (with one default arg)" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(x) end @@ -340,7 +340,7 @@ describe "Semantic: abstract def" do def foo(x, y = 1) end end - ) + CR end it "doesn't error if implements with parent class" do @@ -453,7 +453,7 @@ describe "Semantic: abstract def" do end it "finds implements in included module in disorder (#4052)" do - semantic %( + assert_no_errors <<-CR module B abstract def x end @@ -468,7 +468,7 @@ describe "Semantic: abstract def" do include C include B end - ) + CR end it "errors if missing return type" do @@ -528,7 +528,7 @@ describe "Semantic: abstract def" do end it "matches instantiated generic types" do - semantic(%( + assert_no_errors <<-CR abstract class Foo(T) abstract def foo(x : T) end @@ -540,11 +540,11 @@ describe "Semantic: abstract def" do def foo(x : Int32) end end - )) + CR end it "matches generic types" do - semantic(%( + assert_no_errors <<-CR abstract class Foo(T) abstract def foo(x : T) end @@ -553,11 +553,11 @@ describe "Semantic: abstract def" do def foo(x : U) end end - )) + CR end it "matches instantiated generic module" do - semantic(%( + assert_no_errors <<-CR module Foo(T) abstract def foo(x : T) end @@ -568,11 +568,11 @@ describe "Semantic: abstract def" do def foo(x : Int32) end end - )) + CR end it "matches generic module" do - semantic(%( + assert_no_errors <<-CR module Foo(T) abstract def foo(x : T) end @@ -583,11 +583,11 @@ describe "Semantic: abstract def" do def foo(x : U) end end - )) + CR end it "matches generic module (a bit more complex)" do - semantic(%( + assert_no_errors <<-CR class Gen(T) end @@ -601,11 +601,11 @@ describe "Semantic: abstract def" do def foo(x : Gen(Int32)) end end - )) + CR end it "matches generic return type" do - semantic(%( + assert_no_errors <<-CR abstract class Foo(T) abstract def foo : T end @@ -615,7 +615,7 @@ describe "Semantic: abstract def" do 1 end end - )) + CR end it "errors if missing a return type in subclass of generic subclass" do @@ -661,7 +661,7 @@ describe "Semantic: abstract def" do end it "implements through extend (considers original type for generic lookup) (#8096)" do - semantic(%( + assert_no_errors <<-CR module ICallable(T) abstract def call(foo : T) end @@ -675,11 +675,11 @@ describe "Semantic: abstract def" do extend ICallable(Int32) extend Moo end - )) + CR end it "implements through extend (considers original type for generic lookup) (2) (#8096)" do - semantic(%( + assert_no_errors <<-CR module ICallable(T) abstract def call(foo : T) end @@ -691,11 +691,11 @@ describe "Semantic: abstract def" do def call(foo : Int32) end end - )) + CR end it "can implement even if yield comes later in macro code" do - semantic(%( + assert_no_errors <<-CR module Moo abstract def each(& : Int32 -> _) end @@ -711,11 +711,11 @@ describe "Semantic: abstract def" do {% end %} end end - )) + CR end it "can implement by block signature even if yield comes later in macro code" do - semantic(%( + assert_no_errors <<-CR module Moo abstract def each(& : Int32 -> _) end @@ -729,7 +729,7 @@ describe "Semantic: abstract def" do {% end %} end end - )) + CR end it "error shows full signature of block parameter" do @@ -745,7 +745,7 @@ describe "Semantic: abstract def" do end it "doesn't error if implementation have default value" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(x) end @@ -754,7 +754,7 @@ describe "Semantic: abstract def" do def foo(x = 1) end end - ) + CR end it "errors if implementation doesn't have default value" do @@ -827,7 +827,7 @@ describe "Semantic: abstract def" do end it "doesn't error if implementation matches keyword argument" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(*, x) end @@ -836,7 +836,7 @@ describe "Semantic: abstract def" do def foo(*, x) end end - ) + CR end it "errors if implementation doesn't match keyword argument type" do @@ -854,7 +854,7 @@ describe "Semantic: abstract def" do end it "doesn't error if implementation have keyword arguments in different order" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(*, x : Int32, y : String) end @@ -863,7 +863,7 @@ describe "Semantic: abstract def" do def foo(*, y : String, x : Int32) end end - ) + CR end it "errors if implementation has more keyword arguments" do @@ -881,7 +881,7 @@ describe "Semantic: abstract def" do end it "doesn't error if implementation has more keyword arguments with default values" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(*, x) end @@ -890,7 +890,7 @@ describe "Semantic: abstract def" do def foo(*, x, y = 1) end end - ) + CR end it "errors if implementation doesn't have a splat" do @@ -922,7 +922,7 @@ describe "Semantic: abstract def" do end it "doesn't error with splat" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(*args) end @@ -931,11 +931,11 @@ describe "Semantic: abstract def" do def foo(*args) end end - ) + CR end it "doesn't error with splat and args with default value" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(*args) end @@ -944,11 +944,11 @@ describe "Semantic: abstract def" do def foo(a = 1, *args) end end - ) + CR end it "allows arguments to be collapsed into splat" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(a : Int32, b : String) end @@ -957,7 +957,7 @@ describe "Semantic: abstract def" do def foo(*args : Int32 | String) end end - ) + CR end it "errors if keyword argument doesn't have the same default value" do @@ -974,7 +974,7 @@ describe "Semantic: abstract def" do end it "allow double splat argument" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(**kargs) end @@ -983,11 +983,11 @@ describe "Semantic: abstract def" do def foo(**kargs) end end - ) + CR end it "allow double splat when abstract doesn't have it" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo end @@ -996,7 +996,7 @@ describe "Semantic: abstract def" do def foo(**kargs) end end - ) + CR end it "errors if implementation misses the double splat" do @@ -1026,7 +1026,7 @@ describe "Semantic: abstract def" do end it "allow splat instead of keyword argument" do - semantic %( + assert_no_errors <<-CR abstract class Foo abstract def foo(*, foo) end @@ -1035,7 +1035,7 @@ describe "Semantic: abstract def" do def foo(**kargs) end end - ) + CR end it "extra keyword arguments must have compatible type to double splat" do diff --git a/spec/compiler/semantic/annotation_spec.cr b/spec/compiler/semantic/annotation_spec.cr index 25ac9467787b..2e6670b62f09 100644 --- a/spec/compiler/semantic/annotation_spec.cr +++ b/spec/compiler/semantic/annotation_spec.cr @@ -893,12 +893,12 @@ describe "Semantic: annotation" do end it "doesn't carry link annotation from lib to fun" do - semantic(%( + assert_no_errors <<-CR @[Link("foo")] lib LibFoo fun foo end - )) + CR end it "finds annotation in generic parent (#7885)" do @@ -962,13 +962,13 @@ describe "Semantic: annotation" do end it "doesn't bleed annotation from class into class variable (#8314)" do - semantic(%( + assert_no_errors <<-CR annotation Attr; end @[Attr] class Bar @@x = 0 end - )) + CR end end diff --git a/spec/compiler/semantic/block_spec.cr b/spec/compiler/semantic/block_spec.cr index a893653ddcf5..df707dcf28d4 100644 --- a/spec/compiler/semantic/block_spec.cr +++ b/spec/compiler/semantic/block_spec.cr @@ -1318,7 +1318,7 @@ describe "Block inference" do end it "auto-unpacks tuple, captured empty block" do - semantic(%( + assert_no_errors <<-CR def foo(&block : {Int32, Char} -> _) tup = {1, 'a'} block.call tup @@ -1326,7 +1326,7 @@ describe "Block inference" do foo do |x, y| end - )) + CR end it "auto-unpacks tuple, captured block with multiple statements" do @@ -1522,14 +1522,14 @@ describe "Block inference" do end it "doesn't crash on cleaning up typeof node without dependencies (#8669)" do - semantic(%( + assert_no_errors <<-CR def foo(&) end foo do typeof(bar) end - )) + CR end it "respects block arg restriction when block has a splat parameter (#6473)" do @@ -1565,7 +1565,7 @@ describe "Block inference" do end it "allows underscore in block return type even if the return type can't be computed" do - semantic(%( + assert_no_errors <<-CR def foo(& : -> _) yield end @@ -1577,11 +1577,11 @@ describe "Block inference" do end recursive - )) + CR end it "doesn't fail with 'already had enclosing call' (#11200)" do - semantic(%( + assert_no_errors <<-CR def capture(&block) block end @@ -1606,6 +1606,6 @@ describe "Block inference" do foo = Bar(Bool).new.as(Foo) foo.foo - )) + CR end end diff --git a/spec/compiler/semantic/closure_spec.cr b/spec/compiler/semantic/closure_spec.cr index 829131c91466..302efe0eec94 100644 --- a/spec/compiler/semantic/closure_spec.cr +++ b/spec/compiler/semantic/closure_spec.cr @@ -617,7 +617,7 @@ describe "Semantic: closure" do end it "doesn't assign all types to metavar if closured but only assigned to once" do - semantic(%( + assert_no_errors <<-CR def capture(&block) block end @@ -627,7 +627,7 @@ describe "Semantic: closure" do x &+ 1 end end - )) + CR end it "does assign all types to metavar if closured but only assigned to once in a loop" do diff --git a/spec/compiler/semantic/const_spec.cr b/spec/compiler/semantic/const_spec.cr index e6ea89a20694..c58bc0cfbf99 100644 --- a/spec/compiler/semantic/const_spec.cr +++ b/spec/compiler/semantic/const_spec.cr @@ -319,7 +319,7 @@ describe "Semantic: const" do "1 + 2", "1 + ZED", "ZED - 1", "ZED * 2", "ZED // 2", "1 &+ ZED", "ZED &- 1", "ZED &* 2"].each do |node| it "doesn't errors if constant depends on another one defined later through method, but constant is simple (#{node})" do - semantic(%( + assert_no_errors <<-CR ZED = 10 struct Int32 @@ -337,7 +337,7 @@ describe "Semantic: const" do end CONST1 - )) + CR end end diff --git a/spec/compiler/semantic/enum_spec.cr b/spec/compiler/semantic/enum_spec.cr index 72036dd35047..7216ff464735 100644 --- a/spec/compiler/semantic/enum_spec.cr +++ b/spec/compiler/semantic/enum_spec.cr @@ -475,23 +475,23 @@ describe "Semantic: enum" do end it "doesn't overflow when going from negative to zero (#7874)" do - semantic(%( + assert_no_errors <<-CR enum Nums Zero = -2 One Two end - )) + CR end it "doesn't overflow on flags member (#7877)" do - semantic(%( + assert_no_errors <<-CR @[Flags] enum Filter A = 1 << 29 B end - )) + CR end it "doesn't visit enum members generated by macros twice (#10104)" do diff --git a/spec/compiler/semantic/exception_spec.cr b/spec/compiler/semantic/exception_spec.cr index 8ae25ceec7a7..dd63227f4ccc 100644 --- a/spec/compiler/semantic/exception_spec.cr +++ b/spec/compiler/semantic/exception_spec.cr @@ -672,7 +672,7 @@ describe "Semantic: exception" do end it "gets a non-nilable type if all rescue are unreachable (#8751)" do - semantic(%( + assert_no_errors <<-CR while true begin foo = 1 @@ -684,6 +684,6 @@ describe "Semantic: exception" do foo &+ 2 end - )) + CR end end diff --git a/spec/compiler/semantic/pointer_spec.cr b/spec/compiler/semantic/pointer_spec.cr index 30dcde80c9d4..340268bb6761 100644 --- a/spec/compiler/semantic/pointer_spec.cr +++ b/spec/compiler/semantic/pointer_spec.cr @@ -156,7 +156,7 @@ describe "Semantic: pointer" do end it "can assign pointerof virtual type (#8216)" do - semantic(%( + assert_no_errors <<-CR class Base end @@ -167,7 +167,7 @@ describe "Semantic: pointer" do x : Pointer(Base) x = pointerof(u) - )) + CR end it "errors with non-matching generic value with value= (#10211)" do diff --git a/spec/compiler/semantic/private_spec.cr b/spec/compiler/semantic/private_spec.cr index 2f51ddb48307..b25e280c97a5 100644 --- a/spec/compiler/semantic/private_spec.cr +++ b/spec/compiler/semantic/private_spec.cr @@ -521,7 +521,7 @@ describe "Semantic: private" do end it "doesn't inherit visibility from class node in macro hook (#8794)" do - semantic(%( + assert_no_errors <<-CR, inject_primitives: false module M1 macro included include M2 @@ -563,6 +563,6 @@ describe "Semantic: private" do end Foo.new(1) - ), inject_primitives: false) + CR end end diff --git a/spec/compiler/semantic/virtual_spec.cr b/spec/compiler/semantic/virtual_spec.cr index f98fa1536606..99c2e1dd69a3 100644 --- a/spec/compiler/semantic/virtual_spec.cr +++ b/spec/compiler/semantic/virtual_spec.cr @@ -135,8 +135,8 @@ describe "Semantic: virtual" do end it "works with restriction alpha" do - nodes = parse(" - require \"prelude\" + assert_no_errors <<-CR + require "prelude" class Foo end @@ -154,8 +154,7 @@ describe "Semantic: virtual" do a = [nil, Foo.new, Bar.new, Baz.new] a.push(Baz.new || Ban.new) - ") - semantic nodes + CR end it "doesn't check cover for subclasses" do diff --git a/spec/compiler/semantic/visibility_modifiers_spec.cr b/spec/compiler/semantic/visibility_modifiers_spec.cr index e41d00642cc8..b3a509db9be2 100644 --- a/spec/compiler/semantic/visibility_modifiers_spec.cr +++ b/spec/compiler/semantic/visibility_modifiers_spec.cr @@ -414,7 +414,7 @@ describe "Visibility modifiers" do end it "handles virtual types (#8561)" do - semantic %( + assert_no_errors <<-CR module Namespace class Foo protected def foo @@ -439,6 +439,6 @@ describe "Visibility modifiers" do end Namespace::Baz.new.bar - ) + CR end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 73ae335e0ae3..4aa8f779282d 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -110,8 +110,8 @@ def assert_error(str, message = nil, *, inject_primitives = true, file = __FILE_ end end -def assert_no_errors(*args) - semantic(*args) +def assert_no_errors(*args, **opts) + semantic(*args, **opts) end def warnings_result(code, *, file = __FILE__)