diff --git a/ApprovalTests/CMakeLists.txt b/ApprovalTests/CMakeLists.txt index d389a0bc..fdf2a137 100644 --- a/ApprovalTests/CMakeLists.txt +++ b/ApprovalTests/CMakeLists.txt @@ -43,6 +43,8 @@ add_library(${PROJECT_NAME} launchers/CommandLauncher.h launchers/SystemLauncher.h launchers/SystemLauncher.cpp + logs/ApprovalFileLog.cpp + logs/ApprovalFileLog.hpp namers/ApprovalTestNamer.h namers/ApprovalTestNamer.cpp namers/DefaultNamerDisposer.h diff --git a/ApprovalTests/core/FileApprover.cpp b/ApprovalTests/core/FileApprover.cpp index a1f5b526..67136e8b 100644 --- a/ApprovalTests/core/FileApprover.cpp +++ b/ApprovalTests/core/FileApprover.cpp @@ -2,6 +2,7 @@ #include "ApprovalTests/utilities/FileUtils.h" #include "ApprovalTests/utilities/SystemUtils.h" #include "ApprovalTests/reporters/FrontLoadedReporterFactory.h" +#include #include "ApprovalException.h" #include @@ -63,8 +64,10 @@ namespace ApprovalTests const ApprovalWriter& s, const Reporter& r) { - std::string approvedPath = n.getApprovedFile(s.getFileExtensionWithDot()); - std::string receivedPath = n.getReceivedFile(s.getFileExtensionWithDot()); + std::string const approvedPath = n.getApprovedFile(s.getFileExtensionWithDot()); + std::string const receivedPath = n.getReceivedFile(s.getFileExtensionWithDot()); + + ApprovalFileLog::log(approvedPath); SystemUtils::ensureParentDirectoryExists(approvedPath); SystemUtils::ensureParentDirectoryExists(receivedPath); s.write(receivedPath); @@ -76,6 +79,7 @@ namespace ApprovalTests } catch (const ApprovalException&) { + // FailedFileLog::log(receivedPath, approvedPath); reportAfterTryingFrontLoadedReporter(receivedPath, approvedPath, r); throw; } diff --git a/ApprovalTests/logs/ApprovalFileLog.cpp b/ApprovalTests/logs/ApprovalFileLog.cpp new file mode 100644 index 00000000..7e7d9138 --- /dev/null +++ b/ApprovalTests/logs/ApprovalFileLog.cpp @@ -0,0 +1,31 @@ +#include "ApprovalFileLog.hpp" +#include + +void ApprovalFileLog::initialize() +{ + static bool isInitialized{false}; + if (isInitialized) + { + return; + } + isInitialized = true; + ApprovalTests::FileUtils::writeToFile(getLogFilePath(), ""); +} + +std::string ApprovalFileLog::getLogFilePath() +{ + //auto const rootDirectory = ApprovalTests::TestName::getRootDirectory(); + auto const rootDirectory = ""; + // Note: Need to figure out where the actual root directory is. + std::string const filePath = + rootDirectory + std::string(APPROVAL_TEMP_DIRECTORY) + "/.approved_files.log"; + ApprovalTests::SystemUtils::ensureDirectoryExists(APPROVAL_TEMP_DIRECTORY); + return filePath; +} + +void ApprovalFileLog::log(const std::string& filePath) +{ + initialize(); + std::ofstream ofs(getLogFilePath(), std::ios::app); + ofs << filePath << std::endl; +} diff --git a/ApprovalTests/logs/ApprovalFileLog.hpp b/ApprovalTests/logs/ApprovalFileLog.hpp new file mode 100644 index 00000000..f848cdca --- /dev/null +++ b/ApprovalTests/logs/ApprovalFileLog.hpp @@ -0,0 +1,17 @@ +#pragma once +#include +#include + +auto constexpr APPROVAL_TEMP_DIRECTORY = "/.approval_tests_temp"; + +class ApprovalFileLog { +public: + // Static initializer to ensure an _empty_ log file is created + static void initialize(); + + // Function to get the log file path + static std::string getLogFilePath(); + + // Function to log the approved file path + static void log(const std::string& filePath); +}; diff --git a/ApprovalTests/namers/ApprovalTestNamer.h b/ApprovalTests/namers/ApprovalTestNamer.h index 1d130999..b8dc9853 100644 --- a/ApprovalTests/namers/ApprovalTestNamer.h +++ b/ApprovalTests/namers/ApprovalTestNamer.h @@ -44,7 +44,6 @@ namespace ApprovalTests class ApprovalTestNamer : public ApprovalNamer { - private: public: ApprovalTestNamer() = default;