Skip to content

Commit 20e2e4d

Browse files
authored
check should fail if parsers parse different dependencies (#1343)
* check should fail if parsers parse different dependencies * removes rosetta test * Fixes a crash in the tests (unrelated to the feature) * missing files * better error message * updates error msg * Fixes error message * removes unused var
1 parent 2b1ac5d commit 20e2e4d

File tree

8 files changed

+72
-4
lines changed

8 files changed

+72
-4
lines changed

src/nimble.nim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,13 +1794,26 @@ proc validateDevelopDependenciesVersionRanges(dependentPkg: PackageInfo,
17941794
if errors.len > 0:
17951795
raise nimbleError(invalidDevelopDependenciesVersionsMsg(errors))
17961796

1797+
proc validateParsedDependencies(pkgInfo: PackageInfo, options: Options) =
1798+
displayInfo(&"Validating dependencies for pkgInfo {pkgInfo.infoKind}", HighPriority)
1799+
var options = options
1800+
options.useDeclarativeParser = true
1801+
let declDeps = pkgInfo.toRequiresInfo(options).requires
1802+
1803+
options.useDeclarativeParser = false
1804+
let vmDeps = pkgInfo.toFullInfo(options).requires
1805+
1806+
if declDeps != vmDeps:
1807+
raise nimbleError(&"Parsed declarative and VM dependencies are not the same: {declDeps} != {vmDeps}")
1808+
17971809
proc check(options: Options) =
17981810
try:
17991811
let currentDir = getCurrentDir()
18001812
let pkgInfo = getPkgInfo(currentDir, options, true)
18011813
validateDevelopFile(pkgInfo, options)
18021814
let dependencies = pkgInfo.processAllDependencies(options).toSeq
18031815
validateDevelopDependenciesVersionRanges(pkgInfo, dependencies, options)
1816+
validateParsedDependencies(pkgInfo, options)
18041817
displaySuccess(&"The package \"{pkgInfo.basicInfo.name}\" is valid.")
18051818
except CatchableError as error:
18061819
displayError(error)

src/nimblepkg/downloadnim.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ proc getGccArch*(options: Options): int =
123123
return when defined(windows): 32 else: 64
124124

125125
proc isRosetta*(): bool =
126-
let res = gorgeEx("sysctl -in sysctl.proc_translated")
127-
if res.exitCode == 0:
128-
return res.output.strip() == "1"
129-
return false
126+
try:
127+
let res = execCmdEx("sysctl -in sysctl.proc_translated")
128+
if res.exitCode == 0:
129+
return res.output.strip() == "1"
130+
except CatchableError:
131+
return false
130132

131133
proc getNightliesUrl*(parsedContents: JsonNode, arch: int): (string, string) =
132134
let os =
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Package
2+
3+
version = "0.1.0"
4+
author = "jmgomez"
5+
description = "A new awesome nimble package"
6+
license = "MIT"
7+
srcDir = "src"
8+
9+
10+
# Dependencies
11+
requires "results"
12+
if true:
13+
requires "stew"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This is just an example to get you started. A typical library package
2+
# exports the main API in this file. Note that you cannot rename this file
3+
# but you can remove it if you wish.
4+
5+
proc add*(x, y: int): int =
6+
## Adds two numbers together.
7+
return x + y
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This is just an example to get you started. Users of your library will
2+
# import this file by writing ``import inconsistentdeps/submodule``. Feel free to rename or
3+
# remove this file altogether. You may create additional modules alongside
4+
# this file as required.
5+
6+
type
7+
Submodule* = object
8+
name*: string
9+
10+
proc initSubmodule*(): Submodule =
11+
## Initialises a new ``Submodule`` object.
12+
Submodule(name: "Anonymous")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This is just an example to get you started. You may wish to put all of your
2+
# tests into a single file, or separate them into multiple `test1`, `test2`
3+
# etc. files (better names are recommended, just make sure the name starts with
4+
# the letter 't').
5+
#
6+
# To run these tests, simply execute `nimble test`.
7+
8+
import unittest
9+
10+
import inconsistentdeps
11+
test "can add":
12+
check add(5, 5) == 10

tests/tcheckcommand.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ suite "check command":
3838
check exitCode == QuitSuccess
3939
check outp.processOutput.inLines("success")
4040
check outp.processOutput.inLines("\"x\" is valid")
41+
42+
test "should fail if parsers parse different dependencies":
43+
cd "inconsistentdeps":
44+
let (outp, exitCode) = execNimble("check")
45+
check exitCode == QuitFailure
46+
check outp.processOutput.inLines("Parsed declarative and VM dependencies are not the same: @[results@any version] != @[results@any version, stew@any version]")

tests/tdeclarativeparser.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ suite "Declarative parsing":
7070
let (output, exitCode) = execNimble("--parser:declarative", "install", "nimlangserver")
7171
echo output
7272
check exitCode == QuitSuccess
73+
74+
75+
# suite "Declarative parser features":

0 commit comments

Comments
 (0)