This commit is contained in:
Dominik Picheta 2015-12-24 10:26:07 +00:00
commit 96ddb12da8
4 changed files with 44 additions and 1 deletions

View file

@ -54,7 +54,7 @@ proc validatePackageName*(name: string) =
if name[0] in {'0'..'9'}: if name[0] in {'0'..'9'}:
raise newException(NimbleError, raise newException(NimbleError,
"Invalid package name: cannot beging with " & name[0]) "Invalid package name: cannot begin with " & name[0])
var prevWasUnderscore = false var prevWasUnderscore = false
for c in name: for c in name:
@ -90,6 +90,11 @@ proc validatePackageInfo(pkgInfo: PackageInfo, path: string) =
if pkgInfo.name == "": if pkgInfo.name == "":
raise newException(NimbleError, "Incorrect .nimble file: " & path & raise newException(NimbleError, "Incorrect .nimble file: " & path &
" does not contain a name field.") " does not contain a name field.")
if pkgInfo.name.normalize != path.splitFile.name.normalize:
raise newException(NimbleError,
"The .nimble file name must match name specified inside it.")
if pkgInfo.version == "": if pkgInfo.version == "":
raise newException(NimbleError, "Incorrect .nimble file: " & path & raise newException(NimbleError, "Incorrect .nimble file: " & path &
" does not contain a version field.") " does not contain a version field.")
@ -231,6 +236,8 @@ proc readPackageInfo*(nf: NimbleFile; onlyMinimalInfo=false): PackageInfo =
## populated. The isNimScript field can also be relied on. ## populated. The isNimScript field can also be relied on.
result = initPackageInfo(nf) result = initPackageInfo(nf)
validatePackageName(nf.splitFile.name)
var success = false var success = false
var iniError: ref NimbleError var iniError: ref NimbleError
# Attempt ini-format first. # Attempt ini-format first.

View file

@ -0,0 +1,11 @@
# Package
version = "0.1.0"
author = "Dominik Picheta"
description = "Test to see if certain characters are disallowed in pkg names."
license = "BSD"
# Dependencies
requires "nim >= 0.12.1"

View file

@ -0,0 +1,12 @@
# Package
packageName = "foobar"
version = "0.1.0"
author = "Dominik Picheta"
description = "Test to see if certain characters are disallowed in pkg names."
license = "BSD"
# Dependencies
requires "nim >= 0.12.1"

View file

@ -65,6 +65,19 @@ test "issue #27":
cd "issue27": cd "issue27":
check execCmdEx("../" & path & " install -y").exitCode == QuitSuccess check execCmdEx("../" & path & " install -y").exitCode == QuitSuccess
test "issue #126":
cd "issue126/a":
let (output, exitCode) = execCmdEx("../../" & path & " install")
let lines = output.strip.splitLines()
check exitCode != QuitSuccess
check "Invalid package name: cannot contain '-'" in lines[^1]
cd "issue126/b":
let (output1, exitCode1) = execCmdEx("../../" & path & " install")
let lines1 = output1.strip.splitLines()
check exitCode1 != QuitSuccess
check "The .nimble file name must match name specified inside it." in lines1[^1]
test "can list": test "can list":
check execCmdEx(path & " list").exitCode == QuitSuccess check execCmdEx(path & " list").exitCode == QuitSuccess