|
3 | 3 |
|
4 | 4 | {.used.} |
5 | 5 |
|
6 | | -import unittest, os, strutils |
| 6 | +import unittest, os, strutils, strformat |
7 | 7 | import testscommon |
| 8 | +import nimblepkg/displaymessages |
8 | 9 | from nimblepkg/common import cd |
| 10 | +from nimblepkg/developfile import developFileName |
9 | 11 |
|
10 | 12 | suite "nimble run": |
11 | 13 | test "Invalid binary": |
@@ -162,3 +164,72 @@ suite "nimble run": |
162 | 164 | [$DirSep, "run".changeFileExt(ExeExt)]) |
163 | 165 | check output.contains("""Testing `nimble run`: @["--test"]""") |
164 | 166 | check output.contains("""Whee!""") |
| 167 | + |
| 168 | + const |
| 169 | + testPkgsPath = "runDependencyBinary" |
| 170 | + dependencyPkgPath = testPkgsPath / "dependency" |
| 171 | + dependentPkgPath = testPkgsPath / "dependent" |
| 172 | + dependencyPkgBinary = dependencyPkgPath / "binary".addFileExt(ExeExt) |
| 173 | + dependentPkgDevelopFile = dependentPkgPath / developFileName |
| 174 | + packagesFilePath = "develop/packages.json" |
| 175 | + |
| 176 | + test "Run binary from dependency in Nimble cache": |
| 177 | + cleanDir installDir |
| 178 | + cleanFile dependencyPkgBinary |
| 179 | + usePackageListFile(packagesFilePath): |
| 180 | + cd dependencyPkgPath: |
| 181 | + let (_, exitCode) = execNimble("install") |
| 182 | + check exitCode == QuitSuccess |
| 183 | + cd dependentPkgPath: |
| 184 | + let (output, exitCode) = execNimble("--package:dependency", "run", |
| 185 | + "-d:danger", "binary", "--arg1", "--arg2") |
| 186 | + check exitCode == QuitSuccess |
| 187 | + var lines = output.processOutput |
| 188 | + check lines.inLinesOrdered(ignoringCompilationFlagsMsg) |
| 189 | + check lines.inLinesOrdered("--arg1") |
| 190 | + check lines.inLinesOrdered("--arg2") |
| 191 | + |
| 192 | + test "Run binary from develop mode dependency": |
| 193 | + cleanDir installDir |
| 194 | + cleanFiles dependencyPkgBinary, dependentPkgDevelopFile |
| 195 | + usePackageListFile(packagesFilePath): |
| 196 | + cd dependentPkgPath: |
| 197 | + var (output, exitCode) = execNimble("develop", "-a:../dependency") |
| 198 | + check exitCode == QuitSuccess |
| 199 | + (output, exitCode) = execNimble("--package:dependency", "run", |
| 200 | + "-d:danger", "binary", "--arg1", "--arg2") |
| 201 | + check exitCode == QuitSuccess |
| 202 | + var lines = output.processOutput |
| 203 | + const binaryName = when defined(windows): "binary.exe" else: "binary" |
| 204 | + check lines.inLinesOrdered( |
| 205 | + &"Building dependency/{binaryName} using c backend") |
| 206 | + check lines.inLinesOrdered("--arg1") |
| 207 | + check lines.inLinesOrdered("--arg2") |
| 208 | + |
| 209 | + test "Error when specified package does not exist": |
| 210 | + cleanDir installDir |
| 211 | + cleanFile dependencyPkgBinary |
| 212 | + usePackageListFile(packagesFilePath): |
| 213 | + cd dependencyPkgPath: |
| 214 | + let (_, exitCode) = execNimble("install") |
| 215 | + check exitCode == QuitSuccess |
| 216 | + cd dependentPkgPath: |
| 217 | + let (output, exitCode) = execNimble("--package:dep", "run", |
| 218 | + "-d:danger", "binary", "--arg1", "--arg2") |
| 219 | + check exitCode == QuitFailure |
| 220 | + check output.contains(notFoundPkgWithNameInPkgDepTree("dep")) |
| 221 | + |
| 222 | + test "Error when specified binary does not exist in specified package": |
| 223 | + cleanDir installDir |
| 224 | + cleanFile dependencyPkgBinary |
| 225 | + usePackageListFile(packagesFilePath): |
| 226 | + cd dependencyPkgPath: |
| 227 | + let (_, exitCode) = execNimble("install") |
| 228 | + check exitCode == QuitSuccess |
| 229 | + cd dependentPkgPath: |
| 230 | + let (output, exitCode) = execNimble("--package:dependency", "run", |
| 231 | + "-d:danger", "bin", "--arg1", "--arg2") |
| 232 | + check exitCode == QuitFailure |
| 233 | + const binaryName = when defined(windows): "bin.exe" else: "bin" |
| 234 | + check output.contains(binaryNotDefinedInPkgMsg( |
| 235 | + binaryName, "dependency")) |
0 commit comments