3
3
4
4
{.used .}
5
5
6
- import unittest, os, osproc, strutils, strformat
6
+ import unittest, os, osproc, strutils, strformat, sequtils
7
7
import testscommon
8
8
from nimblepkg/ common import cd, nimbleVersion, nimblePackagesDirName
9
9
10
10
suite " misc tests" :
11
- # test "depsOnly + flag order test":
12
- # let (output, exitCode) = execNimbleYes("--depsOnly", "install", pkgBin2Url)
13
- # check(not output.contains("Success: packagebin2 installed successfully."))
14
- # check exitCode == QuitSuccess
15
-
16
- # test "caching of nims and ini detects changes":
17
- # cd "caching":
18
- # var (output, exitCode) = execNimble("dump")
19
- # check output.contains("0.1.0")
20
- # let
21
- # nfile = "caching.nimble"
22
- # writeFile(nfile, readFile(nfile).replace("0.1.0", "0.2.0"))
23
- # (output, exitCode) = execNimble("dump")
24
- # check output.contains("0.2.0")
25
- # writeFile(nfile, readFile(nfile).replace("0.2.0", "0.1.0"))
26
-
27
- # # Verify cached .nims runs project dir specific commands correctly
28
- # (output, exitCode) = execNimble("testpath")
29
- # check exitCode == QuitSuccess
30
- # check output.contains("imported")
31
- # check output.contains("tests/caching")
32
- # check output.contains("copied")
33
- # check output.contains("removed")
34
-
35
- # test "tasks can be called recursively":
36
- # cd "recursive":
37
- # check execNimble("recurse").exitCode == QuitSuccess
38
-
39
- # test "picks #head when looking for packages":
40
- # removeDir installDir
41
- # cd "versionClashes" / "aporiaScenario":
42
- # let (output, exitCode) = execNimbleYes("install", "--verbose")
43
- # checkpoint output
44
- # check exitCode == QuitSuccess
45
- # check execNimbleYes("remove", "aporiascenario").exitCode == QuitSuccess
46
- # check execNimbleYes("remove", "packagea").exitCode == QuitSuccess
47
-
48
- # test "pass options to the compiler with `nimble install`":
49
- # cd "passNimFlags":
50
- # let (_, exitCode) = execNimble("install", "--passNim:-d:passNimIsWorking")
51
- # check exitCode == QuitSuccess
52
-
53
- # test "install with --noRebuild flag":
54
- # cd "run":
55
- # check execNimbleYes("build").exitCode == QuitSuccess
56
-
57
- # let (output, exitCode) = execNimbleYes("install", "--noRebuild")
58
- # check exitCode == QuitSuccess
59
- # check output.contains("Skipping")
60
-
61
- # test "NimbleVersion is defined":
62
- # cd "nimbleVersionDefine":
63
- # let (output, exitCode) = execNimble("c", "-r", "src/nimbleVersionDefine.nim")
64
- # check output.contains("0.1.0")
65
- # check exitCode == QuitSuccess
66
-
67
- # let (output2, exitCode2) = execNimble("run", "nimbleVersionDefine")
68
- # check output2.contains("0.1.0")
69
- # check exitCode2 == QuitSuccess
70
-
71
- # test "compilation without warnings":
72
- # const buildDir = "./buildDir/"
73
- # const filesToBuild = [
74
- # "../src/nimble.nim",
75
- # #"../src/nimblepkg/nimscriptapi.nim",
76
- # "./tester.nim",
77
- # ]
78
-
79
- # proc execBuild(fileName: string): tuple[output: string, exitCode: int] =
80
- # result = execCmdEx(
81
- # &"nim c -o:{buildDir/fileName.splitFile.name} {fileName}")
82
-
83
- # proc checkOutput(output: string): uint =
84
- # const warningsToCheck = [
85
- # "[UnusedImport]",
86
- # "[DuplicateModuleImport]",
87
- # # "[Deprecated]", # todo fixme
88
- # "[XDeclaredButNotUsed]",
89
- # "[Spacing]",
90
- # "[ProveInit]",
91
- # # "[UnsafeDefault]", # todo fixme
92
- # ]
93
-
94
- # for line in output.splitLines():
95
- # for warning in warningsToCheck:
96
- # if line.find(warning) != stringNotFound:
97
- # once: checkpoint("Detected warnings:")
98
- # checkpoint(line)
99
- # inc(result)
100
-
101
- # removeDir(buildDir)
102
-
103
- # var linesWithWarningsCount: uint = 0
104
- # for file in filesToBuild:
105
- # let (output, exitCode) = execBuild(file)
106
- # check exitCode == QuitSuccess
107
- # linesWithWarningsCount += checkOutput(output)
108
- # check linesWithWarningsCount == 0
109
-
110
- # test "can update":
111
- # check execNimble("update").exitCode == QuitSuccess
112
-
113
- # test "can list":
114
- # check execNimble("list").exitCode == QuitSuccess
115
- # check execNimble("list", "-i").exitCode == QuitSuccess
11
+ test " depsOnly + flag order test" :
12
+ let (output, exitCode) = execNimbleYes (" --depsOnly" , " install" , pkgBin2Url)
13
+ check (not output.contains (" Success: packagebin2 installed successfully." ))
14
+ check exitCode == QuitSuccess
15
+
16
+ test " caching of nims and ini detects changes" :
17
+ cd " caching" :
18
+ var (output, exitCode) = execNimble (" dump" )
19
+ check output.contains (" 0.1.0" )
20
+ let
21
+ nfile = " caching.nimble"
22
+ writeFile (nfile, readFile (nfile).replace (" 0.1.0" , " 0.2.0" ))
23
+ (output, exitCode) = execNimble (" dump" )
24
+ check output.contains (" 0.2.0" )
25
+ writeFile (nfile, readFile (nfile).replace (" 0.2.0" , " 0.1.0" ))
26
+
27
+ # Verify cached .nims runs project dir specific commands correctly
28
+ (output, exitCode) = execNimble (" testpath" )
29
+ check exitCode == QuitSuccess
30
+ check output.contains (" imported" )
31
+ check output.contains (" tests/caching" )
32
+ check output.contains (" copied" )
33
+ check output.contains (" removed" )
34
+
35
+ test " tasks can be called recursively" :
36
+ cd " recursive" :
37
+ check execNimble (" recurse" ).exitCode == QuitSuccess
38
+
39
+ test " picks #head when looking for packages" :
40
+ removeDir installDir
41
+ cd " versionClashes" / " aporiaScenario" :
42
+ let (output, exitCode) = execNimbleYes (" install" , " --verbose" )
43
+ checkpoint output
44
+ check exitCode == QuitSuccess
45
+ check execNimbleYes (" remove" , " aporiascenario" ).exitCode == QuitSuccess
46
+ check execNimbleYes (" remove" , " packagea" ).exitCode == QuitSuccess
47
+
48
+ test " pass options to the compiler with `nimble install`" :
49
+ cd " passNimFlags" :
50
+ let (_, exitCode) = execNimble (" install" , " --passNim:-d:passNimIsWorking" )
51
+ check exitCode == QuitSuccess
52
+
53
+ test " install with --noRebuild flag" :
54
+ cd " run" :
55
+ check execNimbleYes (" build" ).exitCode == QuitSuccess
56
+
57
+ let (output, exitCode) = execNimbleYes (" install" , " --noRebuild" )
58
+ check exitCode == QuitSuccess
59
+ check output.contains (" Skipping" )
60
+
61
+ test " NimbleVersion is defined" :
62
+ cd " nimbleVersionDefine" :
63
+ let (output, exitCode) = execNimble (" c" , " -r" , " src/nimbleVersionDefine.nim" )
64
+ check output.contains (" 0.1.0" )
65
+ check exitCode == QuitSuccess
66
+
67
+ let (output2, exitCode2) = execNimble (" run" , " nimbleVersionDefine" )
68
+ check output2.contains (" 0.1.0" )
69
+ check exitCode2 == QuitSuccess
70
+
71
+ test " compilation without warnings" :
72
+ const buildDir = " ./buildDir/"
73
+ const filesToBuild = [
74
+ " ../src/nimble.nim" ,
75
+ # "../src/nimblepkg/nimscriptapi.nim",
76
+ " ./tester.nim" ,
77
+ ]
78
+
79
+ proc execBuild (fileName: string ): tuple [output: string , exitCode: int ] =
80
+ result = execCmdEx (
81
+ & " nim c -o:{ buildDir/ fileName.splitFile.name} { fileName} " )
82
+
83
+ proc checkOutput (output: string ): uint =
84
+ const warningsToCheck = [
85
+ " [UnusedImport]" ,
86
+ " [DuplicateModuleImport]" ,
87
+ # "[Deprecated]", # todo fixme
88
+ " [XDeclaredButNotUsed]" ,
89
+ " [Spacing]" ,
90
+ " [ProveInit]" ,
91
+ # "[UnsafeDefault]", # todo fixme
92
+ ]
93
+
94
+ for line in output.splitLines ():
95
+ for warning in warningsToCheck:
96
+ if line.find (warning) != stringNotFound:
97
+ once: checkpoint (" Detected warnings:" )
98
+ checkpoint (line)
99
+ inc (result )
100
+
101
+ removeDir (buildDir)
102
+
103
+ var linesWithWarningsCount: uint = 0
104
+ for file in filesToBuild:
105
+ let (output, exitCode) = execBuild (file)
106
+ check exitCode == QuitSuccess
107
+ linesWithWarningsCount += checkOutput (output)
108
+ check linesWithWarningsCount == 0
109
+
110
+ test " can update" :
111
+ check execNimble (" update" ).exitCode == QuitSuccess
112
+
113
+ test " can list" :
114
+ check execNimble (" list" ).exitCode == QuitSuccess
115
+ check execNimble (" list" , " -i" ).exitCode == QuitSuccess
116
116
117
117
test " should not install submodules when --ignoreSubmodules flag is on" :
118
118
let (_, exitCode) = execNimble (" --ignoreSubmodules" , " install" , " https://github.com/jmgomez/submodule_package" )
@@ -121,3 +121,8 @@ suite "misc tests":
121
121
test " should install submodules when --ignoreSubmodules flag is off" :
122
122
let (_, exitCode) = execNimble (" install" , " https://github.com/jmgomez/submodule_package" )
123
123
check exitCode == QuitSuccess
124
+ test " config file should end with a newline" :
125
+ let configFile = readFile (" ../config.nims" )
126
+ let content = configFile.splitLines.toSeq ()
127
+ check content[^ 2 ].strip () == " "
128
+ check content[^ 1 ].strip () == " "
0 commit comments