Merge branch 'master' of https://github.com/Nycto/nimble into Nycto-master
This commit is contained in:
commit
6a851f5b87
14 changed files with 110 additions and 10 deletions
|
|
@ -529,6 +529,28 @@ proc execBackend(options: Options) =
|
||||||
[backend, args, bin], showOutput = true)
|
[backend, args, bin], showOutput = true)
|
||||||
display("Success:", "Execution finished", Success, HighPriority)
|
display("Success:", "Execution finished", Success, HighPriority)
|
||||||
|
|
||||||
|
proc tempOutArg(file: string): string =
|
||||||
|
## Returns the `--out` argument to pass to the compiler, using a temp file
|
||||||
|
let (_, name, _) = splitFile(file)
|
||||||
|
let dir = getNimbleTempDir() / "tests"
|
||||||
|
createDir(dir)
|
||||||
|
result = "--out:" & (dir / name)
|
||||||
|
|
||||||
|
proc test(options: Options) =
|
||||||
|
## Executes all tests
|
||||||
|
var files = toSeq(walkDir(getCurrentDir() / "tests"))
|
||||||
|
files.sort do (a, b: auto) -> int:
|
||||||
|
result = cmp(a.path, b.path)
|
||||||
|
|
||||||
|
for file in files:
|
||||||
|
if file.path.endsWith(".nim") and file.kind in { pcFile, pcLinkToFile }:
|
||||||
|
var optsCopy = options
|
||||||
|
optsCopy.action.file = file.path
|
||||||
|
optsCopy.action.backend = "c -r"
|
||||||
|
optsCopy.action.compileOptions.add("--path:.")
|
||||||
|
optsCopy.action.compileOptions.add(file.path.tempOutArg)
|
||||||
|
execBackend(optsCopy)
|
||||||
|
|
||||||
proc search(options: Options) =
|
proc search(options: Options) =
|
||||||
## Searches for matches in ``options.action.search``.
|
## Searches for matches in ``options.action.search``.
|
||||||
##
|
##
|
||||||
|
|
@ -960,6 +982,8 @@ proc doAction(options: Options) =
|
||||||
listPaths(options)
|
listPaths(options)
|
||||||
of actionBuild:
|
of actionBuild:
|
||||||
build(options)
|
build(options)
|
||||||
|
of actionTest:
|
||||||
|
test(options)
|
||||||
of actionCompile, actionDoc:
|
of actionCompile, actionDoc:
|
||||||
execBackend(options)
|
execBackend(options)
|
||||||
of actionInit:
|
of actionInit:
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ type
|
||||||
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
||||||
actionInstall, actionSearch,
|
actionInstall, actionSearch,
|
||||||
actionList, actionBuild, actionPath, actionUninstall, actionCompile,
|
actionList, actionBuild, actionPath, actionUninstall, actionCompile,
|
||||||
actionDoc, actionCustom, actionTasks, actionDevelop
|
actionDoc, actionCustom, actionTasks, actionDevelop, actionTest
|
||||||
|
|
||||||
Action* = object
|
Action* = object
|
||||||
case typ*: ActionType
|
case typ*: ActionType
|
||||||
|
|
@ -41,7 +41,7 @@ type
|
||||||
search*: seq[string] # Search string.
|
search*: seq[string] # Search string.
|
||||||
of actionInit, actionDump:
|
of actionInit, actionDump:
|
||||||
projName*: string
|
projName*: string
|
||||||
of actionCompile, actionDoc, actionBuild:
|
of actionCompile, actionDoc, actionBuild, actionTest:
|
||||||
file*: string
|
file*: string
|
||||||
backend*: string
|
backend*: string
|
||||||
compileOptions*: seq[string]
|
compileOptions*: seq[string]
|
||||||
|
|
@ -68,6 +68,7 @@ Commands:
|
||||||
build Builds a package.
|
build Builds a package.
|
||||||
c, cc, js [opts, ...] f.nim Builds a file inside a package. Passes options
|
c, cc, js [opts, ...] f.nim Builds a file inside a package. Passes options
|
||||||
to the Nim compiler.
|
to the Nim compiler.
|
||||||
|
test Compiles and executes tests
|
||||||
doc, doc2 [opts, ...] f.nim Builds documentation for a file inside a
|
doc, doc2 [opts, ...] f.nim Builds documentation for a file inside a
|
||||||
package. Passes options to the Nim compiler.
|
package. Passes options to the Nim compiler.
|
||||||
refresh [url] Refreshes the package list. A package list URL
|
refresh [url] Refreshes the package list. A package list URL
|
||||||
|
|
@ -125,6 +126,8 @@ proc parseActionType*(action: string): ActionType =
|
||||||
result = actionPath
|
result = actionPath
|
||||||
of "build":
|
of "build":
|
||||||
result = actionBuild
|
result = actionBuild
|
||||||
|
of "test":
|
||||||
|
result = actionTest
|
||||||
of "c", "compile", "js", "cpp", "cc":
|
of "c", "compile", "js", "cpp", "cc":
|
||||||
result = actionCompile
|
result = actionCompile
|
||||||
of "doc", "doc2":
|
of "doc", "doc2":
|
||||||
|
|
@ -157,7 +160,7 @@ proc initAction*(options: var Options, key: string) =
|
||||||
case options.action.typ
|
case options.action.typ
|
||||||
of actionInstall, actionPath, actionDevelop, actionUninstall:
|
of actionInstall, actionPath, actionDevelop, actionUninstall:
|
||||||
options.action.packages = @[]
|
options.action.packages = @[]
|
||||||
of actionCompile, actionDoc, actionBuild:
|
of actionCompile, actionDoc, actionBuild, actionTest:
|
||||||
options.action.compileOptions = @[]
|
options.action.compileOptions = @[]
|
||||||
options.action.file = ""
|
options.action.file = ""
|
||||||
if keyNorm == "c" or keyNorm == "compile": options.action.backend = ""
|
if keyNorm == "c" or keyNorm == "compile": options.action.backend = ""
|
||||||
|
|
@ -239,7 +242,7 @@ proc parseArgument*(key: string, result: var Options) =
|
||||||
result.action.projName = key
|
result.action.projName = key
|
||||||
of actionCompile, actionDoc:
|
of actionCompile, actionDoc:
|
||||||
result.action.file = key
|
result.action.file = key
|
||||||
of actionList, actionBuild, actionPublish:
|
of actionList, actionBuild, actionTest, actionPublish:
|
||||||
result.showHelp = true
|
result.showHelp = true
|
||||||
of actionCustom:
|
of actionCustom:
|
||||||
result.action.arguments.add(key)
|
result.action.arguments.add(key)
|
||||||
|
|
@ -278,7 +281,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
|
||||||
result.depsOnly = true
|
result.depsOnly = true
|
||||||
else:
|
else:
|
||||||
wasFlagHandled = false
|
wasFlagHandled = false
|
||||||
of actionCompile, actionDoc, actionBuild:
|
of actionCompile, actionDoc, actionBuild, actionTest:
|
||||||
let prefix = if kind == cmdShortOption: "-" else: "--"
|
let prefix = if kind == cmdShortOption: "-" else: "--"
|
||||||
if val == "":
|
if val == "":
|
||||||
result.action.compileOptions.add(prefix & flag)
|
result.action.compileOptions.add(prefix & flag)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ bin = @["nimscript"]
|
||||||
|
|
||||||
requires "nim >= 0.12.1"
|
requires "nim >= 0.12.1"
|
||||||
|
|
||||||
task test, "test description":
|
task work, "test description":
|
||||||
echo(5+5)
|
echo(5+5)
|
||||||
|
|
||||||
task c_test, "Testing `setCommand \"c\", \"nimscript.nim\"`":
|
task c_test, "Testing `setCommand \"c\", \"nimscript.nim\"`":
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
||||||
quotedArgs = quoted_args.map((x: string) => ("\"" & x & "\""))
|
quotedArgs = quoted_args.map((x: string) => ("\"" & x & "\""))
|
||||||
|
|
||||||
result = execCmdEx(quotedArgs.join(" "))
|
result = execCmdEx(quotedArgs.join(" "))
|
||||||
|
checkpoint(result.output)
|
||||||
|
|
||||||
proc execNimbleYes(args: varargs[string]): tuple[output: string, exitCode: int]=
|
proc execNimbleYes(args: varargs[string]): tuple[output: string, exitCode: int]=
|
||||||
# issue #6314
|
# issue #6314
|
||||||
|
|
@ -240,7 +241,7 @@ test "can install nimscript package":
|
||||||
|
|
||||||
test "can execute nimscript tasks":
|
test "can execute nimscript tasks":
|
||||||
cd "nimscript":
|
cd "nimscript":
|
||||||
let (output, exitCode) = execNimble("--verbose", "test")
|
let (output, exitCode) = execNimble("--verbose", "work")
|
||||||
let lines = output.strip.splitLines()
|
let lines = output.strip.splitLines()
|
||||||
check exitCode == QuitSuccess
|
check exitCode == QuitSuccess
|
||||||
check lines[^1] == "10"
|
check lines[^1] == "10"
|
||||||
|
|
@ -273,7 +274,7 @@ test "can use nimscript with repeated flags (issue #329)":
|
||||||
test "can list nimscript tasks":
|
test "can list nimscript tasks":
|
||||||
cd "nimscript":
|
cd "nimscript":
|
||||||
let (output, exitCode) = execNimble("tasks")
|
let (output, exitCode) = execNimble("tasks")
|
||||||
check "test test description".normalize in output.normalize
|
check "work test description".normalize in output.normalize
|
||||||
check exitCode == QuitSuccess
|
check exitCode == QuitSuccess
|
||||||
|
|
||||||
test "can use pre/post hooks":
|
test "can use pre/post hooks":
|
||||||
|
|
@ -558,3 +559,20 @@ suite "develop feature":
|
||||||
let url = "https://github.com/nimble-test/packagea.git"
|
let url = "https://github.com/nimble-test/packagea.git"
|
||||||
let (output, exitCode) = execNimble("develop", "-y", url)
|
let (output, exitCode) = execNimble("develop", "-y", url)
|
||||||
check exitCode == QuitSuccess
|
check exitCode == QuitSuccess
|
||||||
|
|
||||||
|
test "Runs passing unit tests":
|
||||||
|
cd "testsPass":
|
||||||
|
let (outp, exitCode) = execNimble("test")
|
||||||
|
check: exitCode == QuitSuccess
|
||||||
|
check: outp.processOutput.inLines("First test")
|
||||||
|
check: outp.processOutput.inLines("Second test")
|
||||||
|
check: outp.processOutput.inLines("Third test")
|
||||||
|
check: outp.processOutput.inLines("Executing my func")
|
||||||
|
|
||||||
|
test "Runs failing unit tests":
|
||||||
|
cd "testsFail":
|
||||||
|
let (outp, exitCode) = execNimble("test")
|
||||||
|
check: exitCode == QuitFailure
|
||||||
|
check: outp.processOutput.inLines("First test")
|
||||||
|
check: outp.processOutput.inLines("Failing Second test")
|
||||||
|
check: not outp.processOutput.inLines("Third test")
|
||||||
|
|
|
||||||
4
tests/testsFail/testing123.nim
Normal file
4
tests/testsFail/testing123.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
proc myFunc*() =
|
||||||
|
echo "Executing my func"
|
||||||
|
|
||||||
4
tests/testsFail/testing123.nimble
Normal file
4
tests/testsFail/testing123.nimble
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "John Doe"
|
||||||
|
description = "Nimble Test"
|
||||||
|
license = "BSD"
|
||||||
6
tests/testsFail/tests/a.nim
Normal file
6
tests/testsFail/tests/a.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import testing123, unittest
|
||||||
|
|
||||||
|
test "can compile nimble":
|
||||||
|
echo "First test"
|
||||||
|
myFunc()
|
||||||
|
|
||||||
6
tests/testsFail/tests/b.nim
Normal file
6
tests/testsFail/tests/b.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import testing123, unittest
|
||||||
|
|
||||||
|
test "can compile nimble":
|
||||||
|
echo "Failing Second test"
|
||||||
|
assert(false)
|
||||||
|
|
||||||
7
tests/testsFail/tests/c.nim
Normal file
7
tests/testsFail/tests/c.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import testing123, unittest
|
||||||
|
|
||||||
|
test "can compile nimble":
|
||||||
|
echo "Third test"
|
||||||
|
myFunc()
|
||||||
|
|
||||||
|
|
||||||
4
tests/testsPass/testing123.nim
Normal file
4
tests/testsPass/testing123.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
proc myFunc*() =
|
||||||
|
echo "Executing my func"
|
||||||
|
|
||||||
4
tests/testsPass/testing123.nimble
Normal file
4
tests/testsPass/testing123.nimble
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "John Doe"
|
||||||
|
description = "Nimble Test"
|
||||||
|
license = "BSD"
|
||||||
6
tests/testsPass/tests/one.nim
Normal file
6
tests/testsPass/tests/one.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import testing123, unittest
|
||||||
|
|
||||||
|
test "can compile nimble":
|
||||||
|
echo "First test"
|
||||||
|
myFunc()
|
||||||
|
|
||||||
7
tests/testsPass/tests/three.nim
Normal file
7
tests/testsPass/tests/three.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import testing123, unittest
|
||||||
|
|
||||||
|
test "can compile nimble":
|
||||||
|
echo "Third test"
|
||||||
|
myFunc()
|
||||||
|
|
||||||
|
|
||||||
7
tests/testsPass/tests/two.nim
Normal file
7
tests/testsPass/tests/two.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import testing123, unittest
|
||||||
|
|
||||||
|
test "can compile nimble":
|
||||||
|
echo "Second test"
|
||||||
|
myFunc()
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue