Skip to content

Commit

Permalink
Add 'process' module with 'exit' function (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiribenes authored Aug 26, 2024
2 parents d96a17b + 85931da commit 8905a16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions libraries/common/process.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module process

extern io def exit(errorCode: Int): Nothing =
js "(function() { process.exit(${errorCode}) })()"
llvm """
call void @exit(i64 %errorCode)
ret %Pos zeroinitializer
"""
chez "(exit ${errorCode})"
ml "(Posix.Process.exit (Word8.fromInt ${errorCode}))"
10 changes: 9 additions & 1 deletion libraries/common/test.effekt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import string
import process

interface Assertion {
def assert(condition: Bool, msg: String): Unit
Expand Down Expand Up @@ -87,4 +88,11 @@ def suite(name: String) { body: => Unit / Test }: Bool = {
println(ANSI::GREEN ++ "All tests passed (" ++ passed.show ++ " passed)" ++ ANSI::RESET)
true
}
}
}

/// Use as `def main() = mainSuite("...") { ... }`
def mainSuite(name: String) { body: => Unit / Test }: Unit = {
val result = suite(name) { body() }
val exitCode = if (result) 0 else 1
exit(exitCode)
}

0 comments on commit 8905a16

Please sign in to comment.