Skip to content

Commit c4d1d52

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 715d08a commit c4d1d52

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

t/t0002-gitfile.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ test_expect_success 'check commit-tree' '
6565
test_path_is_file "$REAL/objects/$(objpath $SHA)"
6666
'
6767

68-
test_expect_success 'check rev-list' '
68+
test_expect_success !SANITIZE_LEAK 'check rev-list' '
6969
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
7173
'
7274

7375
test_expect_success 'setup_git_dir twice in subdir' '

t/t2200-add-update.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ only the updates to dir/sub.
1414
Also tested are "git add -u" without limiting, and "git add -u"
1515
without contents changes, and other conditions'
1616

17-
TEST_PASSES_SANITIZE_LEAK=true
1817
. ./test-lib.sh
1918

2019
test_expect_success setup '
@@ -41,20 +40,28 @@ test_expect_success update '
4140
'
4241

4342
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
4545
'
4646

4747
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
4950
'
5051

5152
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
5460
'
5561

5662
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
5865
'
5966

6067
test_expect_success 'cache tree has not been corrupted' '
@@ -76,9 +83,8 @@ test_expect_success 'update from a subdirectory' '
7683
'
7784

7885
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
8288
'
8389

8490
test_expect_success 'non-qualified update in subdir updates from the root' '
@@ -103,23 +109,26 @@ test_expect_success 'replace a file with a symlink' '
103109
test_expect_success 'add everything changed' '
104110
105111
git add -u &&
106-
test -z "$(git diff-files)"
112+
git diff-files >out &&
113+
test_must_be_empty out
107114
108115
'
109116

110117
test_expect_success 'touch and then add -u' '
111118
112119
touch check &&
113120
git add -u &&
114-
test -z "$(git diff-files)"
121+
git diff-files >out &&
122+
test_must_be_empty out
115123
116124
'
117125

118126
test_expect_success 'touch and then add explicitly' '
119127
120128
touch check &&
121129
git add check &&
122-
test -z "$(git diff-files)"
130+
git diff-files >out &&
131+
test_must_be_empty out
123132
124133
'
125134

t/t4128-apply-root.sh

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
test_description='apply same filename'
44

5-
6-
TEST_PASSES_SANITIZE_LEAK=true
75
. ./test-lib.sh
86

97
test_expect_success 'setup' '
@@ -26,19 +24,22 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file
2624
EOF
2725

2826
test_expect_success 'apply --directory -p (1)' '
29-
3027
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
3332
3433
'
3534

3635
test_expect_success 'apply --directory -p (2) ' '
3736
3837
git reset --hard initial &&
3938
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
4243
4344
'
4445

@@ -55,8 +56,10 @@ EOF
5556
test_expect_success 'apply --directory (new file)' '
5657
git reset --hard initial &&
5758
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
6063
'
6164

6265
cat > patch << EOF
@@ -72,8 +75,10 @@ EOF
7275
test_expect_success 'apply --directory -p (new file)' '
7376
git reset --hard initial &&
7477
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
7782
'
7883

7984
cat > patch << EOF
@@ -107,8 +112,10 @@ EOF
107112
test_expect_success 'apply --directory (quoted filename)' '
108113
git reset --hard initial &&
109114
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
112119
'
113120

114121
test_done

t/t7103-reset-bare.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ test_expect_success '"mixed" reset is not allowed in bare' '
6363
test_must_fail git reset --mixed HEAD^
6464
'
6565

66-
test_expect_success '"soft" reset is allowed in bare' '
66+
test_expect_success !SANITIZE_LEAK '"soft" reset is allowed in bare' '
6767
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
6972
'
7073

7174
test_done

0 commit comments

Comments
 (0)