From c5d10f256225b74c76ae97890b54f0e3d0665a53 Mon Sep 17 00:00:00 2001 From: Dirk Vanden Boer Date: Fri, 8 Nov 2024 09:33:48 +0100 Subject: [PATCH] TextCompare test util --- testutil/CMakeLists.txt | 1 + testutil/include/infra/test/textcompare.h | 25 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 testutil/include/infra/test/textcompare.h diff --git a/testutil/CMakeLists.txt b/testutil/CMakeLists.txt index b2f6c7ed..629b2811 100644 --- a/testutil/CMakeLists.txt +++ b/testutil/CMakeLists.txt @@ -5,6 +5,7 @@ set (INFRA_TESTUTIL_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/infra/test/printsupport.h ${CMAKE_CURRENT_SOURCE_DIR}/include/infra/test/reporter.h ${CMAKE_CURRENT_SOURCE_DIR}/include/infra/test/tempdir.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/infra/test/textcompare.h ) add_library(infratestutil diff --git a/testutil/include/infra/test/textcompare.h b/testutil/include/infra/test/textcompare.h new file mode 100644 index 00000000..a102e2a7 --- /dev/null +++ b/testutil/include/infra/test/textcompare.h @@ -0,0 +1,25 @@ +#pragma once + +#include "infra/filesystem.h" + +#include + +namespace inf::test { + +inline void check_strings_equal_ignore_line_endings(std::string expected, std::string actual) +{ + str::replace_in_place(expected, "\r\n", "\n"); + str::replace_in_place(actual, "\r\n", "\n"); + + CHECK(expected == actual); +} + +inline void check_text_files_equal_ignore_line_endings(const fs::path& expected, const fs::path& actual) +{ + auto expectedContents = file::read_as_text(expected); + auto actualContents = file::read_as_text(actual); + + check_strings_equal_ignore_line_endings(expectedContents, actualContents); +} + +}