Skip to contentSkip to conversation

t0020-crlf: check the right file

PATCH In review SZEDER Gábor 3 participants 4 messages Aug 22, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 t0020-crlf: check the right file

In the test 'checkout with autocrlf=input' in 't0020-crlf.sh', one of the 'has_cr' checks looks at the non-existing file 'two' instead of 'dir/two'. The test still succeeds, without actually checking what it was supposed to, because this check is expected to fail anyway.

As a minimal fix, fix the name of the file to be checked.

---
 t/t0020-crlf.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/t0020-crlf.sh +1 -1
index 5f056982a5..854da0ae16 100755
@@ -160,7 +160,7 @@ test_expect_success 'checkout with autocrlf=input' '
 	git config core.autocrlf input &&
 	git read-tree --reset -u HEAD &&
 	test_must_fail has_cr one &&
-	test_must_fail has_cr two &&
+	test_must_fail has_cr dir/two &&
 	git update-index -- one dir/two &&
 	test "$one" = $(git hash-object --stdin <one) &&
 	test "$two" = $(git hash-object --stdin <dir/two) &&
Signature · 1 line
2.19.0.rc0.136.gd2dd172e64
#1 lore raw

PATCH 2/2 t4051-diff-function-context: read the right file

The test ' context does not include preceding empty lines' in the block of tests 'change with long common tail and no context' in 't4051-diff-function-context.sh' tries to read the file 'long_common_tail.diff.diff', but that file doesn't exist as its name contains one more '.diff' suffixes than necessary.

Despite this error the test still succeeded without checking what it's supposed to, because this erroneous read is done on the line:

  test "$(first_context_line <long_common_tail.diff.diff)" != " "

which means that:

- the command substitution hides the error, so it won't fail the test, and

- the result of the command substitution is the empty string, which is, of course, not equal to a single space character, so the condition is fulfilled, and the test succeeds.

As a minimal fix, fix the name of the file to be read.

In the future we might want to reorganize this test script (1) to use 'test_cmp' instead of 'test's and command substitutions to catch failing commands and to provide helpful error messages, and (2) to specify what the expected result actually _is_ instead of what it isn't.

---
 t/t4051-diff-function-context.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/t4051-diff-function-context.sh +1 -1
index 2d76a971c4..4838a1df8b 100755
@@ -174,7 +174,7 @@ test_expect_success ' context does not include other functions' '
 '
 
 test_expect_success ' context does not include preceding empty lines' '
-	test "$(first_context_line <long_common_tail.diff.diff)" != " "
+	test "$(first_context_line <long_common_tail.diff)" != " "
 '
 
 check_diff changed_hello_appended 'changed function plus appended function'
Signature · 1 line
2.19.0.rc0.136.gd2dd172e64
#2 lore raw
In reply to SZEDER Gábor
Quoted 9 lines · SZEDER Gábor

In the test 'checkout with autocrlf=input' in 't0020-crlf.sh', one of the 'has_cr' checks looks at the non-existing file 'two' instead of 'dir/two'. The test still succeeds, without actually checking what it was supposed to, because this check is expected to fail anyway.

As a minimal fix, fix the name of the file to be checked.

---

This originates from fd777141 ("t0020: fix ignored exit code inside loops", 2015-03-25) where a loop

for f in one dir/two
do
do things on "$f" || break
done

was unrolled to correctly break out of the &&-chain. The filenames on the update-index line correctly copied one and dir/two, but the has_cr line somehow lost dir/ prefix.

Thanks. Will queue.

Quoted 16 lines
 t/t0020-crlf.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/t0020-crlf.sh +1 -1
index 5f056982a5..854da0ae16 100755
@@ -160,7 +160,7 @@ test_expect_success 'checkout with autocrlf=input' '
 	git config core.autocrlf input &&
 	git read-tree --reset -u HEAD &&
 	test_must_fail has_cr one &&
-	test_must_fail has_cr two &&
+	test_must_fail has_cr dir/two &&
 	git update-index -- one dir/two &&
 	test "$one" = $(git hash-object --stdin <one) &&
 	test "$two" = $(git hash-object --stdin <dir/two) &&
#3 lore raw
Quoted 8 lines · Junio C Hamano

This originates from fd777141 ("t0020: fix ignored exit code inside loops", 2015-03-25) where a loop

for f in one dir/two
do
do things on "$f" || break
done

Quoted 5 lines

was unrolled to correctly break out of the &&-chain. The filenames on the update-index line correctly copied one and dir/two, but the has_cr line somehow lost dir/ prefix.

Thanks. Will queue.

Whoops, my error. Thanks for catching it.

Quoted 10 lines

t/t0020-crlf.sh test_expect_success 'checkout with autocrlf=input' ' · line 163

Quoted 10 lines
t/t0020-crlf.sh +1 -1
index 5f056982a5..854da0ae16 100755
@@ -160,7 +160,7 @@ test_expect_success 'checkout with autocrlf=input' '
 	git config core.autocrlf input &&
 	git read-tree --reset -u HEAD &&
 	test_must_fail has_cr one &&
-	test_must_fail has_cr two &&
+	test_must_fail has_cr dir/two &&

I think I'm also responsible for these mis-uses of test_must_fail, which probably ought to be "!".

-Peff