From 15fddad46dc0b6fc11357b8bc15da4f8d402c3f7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 3 Aug 2021 14:05:33 +0200 Subject: [PATCH] Log error when "srcdirref" cannot be opened --- tests/testutils.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testutils.cpp b/tests/testutils.cpp index c75b8c0..6178ae6 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -600,7 +600,7 @@ string TestApplication::readTestfilePathFromSrcRef() { // find the path of the current executable on platforms supporting "/proc/self/exe"; otherwise assume the current working directory // is the executable path - std::string binaryPath; + auto binaryPath = std::string(); #if defined(CPP_UTILITIES_USE_STANDARD_FILESYSTEM) && defined(PLATFORM_UNIX) try { binaryPath = std::filesystem::read_symlink("/proc/self/exe").parent_path(); @@ -609,9 +609,10 @@ string TestApplication::readTestfilePathFromSrcRef() cerr << Phrases::Warning << "Unable to detect binary path for finding \"srcdirref\": " << e.what() << Phrases::EndFlush; } #endif + const auto srcdirrefPath = binaryPath + "srcdirref"; try { // read "srcdirref" file which should contain the path of the source directory - auto srcDirContent(readFile(binaryPath + "srcdirref", 2 * 1024)); + auto srcDirContent(readFile(srcdirrefPath, 2 * 1024)); if (srcDirContent.empty()) { cerr << Phrases::Warning << "The file \"srcdirref\" is empty." << Phrases::EndFlush; return string(); @@ -627,9 +628,8 @@ string TestApplication::readTestfilePathFromSrcRef() } return srcDirContent; - } catch (const std::ios_base::failure &) { - cerr << Phrases::Warning << "The file \"srcdirref\" can not be opened. It likely just doesn't exist in the working directory." - << Phrases::EndFlush; + } catch (const std::ios_base::failure &e) { + cerr << Phrases::Warning << "The file \"" << srcdirrefPath << "\" can not be opened: " << e.what() << Phrases::EndFlush; } return string(); }