Skip to content

Commit

Permalink
F!! useEmptyFileCreator seam #172
Browse files Browse the repository at this point in the history
Co-Authored-By: Clare Macrae <[email protected]>
  • Loading branch information
isidore and claremacrae committed Aug 30, 2021
1 parent 419265e commit 05a1eb3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ApprovalTests/utilities/FileUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ApprovalTests/utilities/FileUtils.h"
#include "ApprovalTests/writers/StringWriter.h"
#include "EmptyFileCreatorFactory.h"
#include "EmptyFileCreatorDisposer.h"
#include "SystemUtils.h"

#include <fstream>
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -89,4 +95,5 @@ namespace ApprovalTests
}
out << content;
}

}
5 changes: 4 additions & 1 deletion ApprovalTests/utilities/FileUtils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <string>

#include "EmptyFileCreatorFactory.h"
#include "EmptyFileCreatorDisposer.h"
namespace ApprovalTests
{
class FileUtils
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion tests/DocTest_Tests/utilities/FileUtilsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down

0 comments on commit 05a1eb3

Please sign in to comment.