Skip to content

Commit

Permalink
TextCompare test util
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Nov 8, 2024
1 parent 488db76 commit c5d10f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions testutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions testutil/include/infra/test/textcompare.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "infra/filesystem.h"

#include <doctest/doctest.h>

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);
}

}

0 comments on commit c5d10f2

Please sign in to comment.