@@ -63,12 +63,18 @@ GitHubOS getGHOS(string os)
6363 return os in osMap ? osMap[os] : GitHubOS.selfHosted;
6464}
6565
66+ void assertGHOS (string input, GitHubOS expected)
67+ {
68+ auto actual = getGHOS(input);
69+ assert (actual == expected, fmt(" getGHOS(\" %s\" ) should return %s, but returned %s" , input, expected, actual));
70+ }
71+
6672@(" getGHOS" )
6773unittest
6874{
69- assert (getGHOS( " ubuntu-latest" ) == GitHubOS.ubuntuLatest);
70- assert (getGHOS( " macos-14" ) == GitHubOS.macos14);
71- assert (getGHOS( " crazyos-inator-2000" ) == GitHubOS.selfHosted);
75+ assertGHOS( " ubuntu-latest" , GitHubOS.ubuntuLatest);
76+ assertGHOS( " macos-14" , GitHubOS.macos14);
77+ assertGHOS( " crazyos-inator-2000" , GitHubOS.selfHosted);
7278}
7379
7480immutable SupportedSystem[string ] systemMap;
@@ -93,13 +99,19 @@ SupportedSystem getSystem(string system)
9399 return system in systemMap ? systemMap[system] : SupportedSystem.x86_64_linux;
94100}
95101
102+ void assertSystem (string input, SupportedSystem expected)
103+ {
104+ auto actual = getSystem(input);
105+ assert (actual == expected, fmt(" getSystem(\" %s\" ) should return %s, but returned %s" , input, expected, actual));
106+ }
107+
96108@(" getSystem" )
97109unittest
98110{
99- assert (getSystem( " x86_64-linux" ) == SupportedSystem.x86_64_linux);
100- assert (getSystem( " x86_64-darwin" ) == SupportedSystem.x86_64_darwin);
101- assert (getSystem( " aarch64-darwin" ) == SupportedSystem.aarch64_darwin);
102- assert (getSystem( " bender-bending-rodriguez-os" ) == SupportedSystem.x86_64_linux);
111+ assertSystem( " x86_64-linux" , SupportedSystem.x86_64_linux);
112+ assertSystem( " x86_64-darwin" , SupportedSystem.x86_64_darwin);
113+ assertSystem( " aarch64-darwin" , SupportedSystem.aarch64_darwin);
114+ assertSystem( " bender-bending-rodriguez-os" , SupportedSystem.x86_64_linux);
103115}
104116
105117struct Package
@@ -246,12 +258,18 @@ struct Params
246258GitHubOS systemToGHPlatform (SupportedSystem os) =>
247259 os == SupportedSystem.x86_64_linux ? GitHubOS.selfHosted : GitHubOS.macos14;
248260
261+ void assertGHPlatform (SupportedSystem system, GitHubOS expected)
262+ {
263+ auto actual = systemToGHPlatform(system);
264+ assert (actual == expected, fmt(" `systemToGHPlatform(%s)` should return `%s`, but returned `%s`" , system, expected, actual));
265+ }
266+
249267@(" systemToGHPlatform" )
250268unittest
251269{
252- assert (systemToGHPlatform( SupportedSystem.x86_64_linux) == GitHubOS.selfHosted);
253- assert (systemToGHPlatform( SupportedSystem.x86_64_darwin) == GitHubOS.macos14);
254- assert (systemToGHPlatform( SupportedSystem.aarch64_darwin) == GitHubOS.macos14);
270+ assertGHPlatform( SupportedSystem.x86_64_linux, GitHubOS.selfHosted);
271+ assertGHPlatform( SupportedSystem.x86_64_darwin, GitHubOS.macos14);
272+ assertGHPlatform( SupportedSystem.aarch64_darwin, GitHubOS.macos14);
255273}
256274
257275static immutable string [] uselessWarnings =
@@ -453,7 +471,9 @@ int getNixEvalWorkerCount()
453471@(" getNixEvalWorkerCount" )
454472unittest
455473{
456- assert (getNixEvalWorkerCount() == (threadsPerCPU() < MAX_WORKERS ? threadsPerCPU() : MAX_WORKERS ));
474+ auto actual = getNixEvalWorkerCount();
475+ assert (actual == (threadsPerCPU() < MAX_WORKERS ? threadsPerCPU() : MAX_WORKERS ),
476+ " 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));
457477}
458478
459479string [] meminfo;
@@ -485,11 +505,13 @@ unittest
485505{
486506 // Test when params.maxMemory is 0
487507 params.maxMemory = 0 ;
488- assert (getAvailableMemoryMB() > 0 );
508+ auto actual = getAvailableMemoryMB();
509+ assert (actual > 0 , " getAvailableMemoryMB() should return a value greater than 0, but returned %s" .fmt(actual));
489510
490511 // Test when params.maxMemory is not 0
491512 params.maxMemory = 1024 ;
492- assert (getAvailableMemoryMB() == 1024 );
513+ actual = getAvailableMemoryMB();
514+ assert (actual == 1024 , " getAvailableMemoryMB() should return 1024, but returned %s" .fmt(actual));
493515}
494516
495517void saveCachixDeploySpec (Package[] packages)
@@ -512,8 +534,14 @@ unittest
512534 createResultDirs();
513535 saveCachixDeploySpec(cast (Package[]) testPackageArray);
514536 JSONValue deploySpec = parseJSON(resultDir.buildPath(" cachix-deploy-spec.json" ).readText);
515- assert (testPackageArray[1 ].name == deploySpec[0 ][" package" ].str);
516- assert (testPackageArray[1 ].output == deploySpec[0 ][" out" ].str);
537+ string testPackageName = testPackageArray[1 ].name;
538+ string deploySpecName = deploySpec[0 ][" package" ].str;
539+ string testPackageOutput = testPackageArray[1 ].output;
540+ string deploySpecOutput = deploySpec[0 ][" out" ].str;
541+ assert (testPackageName == deploySpecName,
542+ " The name of the package should be %s, but was %s" .fmt(testPackageName, deploySpecName));
543+ assert (testPackageOutput == deploySpecOutput,
544+ " The output of the package should be %s, but was %s" .fmt(testPackageOutput, deploySpecOutput));
517545}
518546
519547void saveGHCIMatrix (Package[] packages)
@@ -548,7 +576,10 @@ unittest
548576 .parseJSON;
549577 foreach (i, pkg; testPackageArray)
550578 {
551- assert (pkg.name == matrix[" include" ][i][" name" ].str);
579+ string pkgName = pkg.name;
580+ string matrixName = matrix[" include" ][i][" name" ].str;
581+ assert (pkgName == matrixName,
582+ " The name of the package should be %s, but was %s" .fmt(pkgName, matrixName));
552583 }
553584}
554585
@@ -589,10 +620,14 @@ unittest
589620 string comment = rootDir.buildPath(" comment.md" ).readText;
590621 foreach (pkg; testSummaryTableEntryArray)
591622 {
592- assert (comment.indexOf(pkg.name) != - 1 );
593- assert (comment.indexOf(pkg.x86_64.linux) != - 1 );
594- assert (comment.indexOf(pkg.x86_64.darwin) != - 1 );
595- assert (comment.indexOf(pkg.aarch64.darwin) != - 1 );
623+ assert (comment.indexOf(pkg.name) != - 1 ,
624+ " The comment should contain the package name %s, the comment is:\n %s" .fmt(pkg.name, comment));
625+ assert (comment.indexOf(pkg.x86_64.linux) != - 1 ,
626+ " The comment should contain the x86_64 linux status %s, the comment is:\n %s" .fmt(pkg.x86_64.linux, comment));
627+ assert (comment.indexOf(pkg.x86_64.darwin) != - 1 ,
628+ " The comment should contain the x86_64 darwin status %s, the comment is:\n %s" .fmt(pkg.x86_64.darwin, comment));
629+ assert (comment.indexOf(pkg.aarch64.darwin) != - 1 ,
630+ " The comment should contain the aarch64 darwin status %s, the comment is:\n %s" .fmt(pkg.aarch64.darwin, comment));
596631 }
597632}
598633
@@ -650,34 +685,39 @@ SummaryTableEntry createSummaryTableEntry(const(Package)[] group, bool isInitial
650685 return entry;
651686}
652687
688+ void assertNixTable (SummaryTableEntry[] tableSummary, immutable (Package[]) testPackageArray, int index,
689+ string expectedLinuxStatus = " [" ~ Status.cached ~ " ](https://testPackage.com)" , string expectedDarwinStatus = Status.notSupported, string expectedAarch64Status = Status.notSupported)
690+ {
691+ string actualName = tableSummary[index].name;
692+ string expectedName = testPackageArray[index].name;
693+ assert (actualName == expectedName, fmt(" Expected name to be %s, but got %s" , expectedName, actualName));
694+
695+ string actualLinuxStatus = tableSummary[index].x86_64.linux;
696+ assert (actualLinuxStatus == expectedLinuxStatus, fmt(" Expected Linux status to be %s, but got %s" , expectedLinuxStatus, actualLinuxStatus));
697+
698+ string actualDarwinStatus = tableSummary[index].x86_64.darwin;
699+ assert (actualDarwinStatus == expectedDarwinStatus, fmt(" Expected Darwin status to be %s, but got %s" , expectedDarwinStatus, actualDarwinStatus));
700+
701+ string actualAarch64Status = tableSummary[index].aarch64.darwin;
702+ assert (actualAarch64Status == expectedAarch64Status, fmt(" Expected Aarch64 Darwin status to be %s, but got %s" , expectedAarch64Status, actualAarch64Status));
703+ }
704+
653705@(" convertNixEvalToTableSummary/getStatus" )
654706unittest
655707{
656708 auto tableSummary = convertNixEvalToTableSummary(
657709 testPackageArray,
658710 isInitial: false
659711 );
660- assert (tableSummary[0 ].name == testPackageArray[0 ].name);
661- assert (tableSummary[0 ].x86_64.linux == " [" ~ Status.cached ~ " ](https://testPackage.com)" );
662- assert (tableSummary[0 ].x86_64.darwin == Status.notSupported);
663- assert (tableSummary[0 ].aarch64.darwin == Status.notSupported);
664- assert (tableSummary[1 ].name == testPackageArray[1 ].name);
665- assert (tableSummary[1 ].x86_64.linux == Status.notSupported);
666- assert (tableSummary[1 ].x86_64.darwin == Status.notSupported);
667- assert (tableSummary[1 ].aarch64.darwin == Status.buildFailed);
712+ assertNixTable(tableSummary, testPackageArray, 0 );
713+ assertNixTable(tableSummary, testPackageArray, 1 , Status.notSupported, Status.notSupported, Status.buildFailed);
668714
669715 tableSummary = convertNixEvalToTableSummary(
670716 testPackageArray,
671717 isInitial: true
672718 );
673- assert (tableSummary[0 ].name == testPackageArray[0 ].name);
674- assert (tableSummary[0 ].x86_64.linux == " [" ~ Status.cached ~ " ](https://testPackage.com)" );
675- assert (tableSummary[0 ].x86_64.darwin == Status.notSupported);
676- assert (tableSummary[0 ].aarch64.darwin == Status.notSupported);
677- assert (tableSummary[1 ].name == testPackageArray[1 ].name);
678- assert (tableSummary[1 ].x86_64.linux == Status.notSupported);
679- assert (tableSummary[1 ].x86_64.darwin == Status.notSupported);
680- assert (tableSummary[1 ].aarch64.darwin == Status.building);
719+ assertNixTable(tableSummary, testPackageArray, 0 );
720+ assertNixTable(tableSummary, testPackageArray, 1 , Status.notSupported, Status.notSupported, Status.building);
681721}
682722
683723void printTableForCacheStatus (Package[] packages)
@@ -733,12 +773,11 @@ unittest
733773 cacheUrl: nixosCacheEndpoint ~ storePathHash ~ " .narinfo" ,
734774 };
735775
736- assert (! testPackage.isCached);
737- assert (checkPackage(testPackage).isCached);
776+ assert (checkPackage(testPackage).isCached, " Package %s should be cached" .fmt(testPackage.cacheUrl));
738777
739778 testPackage.cacheUrl = nixosCacheEndpoint ~ " nonexistent.narinfo" ;
740779
741- assert (! checkPackage(testPackage).isCached);
780+ assert (! checkPackage(testPackage).isCached, " Package %s should not be cached " .fmt(testPackage.cacheUrl) );
742781}
743782
744783Package[] getPrecalcMatrix ()
@@ -770,13 +809,23 @@ unittest
770809 string precalcMatrixStr = " {\" include\" : [{\" name\" : \" test\" , \" allowedToFail\" : false, \" attrPath\" : \" test\" , \" cacheUrl\" : \" url\" , \" isCached\" : true, \" os\" : \" linux\" , \" system\" : \" x86_64-linux\" , \" output\" : \" output\" }]}" ;
771810 params.precalcMatrix = precalcMatrixStr;
772811 auto packages = getPrecalcMatrix();
812+ Package testPackage = {
813+ name: " test" ,
814+ allowedToFail: false ,
815+ attrPath: " test" ,
816+ cacheUrl: " url" ,
817+ isCached: true ,
818+ os: GitHubOS.selfHosted,
819+ system: SupportedSystem.x86_64_linux,
820+ output: " output"
821+ };
773822 assert (packages.length == 1 );
774- assert (packages[0 ].name == " test " );
775- assert (! packages[0 ].allowedToFail);
776- assert (packages[0 ].attrPath == " test " );
777- assert (packages[0 ].cacheUrl == " url " );
823+ assert (packages[0 ].name == testPackage.name, " Expected %s, got %s " .fmt(testPackage.name, packages[ 0 ].name) );
824+ assert (! packages[0 ].allowedToFail, " Expected %s, got %s " .fmt(testPackage.allowedToFail, packages[ 0 ].allowedToFail) );
825+ assert (packages[0 ].attrPath == testPackage.attrPath, " Expected %s, got %s " .fmt(testPackage.attrPath, packages[ 0 ].attrPath) );
826+ assert (packages[0 ].cacheUrl == testPackage.cacheUrl, " Expected %s, got %s " .fmt(testPackage.cacheUrl, packages[ 0 ].cacheUrl) );
778827 assert (packages[0 ].isCached);
779- assert (packages[0 ].os == GitHubOS.selfHosted );
780- assert (packages[0 ].system == SupportedSystem.x86_64_linux );
781- assert (packages[0 ].output == " output" );
828+ assert (packages[0 ].os == testPackage.os, " Expected %s, got %s " .fmt(testPackage.os, packages[ 0 ].os) );
829+ assert (packages[0 ].system == testPackage.system, " Expected %s, got %s " .fmt(testPackage.system, packages[ 0 ].system) );
830+ assert (packages[0 ].output == testPackage. output, " Expected %s, got %s " .fmt(testPackage.output, packages[ 0 ].output) );
782831}
0 commit comments