File tree Expand file tree Collapse file tree 5 files changed +56
-3
lines changed
Expand file tree Collapse file tree 5 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ add_library(${PROJECT_NAME}
4343 launchers/CommandLauncher.h
4444 launchers/SystemLauncher.h
4545 launchers/SystemLauncher.cpp
46+ logs/ApprovalFileLog.cpp
47+ logs/ApprovalFileLog.hpp
4648 namers/ApprovalTestNamer.h
4749 namers/ApprovalTestNamer.cpp
4850 namers/DefaultNamerDisposer.h
Original file line number Diff line number Diff line change 22#include " ApprovalTests/utilities/FileUtils.h"
33#include " ApprovalTests/utilities/SystemUtils.h"
44#include " ApprovalTests/reporters/FrontLoadedReporterFactory.h"
5+ #include < ApprovalTests/logs/ApprovalFileLog.hpp>
56#include " ApprovalException.h"
67
78#include < sstream>
@@ -63,8 +64,10 @@ namespace ApprovalTests
6364 const ApprovalWriter& s,
6465 const Reporter& r)
6566 {
66- std::string approvedPath = n.getApprovedFile (s.getFileExtensionWithDot ());
67- std::string receivedPath = n.getReceivedFile (s.getFileExtensionWithDot ());
67+ std::string const approvedPath = n.getApprovedFile (s.getFileExtensionWithDot ());
68+ std::string const receivedPath = n.getReceivedFile (s.getFileExtensionWithDot ());
69+
70+ ApprovalFileLog::log (approvedPath);
6871 SystemUtils::ensureParentDirectoryExists (approvedPath);
6972 SystemUtils::ensureParentDirectoryExists (receivedPath);
7073 s.write (receivedPath);
@@ -76,6 +79,7 @@ namespace ApprovalTests
7679 }
7780 catch (const ApprovalException&)
7881 {
82+ // FailedFileLog::log(receivedPath, approvedPath);
7983 reportAfterTryingFrontLoadedReporter (receivedPath, approvedPath, r);
8084 throw ;
8185 }
Original file line number Diff line number Diff line change 1+ #include " ApprovalFileLog.hpp"
2+ #include < fstream>
3+
4+ void ApprovalFileLog::initialize ()
5+ {
6+ static bool isInitialized{false };
7+ if (isInitialized)
8+ {
9+ return ;
10+ }
11+ isInitialized = true ;
12+ ApprovalTests::FileUtils::writeToFile (getLogFilePath (), " " );
13+ }
14+
15+ std::string ApprovalFileLog::getLogFilePath ()
16+ {
17+ // auto const rootDirectory = ApprovalTests::TestName::getRootDirectory();
18+ auto const rootDirectory = " " ;
19+ // Note: Need to figure out where the actual root directory is.
20+ std::string const filePath =
21+ rootDirectory + std::string (APPROVAL_TEMP_DIRECTORY) + " /.approved_files.log" ;
22+ ApprovalTests::SystemUtils::ensureDirectoryExists (APPROVAL_TEMP_DIRECTORY);
23+ return filePath;
24+ }
25+
26+ void ApprovalFileLog::log (const std::string& filePath)
27+ {
28+ initialize ();
29+ std::ofstream ofs (getLogFilePath (), std::ios::app);
30+ ofs << filePath << std::endl;
31+ }
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #include < utilities/FileUtils.h>
3+ #include < utilities/SystemUtils.h>
4+
5+ auto constexpr APPROVAL_TEMP_DIRECTORY = " /.approval_tests_temp" ;
6+
7+ class ApprovalFileLog {
8+ public:
9+ // Static initializer to ensure an _empty_ log file is created
10+ static void initialize ();
11+
12+ // Function to get the log file path
13+ static std::string getLogFilePath ();
14+
15+ // Function to log the approved file path
16+ static void log (const std::string& filePath);
17+ };
Original file line number Diff line number Diff line change @@ -44,7 +44,6 @@ namespace ApprovalTests
4444
4545 class ApprovalTestNamer : public ApprovalNamer
4646 {
47- private:
4847 public:
4948 ApprovalTestNamer () = default ;
5049
You can’t perform that action at this time.
0 commit comments