Skip to content

Commit ce17300

Browse files
authored
Improve CI (fixes failure and improves isolation) (#924)
* Clear Nimble dir at the start of each test suite. * Run CI every day at 7pm. * Let's try debugging. * Remove config file if backup doesn't exist in tester.
1 parent bb24fd0 commit ce17300

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
on:
22
push:
33
pull_request:
4+
schedule:
5+
- cron: "0 19 * * *"
46

57
jobs:
68
test:

tests/tester.nim

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ const stringNotFound = -1
1616
# Set env var to propagate nimble binary path
1717
putEnv("NIMBLE_TEST_BINARY_PATH", nimblePath)
1818

19-
# Clear nimble dir.
20-
removeDir(installDir)
21-
createDir(installDir)
22-
2319
# Always recompile.
2420
doAssert execCmdEx("nim c -d:danger " & path).exitCode == QuitSuccess
2521

@@ -111,8 +107,19 @@ template testRefresh(body: untyped) =
111107
# Restore config
112108
if fileExists(configBakFile):
113109
safeMoveFile(configBakFile, configFile)
110+
else:
111+
# If the old config doesn't exist, we should still get rid of this new
112+
# config to not screw up the other tests.
113+
removeFile(configFile)
114+
115+
proc beforeSuite() =
116+
# Clear nimble dir.
117+
removeDir(installDir)
118+
createDir(installDir)
114119

115120
suite "nimble refresh":
121+
beforeSuite()
122+
116123
test "can refresh with default urls":
117124
let (output, exitCode) = execNimble(["refresh"])
118125
checkpoint(output)
@@ -182,6 +189,8 @@ suite "nimble refresh":
182189
check exitCode == QuitFailure
183190

184191
suite "nimscript":
192+
beforeSuite()
193+
185194
test "can install nimscript package":
186195
cd "nimscript":
187196
let
@@ -287,6 +296,8 @@ suite "nimscript":
287296
check execNimble("c", "-d:release", "nimscript.nim").exitCode == QuitSuccess
288297

289298
suite "uninstall":
299+
beforeSuite()
300+
290301
test "can install packagebin2":
291302
let args = ["install", "https://github.com/nimble-test/packagebin2.git"]
292303
check execNimbleYes(args).exitCode == QuitSuccess
@@ -345,9 +356,9 @@ suite "uninstall":
345356
QuitSuccess
346357
check(not dirExists(installDir / "pkgs" / "PackageA-0.2.0"))
347358

348-
check execNimbleYes("uninstall", "nimscript").exitCode == QuitSuccess
349-
350359
suite "nimble dump":
360+
beforeSuite()
361+
351362
test "can dump for current project":
352363
cd "testdump":
353364
let (outp, exitCode) = execNimble("dump")
@@ -425,6 +436,8 @@ backend: "c"
425436
check: outp == outpExpected
426437

427438
suite "can handle two binary versions":
439+
beforeSuite()
440+
428441
setup:
429442
cd "binaryPackage/v1":
430443
check execNimbleYes("install").exitCode == QuitSuccess
@@ -452,6 +465,8 @@ suite "can handle two binary versions":
452465
check output.strip() == "v2"
453466

454467
suite "reverse dependencies":
468+
beforeSuite()
469+
455470
test "basic test":
456471
cd "revdep/mydep":
457472
verify execNimbleYes("install")
@@ -496,7 +511,7 @@ suite "reverse dependencies":
496511
verify execNimbleYes("remove", "mydep")
497512

498513
test "remove skips packages with revDeps (#504)":
499-
check execNimbleYes("install", "[email protected]", "[email protected]").exitCode == QuitSuccess
514+
check execNimbleYes("--debug", "install", "[email protected]", "[email protected]").exitCode == QuitSuccess
500515

501516
var (output, exitCode) = execNimble("uninstall", "nimboost", "nimfp", "-n")
502517
var lines = output.strip.processOutput()
@@ -510,6 +525,8 @@ suite "reverse dependencies":
510525
check execNimble("path", "nimfp").exitCode != QuitSuccess
511526

512527
suite "develop feature":
528+
beforeSuite()
529+
513530
test "can reject binary packages":
514531
cd "develop/binary":
515532
let (output, exitCode) = execNimble("develop")
@@ -533,7 +550,7 @@ suite "develop feature":
533550

534551
test "can develop with srcDir":
535552
cd "develop/srcdirtest":
536-
let (output, exitCode) = execNimble("develop")
553+
let (output, exitCode) = execNimbleYes("develop")
537554
checkpoint output
538555
check(not output.processOutput.inLines("will not be compiled"))
539556
check exitCode == QuitSuccess
@@ -547,7 +564,7 @@ suite "develop feature":
547564
check split[1].endsWith("develop" / "srcdirtest" / "src")
548565

549566
cd "develop/dependent":
550-
let (output, exitCode) = execNimble("c", "-r", "src" / "dependent.nim")
567+
let (output, exitCode) = execNimbleYes("c", "-r", "src" / "dependent.nim")
551568
checkpoint output
552569
check(output.processOutput.inLines("hello"))
553570
check exitCode == QuitSuccess
@@ -591,6 +608,8 @@ suite "develop feature":
591608
check output.strip() == installDir / "pkgs" / "srcdirtest-1.0"
592609

593610
suite "test command":
611+
beforeSuite()
612+
594613
test "Runs passing unit tests":
595614
cd "testCommand/testsPass":
596615
# Pass flags to test #726, #757
@@ -630,6 +649,8 @@ suite "test command":
630649
check outp.processOutput.inLines(getCurrentDir())
631650

632651
suite "check command":
652+
beforeSuite()
653+
633654
test "can succeed package":
634655
cd "binaryPackage/v1":
635656
let (outp, exitCode) = execNimble("check")
@@ -664,6 +685,8 @@ suite "check command":
664685
check outp.processOutput.inLines("package 'x' has an incorrect structure")
665686

666687
suite "multi":
688+
beforeSuite()
689+
667690
test "can install package from git subdir":
668691
var
669692
args = @["install", "https://github.com/nimble-test/multi?subdir=alpha"]
@@ -683,6 +706,8 @@ suite "multi":
683706
check execNimbleYes(args).exitCode == QuitSuccess
684707

685708
suite "Module tests":
709+
beforeSuite()
710+
686711
test "version":
687712
cd "..":
688713
check execCmdEx("nim c -r src/nimblepkg/version").exitCode == QuitSuccess
@@ -708,6 +733,8 @@ suite "Module tests":
708733
check execCmdEx("nim c -r src/nimblepkg/download").exitCode == QuitSuccess
709734

710735
suite "nimble run":
736+
beforeSuite()
737+
711738
test "Invalid binary":
712739
cd "run":
713740
let (output, exitCode) = execNimble(
@@ -806,6 +833,8 @@ suite "nimble run":
806833
check output.contains("""Testing `nimble run`: @["--test"]""")
807834

808835
suite "project local deps mode":
836+
beforeSuite()
837+
809838
test "nimbledeps exists":
810839
cd "localdeps":
811840
removeDir("nimbledeps")
@@ -831,6 +860,8 @@ suite "project local deps mode":
831860
check not dirExists("nimbledeps")
832861

833862
suite "misc tests":
863+
beforeSuite()
864+
834865
test "depsOnly + flag order test":
835866
let (output, exitCode) = execNimbleYes(
836867
"--depsOnly", "install", "https://github.com/nimble-test/packagebin2"
@@ -926,9 +957,11 @@ suite "misc tests":
926957
check execNimble("list", "-i").exitCode == QuitSuccess
927958

928959
suite "issues":
960+
beforeSuite()
961+
929962
test "issue 801":
930963
cd "issue801":
931-
let (output, exitCode) = execNimbleYes("test")
964+
let (output, exitCode) = execNimbleYes("--debug", "test")
932965
check exitCode == QuitSuccess
933966

934967
# Verify hooks work
@@ -961,22 +994,22 @@ suite "issues":
961994

962995
test "issue 727":
963996
cd "issue727":
964-
var (output, exitCode) = execNimbleYes("c", "src/abc")
997+
var (output, exitCode) = execNimbleYes("--debug", "c", "src/abc")
965998
check exitCode == QuitSuccess
966999
check fileExists(buildTests / "abc".addFileExt(ExeExt))
9671000
check not fileExists("src/def".addFileExt(ExeExt))
9681001
check not fileExists(buildTests / "def".addFileExt(ExeExt))
9691002

970-
(output, exitCode) = execNimbleYes("uninstall", "-i", "timezones")
1003+
(output, exitCode) = execNimbleYes("--debug", "uninstall", "-i", "timezones")
9711004
check exitCode == QuitSuccess
9721005

973-
(output, exitCode) = execNimbleYes("run", "def")
1006+
(output, exitCode) = execNimbleYes("--debug", "run", "def")
9741007
check exitCode == QuitSuccess
9751008
check output.contains("def727")
9761009
check not fileExists("abc".addFileExt(ExeExt))
9771010
check fileExists("def".addFileExt(ExeExt))
9781011

979-
(output, exitCode) = execNimbleYes("uninstall", "-i", "timezones")
1012+
(output, exitCode) = execNimbleYes("--debug", "uninstall", "-i", "timezones")
9801013
check exitCode == QuitSuccess
9811014

9821015
test "issue 708":
@@ -1285,6 +1318,8 @@ suite "issues":
12851318
check inLines(lines, "Nothing to build")
12861319

12871320
suite "nimble tasks":
1321+
beforeSuite()
1322+
12881323
test "can list tasks even with no tasks defined in nimble file":
12891324
cd "tasks/empty":
12901325
let (_, exitCode) = execNimble("tasks")

0 commit comments

Comments
 (0)