diff --git a/ApprovalTests/utilities/FileUtils.cpp b/ApprovalTests/utilities/FileUtils.cpp index 693917a2..99d05825 100644 --- a/ApprovalTests/utilities/FileUtils.cpp +++ b/ApprovalTests/utilities/FileUtils.cpp @@ -1,6 +1,7 @@ #include "ApprovalTests/utilities/FileUtils.h" #include "ApprovalTests/writers/StringWriter.h" #include "EmptyFileCreatorFactory.h" +#include "EmptyFileCreatorDisposer.h" #include "SystemUtils.h" #include @@ -32,6 +33,11 @@ namespace ApprovalTests return int(statbuf.st_size); } + EmptyFileCreatorDisposer FileUtils::useEmptyFileCreator(EmptyFileCreator creator) + { + return EmptyFileCreatorDisposer(creator); + } + void FileUtils::ensureFileExists(const std::string& fullFilePath) { if (!fileExists(fullFilePath)) @@ -89,4 +95,5 @@ namespace ApprovalTests } out << content; } + } diff --git a/ApprovalTests/utilities/FileUtils.h b/ApprovalTests/utilities/FileUtils.h index f5033f90..52bf1d3d 100644 --- a/ApprovalTests/utilities/FileUtils.h +++ b/ApprovalTests/utilities/FileUtils.h @@ -1,7 +1,8 @@ #pragma once #include - +#include "EmptyFileCreatorFactory.h" +#include "EmptyFileCreatorDisposer.h" namespace ApprovalTests { class FileUtils @@ -11,6 +12,8 @@ namespace ApprovalTests static int fileSize(const std::string& path); + static EmptyFileCreatorDisposer useEmptyFileCreator(EmptyFileCreator creator); + static void ensureFileExists(const std::string& fullFilePath); static std::string getDirectory(const std::string& filePath); diff --git a/tests/DocTest_Tests/utilities/FileUtilsTests.cpp b/tests/DocTest_Tests/utilities/FileUtilsTests.cpp index 98ce0a1e..dd138a31 100644 --- a/tests/DocTest_Tests/utilities/FileUtilsTests.cpp +++ b/tests/DocTest_Tests/utilities/FileUtilsTests.cpp @@ -45,7 +45,11 @@ TEST_CASE("check impossible directories don't explode") TEST_CASE("Empty File Creation") { - //auto disposer = ApprovalTests::FileUtils::useEmptyFileCreator([](std::string fileName) {}); + std::string called = ""; + auto disposer = ApprovalTests::FileUtils::useEmptyFileCreator([&](std::string fileName) {called = fileName;}); + std::string filePath = "/this/file/will/not/exist.txt"; + FileUtils::ensureFileExists(filePath); + REQUIRE(filePath == called); }