From 7d8cd00778c3eee9f32af04b009d8a5651eb53e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Thu, 22 Apr 2021 09:36:58 +0200 Subject: [PATCH] fix tests expectations for alpine linux --- unitTests/test_futils.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/unitTests/test_futils.cpp b/unitTests/test_futils.cpp index ee618c7b..7d67c353 100644 --- a/unitTests/test_futils.cpp +++ b/unitTests/test_futils.cpp @@ -42,6 +42,7 @@ TEST(strError, returnSuccessAfterClosingFile) std::string tmpFile("tmp.dat"); std::ofstream auxFile(tmpFile.c_str()); auxFile.close(); + bool useExactString{true}; #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__) || defined(__MSYS__) const char * expectedString = "No error (errno = 0)"; #elif defined(__APPLE__) @@ -53,10 +54,16 @@ TEST(strError, returnSuccessAfterClosingFile) #elif defined(__NetBSD__) const char * expectedString = "Undefined error: 0 (errno = 0)"; #else - const char * expectedString = "Success (errno = 0)"; + // On Alpine we get 'No error information (errno = 0)' instead of 'Success (errno = 0)' + const char * expectedString = "(errno = 0)"; + useExactString = false; #endif std::remove(tmpFile.c_str()); - ASSERT_STREQ(expectedString, strError().c_str()); + if (useExactString) { + ASSERT_STREQ(expectedString, strError().c_str()); + } else { + ASSERT_TRUE(strError().find(expectedString) != std::string::npos); + } } TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) @@ -68,6 +75,7 @@ TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) TEST(strError, doNotRecognizeUnknownError) { errno = 9999; + bool useExactString{true}; #if defined(__MINGW__) || defined(__MSYS__) || defined(__CYGWIN__) const char * expectedString = "Unknown error 9999 (errno = 9999)"; #elif defined(_WIN32) @@ -81,9 +89,15 @@ TEST(strError, doNotRecognizeUnknownError) #elif defined(__NetBSD__) const char * expectedString = "Unknown error: 9999 (errno = 9999)"; #else - const char * expectedString = "Unknown error 9999 (errno = 9999)"; + // On Alpine we get 'No error information (errno = 9999)' instead of 'Unknown error 9999 (errno = 9999)' + const char * expectedString = "(errno = 9999)"; + useExactString = false; #endif - ASSERT_STREQ(expectedString, strError().c_str()); + if (useExactString) { + ASSERT_STREQ(expectedString, strError().c_str()); + } else { + ASSERT_TRUE(strError().find(expectedString) != std::string::npos); + } } TEST(getEnv, getsDefaultValueWhenExpectedEnvVariableDoesNotExist)