tests: change some 'test $(git) = "x"' to test_cmp
Change some of the patterns in the test suite where we were hiding the exit code from "git" by invoking it in a sub-shell within a "test" expression to use temporary files and test_cmp instead. These are not all the occurrences of this anti-pattern, but these in particular hid issues where LSAN was dying, and I'd thus marked these tests as passing under the linux-leaks CI job in past commits with "TEST_PASSES_SANITIZE_LEAK=true". Let's deal with that by either removing that marking, or skipping specific tests under !SANITIZE_LEAK. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 7, 2022 at 13:48 UTC
c4d1d526312a2dbe39c7997cb5a08cfce12f2427
4 files changed
+50
-29
t/t0002-gitfile.sh
+4
-2
@@ -65,9 +65,11 @@ test_expect_success 'check commit-tree' '
65
test_path_is_file "$REAL/objects/$(objpath $SHA)"
66
'
67
68
-test_expect_success 'check rev-list' '
68
+test_expect_success !SANITIZE_LEAK 'check rev-list' '
69
git update-ref "HEAD" "$SHA" &&
70
- test "$SHA" = "$(git rev-list HEAD)"
70
+ git rev-list HEAD >actual &&
71
+ echo $SHA >expected &&
72
+ test_cmp expected actual
73
'
74
75
test_expect_success 'setup_git_dir twice in subdir' '
t/t2200-add-update.sh
+21
-12
@@ -14,7 +14,6 @@ only the updates to dir/sub.
14
Also tested are "git add -u" without limiting, and "git add -u"
15
without contents changes, and other conditions'
16
17
-TEST_PASSES_SANITIZE_LEAK=true
17
. ./test-lib.sh
18
19
test_expect_success setup '
@@ -41,20 +40,28 @@ test_expect_success update '
40
'
41
42
test_expect_success 'update noticed a removal' '
44
- test "$(git ls-files dir1/sub1)" = ""
43
+ git ls-files dir1/sub1 >out &&
44
+ test_must_be_empty out
45
'
46
47
test_expect_success 'update touched correct path' '
48
- test "$(git diff-files --name-status dir2/sub3)" = ""
48
+ git diff-files --name-status dir2/sub3 >out &&
49
+ test_must_be_empty out
50
'
51
52
test_expect_success 'update did not touch other tracked files' '
52
- test "$(git diff-files --name-status check)" = "M check" &&
53
- test "$(git diff-files --name-status top)" = "M top"
53
+ echo "M check" >expect &&
54
+ git diff-files --name-status check >actual &&
55
+ test_cmp expect actual &&
56
+
57
+ echo "M top" >expect &&
58
+ git diff-files --name-status top >actual &&
59
+ test_cmp expect actual
60
'
61
62
test_expect_success 'update did not touch untracked files' '
57
- test "$(git ls-files dir2/other)" = ""
63
+ git ls-files dir2/other >out &&
64
+ test_must_be_empty out
65
'
66
67
test_expect_success 'cache tree has not been corrupted' '
@@ -76,9 +83,8 @@ test_expect_success 'update from a subdirectory' '
83
'
84
85
test_expect_success 'change gets noticed' '
79
-
80
- test "$(git diff-files --name-status dir1)" = ""
81
-
86
+ git diff-files --name-status dir1 >out &&
87
+ test_must_be_empty out
88
'
89
90
test_expect_success 'non-qualified update in subdir updates from the root' '
@@ -103,7 +109,8 @@ test_expect_success 'replace a file with a symlink' '
109
test_expect_success 'add everything changed' '
110
111
git add -u &&
106
- test -z "$(git diff-files)"
112
+ git diff-files >out &&
113
+ test_must_be_empty out
114
115
'
116
@@ -111,7 +118,8 @@ test_expect_success 'touch and then add -u' '
118
119
touch check &&
120
git add -u &&
114
- test -z "$(git diff-files)"
121
+ git diff-files >out &&
122
+ test_must_be_empty out
123
124
'
125
@@ -119,7 +127,8 @@ test_expect_success 'touch and then add explicitly' '
127
128
touch check &&
129
git add check &&
122
- test -z "$(git diff-files)"
130
+ git diff-files >out &&
131
+ test_must_be_empty out
132
133
'
134
t/t4128-apply-root.sh
+20
-13
@@ -2,8 +2,6 @@
2
3
test_description='apply same filename'
4
5
-
6
-TEST_PASSES_SANITIZE_LEAK=true
5
. ./test-lib.sh
6
7
test_expect_success 'setup' '
@@ -26,10 +24,11 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file
24
EOF
25
26
test_expect_success 'apply --directory -p (1)' '
29
-
27
git apply --directory=some/sub -p3 --index patch &&
31
- test Bello = $(git show :some/sub/dir/file) &&
32
- test Bello = $(cat some/sub/dir/file)
28
+ echo Bello >expect &&
29
+ git show :some/sub/dir/file >actual &&
30
+ test_cmp expect actual &&
31
+ test_cmp expect some/sub/dir/file
32
33
'
34
@@ -37,8 +36,10 @@ test_expect_success 'apply --directory -p (2) ' '
36
37
git reset --hard initial &&
38
git apply --directory=some/sub/ -p3 --index patch &&
40
- test Bello = $(git show :some/sub/dir/file) &&
41
- test Bello = $(cat some/sub/dir/file)
39
+ echo Bello >expect &&
40
+ git show :some/sub/dir/file >actual &&
41
+ test_cmp expect actual &&
42
+ test_cmp expect some/sub/dir/file
43
44
'
45
@@ -55,8 +56,10 @@ EOF
56
test_expect_success 'apply --directory (new file)' '
57
git reset --hard initial &&
58
git apply --directory=some/sub/dir/ --index patch &&
58
- test content = $(git show :some/sub/dir/newfile) &&
59
- test content = $(cat some/sub/dir/newfile)
59
+ echo content >expect &&
60
+ git show :some/sub/dir/newfile >actual &&
61
+ test_cmp expect actual &&
62
+ test_cmp expect some/sub/dir/newfile
63
'
64
65
cat > patch << EOF
@@ -72,8 +75,10 @@ EOF
75
test_expect_success 'apply --directory -p (new file)' '
76
git reset --hard initial &&
77
git apply -p2 --directory=some/sub/dir/ --index patch &&
75
- test content = $(git show :some/sub/dir/newfile2) &&
76
- test content = $(cat some/sub/dir/newfile2)
78
+ echo content >expect &&
79
+ git show :some/sub/dir/newfile2 >actual &&
80
+ test_cmp expect actual &&
81
+ test_cmp expect some/sub/dir/newfile2
82
'
83
84
cat > patch << EOF
@@ -107,8 +112,10 @@ EOF
112
test_expect_success 'apply --directory (quoted filename)' '
113
git reset --hard initial &&
114
git apply --directory=some/sub/dir/ --index patch &&
110
- test content = $(git show :some/sub/dir/quotefile) &&
111
- test content = $(cat some/sub/dir/quotefile)
115
+ echo content >expect &&
116
+ git show :some/sub/dir/quotefile >actual &&
117
+ test_cmp expect actual &&
118
+ test_cmp expect some/sub/dir/quotefile
119
'
120
121
test_done
t/t7103-reset-bare.sh
+5
-2
@@ -63,9 +63,12 @@ test_expect_success '"mixed" reset is not allowed in bare' '
63
test_must_fail git reset --mixed HEAD^
64
'
65
66
-test_expect_success '"soft" reset is allowed in bare' '
66
+test_expect_success !SANITIZE_LEAK '"soft" reset is allowed in bare' '
67
git reset --soft HEAD^ &&
68
- test "$(git show --pretty=format:%s | head -n 1)" = "one"
68
+ git show --pretty=format:%s >out &&
69
+ echo one >expect &&
70
+ head -n 1 out >actual &&
71
+ test_cmp expect actual
72
'
73
74
test_done