Skip to content

Commit

Permalink
Fix unit tests to work with different CRT linking and with WL13+ afte…
Browse files Browse the repository at this point in the history
…r MUnit refactor.
  • Loading branch information
rafal-c committed Jul 27, 2022
1 parent 552d46d commit 0d449ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
35 changes: 19 additions & 16 deletions tests/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,38 @@ else()
return()
endif()

get_target_property(LLU_CRT_LINKING LLU MSVC_RUNTIME_LIBRARY)
if(NOT LLU_CRT_LINKING)
set(LLU_CRT_LINKING ${CMAKE_MSVC_RUNTIME_LIBRARY})
endif()

foreach(UnitTest ${TEST_MODULES})
set(MODULE_CODE
[===[
Needs["MUnit`"];
$LLUInstallDir = "${CMAKE_INSTALL_PREFIX}";
$LinkToCRTStaticallyQ = "${LLU_CRT_LINKING}";
report = Catch[
TestReport["${UnitTest}TestSuite.mt", MemoryConstraint -> Quantity[500, "MB"], TimeConstraint -> 30],
_String,
Function[{value, tag}, Print["ERROR: " <> ToString[value]]; Exit[1]]
];
report = report /. resObj_TestResultObject :> RuleCondition[TextString[resObj[{
"TestID",
"ExpectedOutput",
"ActualOutput",
"ExpectedMessages",
"ActualMessages",
"AbsoluteTimeUsed",
"MemoryUsed"
}], AssociationFormat -> {"{\n\t\t", ",\n\t\t", "\n\t}", " -> "}]];
propertiesToPrint = {"Title", "TimeElapsed", "Aborted", "TestsSucceededCount", "TestsFailedCount"};
failedCount = report["TestsFailedCount"];
indexKeyword = If[$VersionNumber >= 13, "Keys", "Indices"];
propertiesToPrint = {"Title", "Aborted"};
failedCount = 0;
Scan[
If[report["TestsFailed" <> # <> indexKeyword] != {},
AppendTo[propertiesToPrint, "TestsFailed" <> # <> indexKeyword];
failedCount += Length @ report["TestsFailed" <> # <> indexKeyword];
]&, {"WrongResults", "WithMessages", "WithErrors"}
];
If[failedCount > 0,
AppendTo[propertiesToPrint, "TestsFailedIndices"];
Scan[If[report["TestsFailed" <> # <> "Count"] > 0,
propertiesToPrint = Join[propertiesToPrint, {"TestsFailed" <> # <> "Count", "TestsFailed" <> # <> "Indices", "TestsFailed" <> #}];
]&, {"WrongResults", "WithMessages", "WithErrors"}];
If[#["Outcome"] =!= "Success",
Print @ TextString[#, AssociationFormat -> {"{\n\t", ",\n\t", "\n}", ": "}]
]& /@ report["TestResults"];
];
Print[TextString[AssociationMap[report, propertiesToPrint], AssociationFormat -> {"{\n\t", ",\n\t", "\n}", ": "}]];
exitCode = 1 - Boole[report["AllTestsSucceeded"]];
exitCode = Boole[failedCount > 0];
Exit[exitCode]
]===])
string(REGEX REPLACE "[\t\r\n]+" "" MODULE_CODE "${MODULE_CODE}")
Expand Down
10 changes: 9 additions & 1 deletion tests/UnitTests/TestConfig.wl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ $baseDir = FileNameDrop[$TestFileName, -3];

$installDir = If[StringQ[$LLUInstallDir], $LLUInstallDir, FileNameJoin[{$baseDir, "install"}]];

$CRTLinkingFlag = Switch[$LinkToCRTStaticallyQ,
"MultiThreaded", "/MT",
"MultiThreadedDLL", "/MD",
"MultiThreadedDebug", "/MTd",
"MultiThreadedDebugDLL", "/MDd",
_, "/MD"
];

(* Path to directory containing include folder from LibraryLinkUtilities installation *)
$LLUIncDir = FileNameJoin[{$installDir, "include"}];

Expand Down Expand Up @@ -32,7 +40,7 @@ options := {
"CompileOptions" ->
Switch[$OperatingSystem,
"Windows",
"/EHsc /W3 /std:" <> $CppVersion <> " /D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING",
"/EHsc /W3 " <> $CRTLinkingFlag <> " /std:" <> $CppVersion <> " /D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING",
"Unix",
"-Wall --pedantic -fvisibility=hidden -std=" <> $CppVersion,
"MacOSX",
Expand Down

0 comments on commit 0d449ce

Please sign in to comment.