Add alias for "fail"

This commit is contained in:
2020-07-02 18:10:48 +02:00
parent 6bd1a41515
commit 2f1f5ed2f8
2 changed files with 21 additions and 1 deletions

View File

@@ -45,3 +45,7 @@ proc fail*[T](msg: string): OP[T] =
assert res.error == "Something is wrong!"
OP[T](isOK: false, error: msg)
proc fail*(T: typedesc, msg: string): OP[T] =
## Alias for `fail[T](string) proc <#fail,string>`_
fail[T] msg

View File

@@ -19,7 +19,7 @@ test "Check proc results":
check data.isOk
check data.val == "This is test code!"
test "Check failing proc":
test "Check failing result proc":
proc someProc(): OP[int] =
result.fail "Not implemented!"
@@ -27,6 +27,22 @@ test "Check failing proc":
assert data.isOk == false
assert data.error == "Not implemented!"
test "Check failing typedesc proc ":
proc someProc(): OP[int] =
fail(int, "Not implemented!")
let data = someProc()
assert data.isOk == false
assert data.error == "Not implemented!"
test "Check failing type param proc ":
proc someProc(): OP[int] =
op.fail[int]("Not implemented!")
let data = someProc()
assert data.isOk == false
assert data.error == "Not implemented!"
test "Check changing result":
proc checker(): OP[int] =
result = ok 42