Skip to content

Commit

Permalink
Replace semantic with assert_no_errors in compiler specs whenever…
Browse files Browse the repository at this point in the history
… possible (#11288)
  • Loading branch information
HertzDevil authored Oct 24, 2021
1 parent 6ef1355 commit dfa28a4
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 92 deletions.
116 changes: 58 additions & 58 deletions spec/compiler/semantic/abstract_def_spec.cr

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions spec/compiler/semantic/annotation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
16 changes: 8 additions & 8 deletions spec/compiler/semantic/block_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1318,15 +1318,15 @@ 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
end
foo do |x, y|
end
))
CR
end

it "auto-unpacks tuple, captured block with multiple statements" do
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -1606,6 +1606,6 @@ describe "Block inference" do
foo = Bar(Bool).new.as(Foo)
foo.foo
))
CR
end
end
4 changes: 2 additions & 2 deletions spec/compiler/semantic/closure_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/const_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -337,7 +337,7 @@ describe "Semantic: const" do
end
CONST1
))
CR
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/compiler/semantic/enum_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/exception_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -684,6 +684,6 @@ describe "Semantic: exception" do
foo &+ 2
end
))
CR
end
end
4 changes: 2 additions & 2 deletions spec/compiler/semantic/pointer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/private_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -563,6 +563,6 @@ describe "Semantic: private" do
end
Foo.new(1)
), inject_primitives: false)
CR
end
end
7 changes: 3 additions & 4 deletions spec/compiler/semantic/virtual_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/visibility_modifiers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -439,6 +439,6 @@ describe "Visibility modifiers" do
end
Namespace::Baz.new.bar
)
CR
end
end
4 changes: 2 additions & 2 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit dfa28a4

Please sign in to comment.