-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,6 @@ demo/battleship/battleship | |
tests/megatest.nim | ||
tests/megatest | ||
|
||
tests/tutils | ||
tests/basicmath | ||
tests/tbasicmath | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import std/strutils | ||
|
||
import climate | ||
|
||
|
||
proc sum(context: Context): int = | ||
context.args: | ||
if len(args) != 2: | ||
echo "The command expects exactly two arguments" | ||
return 1 | ||
|
||
echo parseInt(args[0]) + parseInt(args[1]) | ||
|
||
do: | ||
echo "The command expects exactly two arguments" | ||
return 2 | ||
|
||
proc root(context: Context): int = | ||
echo "Available commands: sum." | ||
|
||
|
||
quit parseCommands({"sum": sum}, defaultHandler = root) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import std/[unittest, os, osproc, strutils, strformat] | ||
|
||
|
||
const clifile = "tests" / "basicmath" | ||
|
||
suite "Basic CLI": | ||
discard execCmd("nim c " & clifile) | ||
|
||
test "Run command with two arguments": | ||
const | ||
a = 2 | ||
b = 3 | ||
|
||
let (output, code) = execCmdEx &"{findExe(clifile)} sum {a} {b}" | ||
|
||
check code == 0 | ||
check parseInt(strip(output)) == a + b | ||
|
||
test "Run command with too many arguments": | ||
const | ||
a = 2 | ||
b = 3 | ||
c = 4 | ||
|
||
let (output, code) = execCmdEx &"{findExe(clifile)} sum {a} {b} {c}" | ||
|
||
check code == 1 | ||
check (strip(output)) == "The command expects exactly two arguments" | ||
|
||
test "Run command without arguments": | ||
let (output, code) = execCmdEx &"{findExe(clifile)} sum" | ||
|
||
check code == 2 | ||
check (strip(output)) == "The command expects exactly two arguments" | ||
|
||
test "Run without command": | ||
let (output, code) = execCmdEx &"{findExe(clifile)}" | ||
|
||
check code == 0 | ||
check (strip(output)) == "Available commands: sum." | ||
|
This file was deleted.
Oops, something went wrong.