@@ -62,12 +62,18 @@ GitHubOS getGHOS(string os)
6262 return os in osMap ? osMap[os] : GitHubOS.selfHosted;
6363}
6464
65+ void assertGHOS (string input, GitHubOS expected)
66+ {
67+ auto actual = getGHOS(input);
68+ assert (actual == expected, fmt(" getGHOS(\" %s\" ) should return %s, but returned %s" , input, expected, actual));
69+ }
70+
6571@(" getGHOS" )
6672unittest
6773{
68- assert (getGHOS( " ubuntu-latest" ) == GitHubOS.ubuntuLatest);
69- assert (getGHOS( " macos-14" ) == GitHubOS.macos14);
70- assert (getGHOS( " crazyos-inator-2000" ) == GitHubOS.selfHosted);
74+ assertGHOS( " ubuntu-latest" , GitHubOS.ubuntuLatest);
75+ assertGHOS( " macos-14" , GitHubOS.macos14);
76+ assertGHOS( " crazyos-inator-2000" , GitHubOS.selfHosted);
7177}
7278
7379immutable SupportedSystem[string ] systemMap;
@@ -92,13 +98,19 @@ SupportedSystem getSystem(string system)
9298 return system in systemMap ? systemMap[system] : SupportedSystem.x86_64_linux;
9399}
94100
101+ void assertSystem (string input, SupportedSystem expected)
102+ {
103+ auto actual = getSystem(input);
104+ assert (actual == expected, fmt(" getSystem(\" %s\" ) should return %s, but returned %s" , input, expected, actual));
105+ }
106+
95107@(" getSystem" )
96108unittest
97109{
98- assert (getSystem( " x86_64-linux" ) == SupportedSystem.x86_64_linux);
99- assert (getSystem( " x86_64-darwin" ) == SupportedSystem.x86_64_darwin);
100- assert (getSystem( " aarch64-darwin" ) == SupportedSystem.aarch64_darwin);
101- assert (getSystem( " bender-bending-rodriguez-os" ) == SupportedSystem.x86_64_linux);
110+ assertSystem( " x86_64-linux" , SupportedSystem.x86_64_linux);
111+ assertSystem( " x86_64-darwin" , SupportedSystem.x86_64_darwin);
112+ assertSystem( " aarch64-darwin" , SupportedSystem.aarch64_darwin);
113+ assertSystem( " bender-bending-rodriguez-os" , SupportedSystem.x86_64_linux);
102114}
103115
104116struct Package
@@ -229,12 +241,18 @@ struct Params
229241GitHubOS systemToGHPlatform (SupportedSystem os) =>
230242 os == SupportedSystem.x86_64_linux ? GitHubOS.selfHosted : GitHubOS.macos14;
231243
244+ void assertGHPlatform (SupportedSystem system, GitHubOS expected)
245+ {
246+ auto actual = systemToGHPlatform(system);
247+ assert (actual == expected, fmt(" `systemToGHPlatform(%s)` should return `%s`, but returned `%s`" , system, expected, actual));
248+ }
249+
232250@(" systemToGHPlatform" )
233251unittest
234252{
235- assert (systemToGHPlatform( SupportedSystem.x86_64_linux) == GitHubOS.selfHosted);
236- assert (systemToGHPlatform( SupportedSystem.x86_64_darwin) == GitHubOS.macos14);
237- assert (systemToGHPlatform( SupportedSystem.aarch64_darwin) == GitHubOS.macos14);
253+ assertGHPlatform( SupportedSystem.x86_64_linux, GitHubOS.selfHosted);
254+ assertGHPlatform( SupportedSystem.x86_64_darwin, GitHubOS.macos14);
255+ assertGHPlatform( SupportedSystem.aarch64_darwin, GitHubOS.macos14);
238256}
239257
240258static immutable string [] uselessWarnings =
@@ -371,7 +389,9 @@ int getNixEvalWorkerCount()
371389@(" getNixEvalWorkerCount" )
372390unittest
373391{
374- assert (getNixEvalWorkerCount() == (threadsPerCPU() < MAX_WORKERS ? threadsPerCPU() : MAX_WORKERS ));
392+ auto actual = getNixEvalWorkerCount();
393+ assert (actual == (threadsPerCPU() < MAX_WORKERS ? threadsPerCPU() : MAX_WORKERS ),
394+ " getNixEvalWorkerCount() should return the number of threads per CPU if it is less than MAX_WORKERS, otherwise it should return MAX_WORKERS, but returned %s" .fmt(actual));
375395}
376396
377397string [] meminfo;
@@ -403,11 +423,13 @@ unittest
403423{
404424 // Test when params.maxMemory is 0
405425 params.maxMemory = 0 ;
406- assert (getAvailableMemoryMB() > 0 );
426+ auto actual = getAvailableMemoryMB();
427+ assert (actual > 0 , " getAvailableMemoryMB() should return a value greater than 0, but returned %s" .fmt(actual));
407428
408429 // Test when params.maxMemory is not 0
409430 params.maxMemory = 1024 ;
410- assert (getAvailableMemoryMB() == 1024 );
431+ actual = getAvailableMemoryMB();
432+ assert (actual == 1024 , " getAvailableMemoryMB() should return 1024, but returned %s" .fmt(actual));
411433}
412434
413435void saveCachixDeploySpec (Package[] packages)
@@ -430,8 +452,14 @@ unittest
430452 createResultDirs();
431453 saveCachixDeploySpec(cast (Package[]) testPackageArray);
432454 JSONValue deploySpec = parseJSON(resultDir.buildPath(" cachix-deploy-spec.json" ).readText);
433- assert (testPackageArray[1 ].name == deploySpec[0 ][" package" ].str);
434- assert (testPackageArray[1 ].output == deploySpec[0 ][" out" ].str);
455+ string testPackageName = testPackageArray[1 ].name;
456+ string deploySpecName = deploySpec[0 ][" package" ].str;
457+ string testPackageOutput = testPackageArray[1 ].output;
458+ string deploySpecOutput = deploySpec[0 ][" out" ].str;
459+ assert (testPackageName == deploySpecName,
460+ " The name of the package should be %s, but was %s" .fmt(testPackageName, deploySpecName));
461+ assert (testPackageOutput == deploySpecOutput,
462+ " The output of the package should be %s, but was %s" .fmt(testPackageOutput, deploySpecOutput));
435463}
436464
437465void saveGHCIMatrix (Package[] packages)
@@ -466,7 +494,10 @@ unittest
466494 .parseJSON;
467495 foreach (i, pkg; testPackageArray)
468496 {
469- assert (pkg.name == matrix[" include" ][i][" name" ].str);
497+ string pkgName = pkg.name;
498+ string matrixName = matrix[" include" ][i][" name" ].str;
499+ assert (pkgName == matrixName,
500+ " The name of the package should be %s, but was %s" .fmt(pkgName, matrixName));
470501 }
471502}
472503
@@ -507,10 +538,14 @@ unittest
507538 string comment = rootDir.buildPath(" comment.md" ).readText;
508539 foreach (pkg; testSummaryTableEntryArray)
509540 {
510- assert (comment.indexOf(pkg.name) != - 1 );
511- assert (comment.indexOf(pkg.x86_64.linux) != - 1 );
512- assert (comment.indexOf(pkg.x86_64.darwin) != - 1 );
513- assert (comment.indexOf(pkg.aarch64.darwin) != - 1 );
541+ assert (comment.indexOf(pkg.name) != - 1 ,
542+ " The comment should contain the package name %s, the comment is:\n %s" .fmt(pkg.name, comment));
543+ assert (comment.indexOf(pkg.x86_64.linux) != - 1 ,
544+ " The comment should contain the x86_64 linux status %s, the comment is:\n %s" .fmt(pkg.x86_64.linux, comment));
545+ assert (comment.indexOf(pkg.x86_64.darwin) != - 1 ,
546+ " The comment should contain the x86_64 darwin status %s, the comment is:\n %s" .fmt(pkg.x86_64.darwin, comment));
547+ assert (comment.indexOf(pkg.aarch64.darwin) != - 1 ,
548+ " The comment should contain the aarch64 darwin status %s, the comment is:\n %s" .fmt(pkg.aarch64.darwin, comment));
514549 }
515550}
516551
@@ -564,30 +599,35 @@ SummaryTableEntry createSummaryTableEntry(Package[] group)
564599 return entry;
565600}
566601
602+ void assertNixTable (SummaryTableEntry[] tableSummary, immutable (Package[]) testPackageArray, int index,
603+ string expectedLinuxStatus = " [" ~ Status.cached ~ " ](https://testPackage.com)" , string expectedDarwinStatus = Status.notSupported, string expectedAarch64Status = Status.notSupported)
604+ {
605+ string actualName = tableSummary[index].name;
606+ string expectedName = testPackageArray[index].name;
607+ assert (actualName == expectedName, fmt(" Expected name to be %s, but got %s" , expectedName, actualName));
608+
609+ string actualLinuxStatus = tableSummary[index].x86_64.linux;
610+ assert (actualLinuxStatus == expectedLinuxStatus, fmt(" Expected Linux status to be %s, but got %s" , expectedLinuxStatus, actualLinuxStatus));
611+
612+ string actualDarwinStatus = tableSummary[index].x86_64.darwin;
613+ assert (actualDarwinStatus == expectedDarwinStatus, fmt(" Expected Darwin status to be %s, but got %s" , expectedDarwinStatus, actualDarwinStatus));
614+
615+ string actualAarch64Status = tableSummary[index].aarch64.darwin;
616+ assert (actualAarch64Status == expectedAarch64Status, fmt(" Expected Aarch64 Darwin status to be %s, but got %s" , expectedAarch64Status, actualAarch64Status));
617+ }
618+
567619@(" convertNixEvalToTableSummary/getStatus" )
568620unittest
569621{
570622 auto tableSummary = convertNixEvalToTableSummary(cast (Package[]) testPackageArray);
571- assert (tableSummary[0 ].name == testPackageArray[0 ].name);
572- assert (tableSummary[0 ].x86_64.linux == " [" ~ Status.cached ~ " ](https://testPackage.com)" );
573- assert (tableSummary[0 ].x86_64.darwin == Status.notSupported);
574- assert (tableSummary[0 ].aarch64.darwin == Status.notSupported);
575- assert (tableSummary[1 ].name == testPackageArray[1 ].name);
576- assert (tableSummary[1 ].x86_64.linux == Status.notSupported);
577- assert (tableSummary[1 ].x86_64.darwin == Status.notSupported);
578- assert (tableSummary[1 ].aarch64.darwin == Status.buildFailed);
623+ assertNixTable(tableSummary, testPackageArray, 0 );
624+ assertNixTable(tableSummary, testPackageArray, 1 , Status.notSupported, Status.notSupported, Status.buildFailed);
579625
580626 params.isInitial = true ;
581627 tableSummary = convertNixEvalToTableSummary(cast (Package[]) testPackageArray);
582628 params.isInitial = false ;
583- assert (tableSummary[0 ].name == testPackageArray[0 ].name);
584- assert (tableSummary[0 ].x86_64.linux == " [" ~ Status.cached ~ " ](https://testPackage.com)" );
585- assert (tableSummary[0 ].x86_64.darwin == Status.notSupported);
586- assert (tableSummary[0 ].aarch64.darwin == Status.notSupported);
587- assert (tableSummary[1 ].name == testPackageArray[1 ].name);
588- assert (tableSummary[1 ].x86_64.linux == Status.notSupported);
589- assert (tableSummary[1 ].x86_64.darwin == Status.notSupported);
590- assert (tableSummary[1 ].aarch64.darwin == Status.building);
629+ assertNixTable(tableSummary, testPackageArray, 0 );
630+ assertNixTable(tableSummary, testPackageArray, 1 , Status.notSupported, Status.notSupported, Status.building);
591631}
592632
593633void printTableForCacheStatus (Package[] packages)
@@ -640,12 +680,11 @@ unittest
640680 cacheUrl: nixosCacheEndpoint ~ storePathHash ~ " .narinfo" ,
641681 };
642682
643- assert (! testPackage.isCached);
644- assert (checkPackage(testPackage).isCached);
683+ assert (checkPackage(testPackage).isCached, " Package %s should be cached" .fmt(testPackage.cacheUrl));
645684
646685 testPackage.cacheUrl = nixosCacheEndpoint ~ " nonexistent.narinfo" ;
647686
648- assert (! checkPackage(testPackage).isCached);
687+ assert (! checkPackage(testPackage).isCached, " Package %s should not be cached " .fmt(testPackage.cacheUrl) );
649688}
650689
651690Package[] getPrecalcMatrix ()
@@ -677,13 +716,23 @@ unittest
677716 string precalcMatrixStr = " {\" include\" : [{\" name\" : \" test\" , \" allowedToFail\" : false, \" attrPath\" : \" test\" , \" cacheUrl\" : \" url\" , \" isCached\" : true, \" os\" : \" linux\" , \" system\" : \" x86_64-linux\" , \" output\" : \" output\" }]}" ;
678717 params.precalcMatrix = precalcMatrixStr;
679718 auto packages = getPrecalcMatrix();
719+ Package testPackage = {
720+ name: " test" ,
721+ allowedToFail: false ,
722+ attrPath: " test" ,
723+ cacheUrl: " url" ,
724+ isCached: true ,
725+ os: GitHubOS.selfHosted,
726+ system: SupportedSystem.x86_64_linux,
727+ output: " output"
728+ };
680729 assert (packages.length == 1 );
681- assert (packages[0 ].name == " test " );
682- assert (! packages[0 ].allowedToFail);
683- assert (packages[0 ].attrPath == " test " );
684- assert (packages[0 ].cacheUrl == " url " );
730+ assert (packages[0 ].name == testPackage.name, " Expected %s, got %s " .fmt(testPackage.name, packages[ 0 ].name) );
731+ assert (! packages[0 ].allowedToFail, " Expected %s, got %s " .fmt(testPackage.allowedToFail, packages[ 0 ].allowedToFail) );
732+ assert (packages[0 ].attrPath == testPackage.attrPath, " Expected %s, got %s " .fmt(testPackage.attrPath, packages[ 0 ].attrPath) );
733+ assert (packages[0 ].cacheUrl == testPackage.cacheUrl, " Expected %s, got %s " .fmt(testPackage.cacheUrl, packages[ 0 ].cacheUrl) );
685734 assert (packages[0 ].isCached);
686- assert (packages[0 ].os == GitHubOS.selfHosted );
687- assert (packages[0 ].system == SupportedSystem.x86_64_linux );
688- assert (packages[0 ].output == " output" );
735+ assert (packages[0 ].os == testPackage.os, " Expected %s, got %s " .fmt(testPackage.os, packages[ 0 ].os) );
736+ assert (packages[0 ].system == testPackage.system, " Expected %s, got %s " .fmt(testPackage.system, packages[ 0 ].system) );
737+ assert (packages[0 ].output == testPackage. output, " Expected %s, got %s " .fmt(testPackage.output, packages[ 0 ].output) );
689738}
0 commit comments