diff --git a/doc/Writers.md b/doc/Writers.md index f14df3a7..638b586e 100644 --- a/doc/Writers.md +++ b/doc/Writers.md @@ -7,7 +7,8 @@ * [Default Behaviour](#default-behaviour) * [Using custom writers](#using-custom-writers) - * [Using custom filename extensions](#using-custom-filename-extensions) + * [Using custom filename extensions](#using-custom-filename-extensions) + * [Creating Empty Files](#creating-empty-files) ## Default Behaviour @@ -55,7 +56,22 @@ By default, ApprovalTests will create an empty file as a text file with an empty This behavior can be customized as follows which will create a valid empty json file when running a new ApprovalTest: -snippet: use_empty_file_creator + + +```cpp +ApprovalTests::EmptyFileCreator jsonCreator = [](std::string fileName) { + std::string contents = ""; + if (ApprovalTests::StringUtils::endsWith(fileName, ".json")) + { + contents = "{}"; + } + ApprovalTests::StringWriter s(contents); + s.write(fileName); +}; +auto disposer = ApprovalTests::FileUtils::useEmptyFileCreator(jsonCreator); +``` +snippet source | anchor + --- diff --git a/doc/how_tos/ToggleDeprecatedCode.md b/doc/how_tos/ToggleDeprecatedCode.md index 7a19c97e..c2818b77 100644 --- a/doc/how_tos/ToggleDeprecatedCode.md +++ b/doc/how_tos/ToggleDeprecatedCode.md @@ -52,7 +52,7 @@ Or this to your CMakeLists.txt: # Replace ${PROJECT_NAME} with the name of your test executable: target_compile_definitions(${PROJECT_NAME} PRIVATE -DAPPROVAL_TESTS_SHOW_DEPRECATION_WARNINGS=1) ``` -snippet source | anchor +snippet source | anchor ### Hide deprecated code @@ -75,7 +75,7 @@ Or this to your CMakeLists.txt: # Replace ${PROJECT_NAME} with the name of your test executable: target_compile_definitions(${PROJECT_NAME} PRIVATE -DAPPROVAL_TESTS_HIDE_DEPRECATED_CODE=1) ``` -snippet source | anchor +snippet source | anchor ## How to Update Calls to Deprecated Code