Skip to content

Commit

Permalink
internal: test: file: Handle newline character difference
Browse files Browse the repository at this point in the history
In Windows, the newline(\n) characters in internal test data are replaced with \r\n
by git settings: core.autocrlf true.
This serrings accicdentally converting the newlines.
This commit handles the converted characters.

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Mar 15, 2024
1 parent 1ec8aee commit b077178
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/internal/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#define TEXT_FILE FLB_TESTS_DATA_PATH "/data/file/text_file.txt"
#define EMPTY_FILE FLB_TESTS_DATA_PATH "/data/file/empty_file.txt"

#define NEWLINE "\n"
#define CRNEWLINE "\r\n"

static void check_equals(flb_sds_t result, const char *expected)
{
size_t expected_len = strlen(expected);
Expand All @@ -23,7 +26,13 @@ static void check_equals(flb_sds_t result, const char *expected)
static void test_file_read_text_file()
{
flb_sds_t result = flb_file_read(TEXT_FILE);
check_equals(result, "Some text file\n\nline 3\n\nline 5\n");
/* In Windows, \n is replaced with \r\n by git settings. */
if (strstr(result, "\r\n") != NULL) {
check_equals(result, "Some text file\r\n\r\nline 3\r\n\r\nline 5\r\n");
}
else {
check_equals(result, "Some text file\n\nline 3\n\nline 5\n");
}
flb_sds_destroy(result);
}

Expand Down

0 comments on commit b077178

Please sign in to comment.