Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e46d54

Browse files
ethomsonEdward Thomson
authored and
Edward Thomson
committed
crlf tests: ensure that Unix obeys autocrlf=true
All platforms do terrible, horrible, no good, very bad translation when core.autocrlf=true. It's not just Windows!
1 parent 8293c8f commit 1e46d54

File tree

2 files changed

+17
-60
lines changed

2 files changed

+17
-60
lines changed

tests/checkout/crlf.c

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void)
220220

221221
git_checkout_head(g_repo, &opts);
222222

223-
if (GIT_EOL_NATIVE == GIT_EOL_LF)
224-
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
225-
else
226-
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
227-
223+
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
228224
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
229225
}
230226

@@ -238,16 +234,8 @@ void test_checkout_crlf__detect_crlf_autocrlf_true_utf8(void)
238234
git_repository_set_head(g_repo, "refs/heads/master");
239235
git_checkout_head(g_repo, &opts);
240236

241-
if (GIT_EOL_NATIVE == GIT_EOL_LF)
242-
{
243-
check_file_contents("./crlf/few-utf8-chars-lf", FEW_UTF8_LF_RAW);
244-
check_file_contents("./crlf/many-utf8-chars-lf", MANY_UTF8_LF_RAW);
245-
}
246-
else
247-
{
248-
check_file_contents("./crlf/few-utf8-chars-lf", FEW_UTF8_CRLF_RAW);
249-
check_file_contents("./crlf/many-utf8-chars-lf", MANY_UTF8_CRLF_RAW);
250-
}
237+
check_file_contents("./crlf/few-utf8-chars-lf", FEW_UTF8_CRLF_RAW);
238+
check_file_contents("./crlf/many-utf8-chars-lf", MANY_UTF8_CRLF_RAW);
251239

252240
check_file_contents("./crlf/few-utf8-chars-crlf", FEW_UTF8_CRLF_RAW);
253241
check_file_contents("./crlf/many-utf8-chars-crlf", MANY_UTF8_CRLF_RAW);
@@ -269,10 +257,7 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
269257

270258
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
271259

272-
if (GIT_EOL_NATIVE == GIT_EOL_LF)
273-
cl_assert_equal_sz(strlen(ALL_LF_TEXT_RAW), entry->file_size);
274-
else
275-
cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
260+
cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
276261

277262
cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
278263
cl_assert_equal_sz(strlen(ALL_CRLF_TEXT_RAW), entry->file_size);
@@ -341,25 +326,14 @@ void test_checkout_crlf__with_ident(void)
341326

342327
git_checkout_head(g_repo, &opts);
343328

344-
if (GIT_EOL_NATIVE == GIT_EOL_LF) {
345-
cl_assert_equal_file(
346-
ALL_LF_TEXT_RAW
347-
"\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\n",
348-
0, "crlf/lf.ident");
349-
cl_assert_equal_file(
350-
ALL_CRLF_TEXT_AS_LF
351-
"\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\n\n",
352-
0, "crlf/crlf.ident");
353-
} else {
354-
cl_assert_equal_file(
355-
ALL_LF_TEXT_AS_CRLF
356-
"\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\r\n",
357-
0, "crlf/lf.ident");
358-
cl_assert_equal_file(
359-
ALL_CRLF_TEXT_RAW
360-
"\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\r\n\r\n",
361-
0, "crlf/crlf.ident");
362-
}
329+
cl_assert_equal_file(
330+
ALL_LF_TEXT_AS_CRLF
331+
"\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\r\n",
332+
0, "crlf/lf.ident");
333+
cl_assert_equal_file(
334+
ALL_CRLF_TEXT_RAW
335+
"\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\r\n\r\n",
336+
0, "crlf/crlf.ident");
363337

364338
cl_assert_equal_file(
365339
"$Id: f7830382dac1f1583422be5530fdfbd26289431b $\n"
@@ -394,13 +368,8 @@ void test_checkout_crlf__autocrlf_true_no_attrs(void)
394368

395369
git_checkout_head(g_repo, &opts);
396370

397-
if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
398-
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
399-
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
400-
} else {
401-
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
402-
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
403-
}
371+
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
372+
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
404373
}
405374

406375
void test_checkout_crlf__autocrlf_input_no_attrs(void)
@@ -447,13 +416,8 @@ void test_checkout_crlf__autocrlf_true_text_auto_attr(void)
447416

448417
git_checkout_head(g_repo, &opts);
449418

450-
if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
451-
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
452-
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
453-
} else {
454-
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
455-
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
456-
}
419+
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
420+
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
457421
}
458422

459423
void test_checkout_crlf__autocrlf_input_text_auto_attr(void)
@@ -483,10 +447,7 @@ void test_checkout_crlf__can_write_empty_file(void)
483447

484448
check_file_contents("./crlf/test1.txt", "");
485449

486-
if (GIT_EOL_NATIVE == GIT_EOL_LF)
487-
check_file_contents("./crlf/test2.txt", "test2.txt's content\n");
488-
else
489-
check_file_contents("./crlf/test2.txt", "test2.txt's content\r\n");
450+
check_file_contents("./crlf/test2.txt", "test2.txt's content\r\n");
490451

491452
check_file_contents("./crlf/test3.txt", "");
492453
}

tests/filter/crlf.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ void test_filter_crlf__to_worktree(void)
3838

3939
cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
4040

41-
#ifdef GIT_WIN32
4241
cl_assert_equal_s("Some text\r\nRight here\r\n", out.ptr);
43-
#else
44-
cl_assert_equal_s("Some text\nRight here\n", out.ptr);
45-
#endif
4642

4743
git_filter_list_free(fl);
4844
git_buf_free(&out);

0 commit comments

Comments
 (0)