Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow asyncronhous tests. #669

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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