Skip to content

Commit 32cde6d

Browse files
authored
ENH: Update UnitTestCommon to have a .cpp file for implementations (#1459)
This is handy because on macOS when debugging the requirements for the decompression never passes even though it actually does work. This allows the developer to quickly comment out that line in order to debug.
1 parent c977bcc commit 32cde6d

File tree

3 files changed

+60
-49
lines changed

3 files changed

+60
-49
lines changed

test/UnitTestCommon/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
find_package(Catch2 CONFIG REQUIRED)
22
find_package(reproc++ CONFIG REQUIRED)
33

4-
add_library(ComplexUnitTestCommon INTERFACE)
5-
add_library(simplnx::UnitTestCommon ALIAS ComplexUnitTestCommon)
4+
add_library(SimplnxUnitTestCommon INTERFACE)
5+
add_library(simplnx::UnitTestCommon ALIAS SimplnxUnitTestCommon)
66

7-
target_include_directories(ComplexUnitTestCommon
7+
target_include_directories(SimplnxUnitTestCommon
88
INTERFACE
99
${PROJECT_SOURCE_DIR}/test/UnitTestCommon/include
1010
)
1111

12-
target_link_libraries(ComplexUnitTestCommon
12+
target_link_libraries(SimplnxUnitTestCommon
1313
INTERFACE
1414
simplnx
1515
Catch2::Catch2
1616
reproc++
1717
)
1818

19-
target_sources(ComplexUnitTestCommon
19+
target_sources(SimplnxUnitTestCommon
20+
PUBLIC
21+
${PROJECT_SOURCE_DIR}/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.cpp
2022
INTERFACE
2123
${PROJECT_SOURCE_DIR}/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp
2224
${PROJECT_SOURCE_DIR}/test/UnitTestCommon/include/simplnx/UnitTest/DataObjectComparison.hpp
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "UnitTestCommon.hpp"
2+
3+
using namespace nx::core::UnitTest;
4+
5+
TestFileSentinel::TestFileSentinel(std::string cmakeExecutable, std::string testFilesDir, std::string inputArchiveName, std::string expectedTopLevelOutput, bool decompressFiles, bool removeTemp)
6+
: m_CMakeExecutable(std::move(cmakeExecutable))
7+
, m_TestFilesDir(std::move(testFilesDir))
8+
, m_InputArchiveName(std::move(inputArchiveName))
9+
, m_ExpectedTopLevelOutput(std::move(expectedTopLevelOutput))
10+
, m_Decompress(decompressFiles)
11+
, m_RemoveTemp(removeTemp)
12+
{
13+
if(m_Decompress)
14+
{
15+
const auto errorCode = decompress();
16+
if(errorCode)
17+
{
18+
std::cout << "std::error_code.value(): " << errorCode.value() << std::endl;
19+
std::cout << "std::error_code.message(): " << errorCode.message() << std::endl;
20+
// REQUIRE(errorCode.value() == 0);
21+
}
22+
}
23+
}
24+
25+
TestFileSentinel::~TestFileSentinel()
26+
{
27+
if(m_RemoveTemp)
28+
{
29+
std::error_code errorCode;
30+
std::filesystem::remove_all(fmt::format("{}/{}", m_TestFilesDir, m_ExpectedTopLevelOutput), errorCode);
31+
if(errorCode)
32+
{
33+
std::cout << "Removing decompressed data failed: " << errorCode.message() << std::endl;
34+
}
35+
}
36+
}
37+
38+
std::error_code TestFileSentinel::decompress()
39+
{
40+
reproc::options options;
41+
options.redirect.parent = true;
42+
options.deadline = reproc::milliseconds(600000);
43+
options.working_directory = m_TestFilesDir.c_str();
44+
options.nonblocking = false;
45+
46+
std::vector<std::string> args = {m_CMakeExecutable, "-E", "tar", "xvzf", fmt::format("{}/{}", m_TestFilesDir, m_InputArchiveName)};
47+
48+
auto resultPair = reproc::run(args, options);
49+
return resultPair.second;
50+
}

test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -249,38 +249,9 @@ class TestFileSentinel
249249
* @param decompressFiles Decompress the archive
250250
* @param removeTemp delete files that were decompressed
251251
*/
252-
TestFileSentinel(std::string cmakeExecutable, std::string testFilesDir, std::string inputArchiveName, std::string expectedTopLevelOutput, bool decompressFiles = true, bool removeTemp = true)
253-
: m_CMakeExecutable(std::move(cmakeExecutable))
254-
, m_TestFilesDir(std::move(testFilesDir))
255-
, m_InputArchiveName(std::move(inputArchiveName))
256-
, m_ExpectedTopLevelOutput(std::move(expectedTopLevelOutput))
257-
, m_Decompress(decompressFiles)
258-
, m_RemoveTemp(removeTemp)
259-
{
260-
if(m_Decompress)
261-
{
262-
const auto errorCode = decompress();
263-
if(errorCode)
264-
{
265-
std::cout << "std::error_code.value(): " << errorCode.value() << std::endl;
266-
std::cout << "std::error_code.message(): " << errorCode.message() << std::endl;
267-
REQUIRE(errorCode.value() == 0);
268-
}
269-
}
270-
}
252+
TestFileSentinel(std::string cmakeExecutable, std::string testFilesDir, std::string inputArchiveName, std::string expectedTopLevelOutput, bool decompressFiles = true, bool removeTemp = true);
271253

272-
~TestFileSentinel()
273-
{
274-
if(m_RemoveTemp)
275-
{
276-
std::error_code errorCode;
277-
std::filesystem::remove_all(fmt::format("{}/{}", m_TestFilesDir, m_ExpectedTopLevelOutput), errorCode);
278-
if(errorCode)
279-
{
280-
std::cout << "Removing decompressed data failed: " << errorCode.message() << std::endl;
281-
}
282-
}
283-
}
254+
~TestFileSentinel();
284255

285256
TestFileSentinel(const TestFileSentinel&) = delete; // Copy Constructor Not Implemented
286257
TestFileSentinel(TestFileSentinel&&) = delete; // Move Constructor Not Implemented
@@ -291,19 +262,7 @@ class TestFileSentinel
291262
* @brief Does the actual decompression of the archive.
292263
* @return
293264
*/
294-
std::error_code decompress()
295-
{
296-
reproc::options options;
297-
options.redirect.parent = true;
298-
options.deadline = reproc::milliseconds(600000);
299-
options.working_directory = m_TestFilesDir.c_str();
300-
options.nonblocking = false;
301-
302-
std::vector<std::string> args = {m_CMakeExecutable, "-E", "tar", "xvzf", fmt::format("{}/{}", m_TestFilesDir, m_InputArchiveName)};
303-
304-
auto resultPair = reproc::run(args, options);
305-
return resultPair.second;
306-
}
265+
std::error_code decompress();
307266

308267
private:
309268
std::string m_CMakeExecutable;

0 commit comments

Comments
 (0)