Skip to content

Commit

Permalink
Allow asyncronhous tests. (#669)
Browse files Browse the repository at this point in the history
* Allow asyncronhous tests.

Fixes #662

* Update core/tests/tests/Test.mint

Co-authored-by: Sijawusz Pur Rahnama <[email protected]>

---------

Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
  • Loading branch information
gdotdesign and Sija authored Sep 19, 2023
1 parent dcf97cf commit 5f1b7bb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
9 changes: 9 additions & 0 deletions core/tests/tests/Test.mint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
suite "Test (Async)" {
test "await Bool" {
await true
}

test "await Test.Context(Bool)" {
await Test.Context.of(true)
}
}
2 changes: 2 additions & 0 deletions spec/errors/test_type_mismatch
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ The type of a test does not match any of the allowed types.

I was expecting one of:

Promise(Test.Context(a))
Test.Context(a)
Promise(Bool)
Bool

Instead it is:
Expand Down
6 changes: 6 additions & 0 deletions spec/examples/test
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ suite "X" {
true
}
}
-------------------------------------------------------------------------------
suite "X" {
test "X" {
await true
}
}
2 changes: 1 addition & 1 deletion src/compilers/test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Mint

expression ||= compile(raw_expression)

"{ name: #{name}, location: #{location}, proc: (constants) => { return #{expression} } }"
"{ name: #{name}, location: #{location}, proc: async (constants) => { return #{expression} } }"
end
end
end
9 changes: 9 additions & 0 deletions src/type_checker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module Mint
TEST_CONTEXT = Type.new("Test.Context", [Variable.new("a")] of Checkable)
STYLE_MAP = Type.new("Map", [STRING, STRING] of Checkable)
VOID_PROMISE = Type.new("Promise", [VOID] of Checkable)
BOOL_PROMISE = Type.new("Promise", [BOOL] of Checkable)
TEST_PROMISE = Type.new("Promise", [TEST_CONTEXT] of Checkable)

VALID_IF_TYPES = [
VOID_PROMISE,
Expand All @@ -40,6 +42,13 @@ module Mint
HTML,
] of Checkable

VALID_TEST_TYPES = [
TEST_PROMISE,
TEST_CONTEXT,
BOOL_PROMISE,
BOOL,
] of Checkable

getter records, artifacts, formatter, web_components

property? checking = true
Expand Down
18 changes: 7 additions & 11 deletions src/type_checkers/test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ module Mint
type =
resolve node.expression

if Comparer.compare(type, BOOL) ||
Comparer.compare(type, TEST_CONTEXT)
else
error! :test_type_mismatch do
block "The type of a test does not match any of the allowed types."
block "I was expecting one of:"
error! :test_type_mismatch do
block "The type of a test does not match any of the allowed types."
block "I was expecting one of:"

snippet "Test.Context(a)\nBool"
snippet "Instead it is:", type
snippet "The test in question is here:", node.expression.expressions.last
end
end
snippet VALID_TEST_TYPES.map(&.to_pretty).join("\n")
snippet "Instead it is:", type
snippet "The test in question is here:", node.expression.expressions.last
end unless Comparer.matches_any? type, VALID_TEST_TYPES

VOID
end
Expand Down

0 comments on commit 5f1b7bb

Please sign in to comment.