Skip to content

Commit 74f16b0

Browse files
peffgitster
authored andcommitted
mask necessary whitespace policy violations in test scripts
All of these violations are necessary parts of the tests (which are generally checking the behavior of trailing whitespace, or contain diff fragments with empty lines). Our solution is two-fold: 1. Process input with whitespace problems using tr. This has the added bonus that it becomes very obvious where the bogus whitespace is intended to go. 2. Move large diff fragments into their own supplemental files. This gets rid of the whitespace problem, since supplemental files are not checked, and it also makes the test script a bit easier to read. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3b2eb18 commit 74f16b0

File tree

8 files changed

+131
-136
lines changed

8 files changed

+131
-136
lines changed

t/t3800-mktag.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ check_verify_failure 'disallow spaces in tag email' \
241241
############################################################
242242
# 17. disallow missing tag timestamp
243243

244-
cat >tag.sig <<EOF
244+
tr '_' ' ' >tag.sig <<EOF
245245
object $head
246246
type commit
247247
tag mytag
248-
tagger T A Gger <tagger@example.com>
248+
tagger T A Gger <tagger@example.com>__
249249
250250
EOF
251251

t/t4015-diff-whitespace.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ EOF
6262

6363
git update-index x
6464

65-
cat << EOF > x
65+
tr '_' ' ' << EOF > x
6666
whitespace at beginning
6767
whitespace change
6868
white space in the middle
69-
whitespace at end
69+
whitespace at end__
7070
unchanged line
7171
CR at end
7272
EOF
7373

74-
tr 'Q' '\015' << EOF > expect
74+
tr 'Q_' '\015 ' << EOF > expect
7575
diff --git a/x b/x
7676
index d99af23..8b32fb5 100644
7777
--- a/x
@@ -84,7 +84,7 @@ index d99af23..8b32fb5 100644
8484
+ whitespace at beginning
8585
+whitespace change
8686
+white space in the middle
87-
+whitespace at end
87+
+whitespace at end__
8888
unchanged line
8989
-CR at endQ
9090
+CR at end

t/t4109-apply-multifrag.sh

Lines changed: 4 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -9,134 +9,10 @@ test_description='git apply test patches with multiple fragments.
99
'
1010
. ./test-lib.sh
1111

12-
# setup
13-
14-
cat > patch1.patch <<\EOF
15-
diff --git a/main.c b/main.c
16-
new file mode 100644
17-
--- /dev/null
18-
+++ b/main.c
19-
@@ -0,0 +1,23 @@
20-
+#include <stdio.h>
21-
+
22-
+int func(int num);
23-
+void print_int(int num);
24-
+
25-
+int main() {
26-
+ int i;
27-
+
28-
+ for (i = 0; i < 10; i++) {
29-
+ print_int(func(i));
30-
+ }
31-
+
32-
+ return 0;
33-
+}
34-
+
35-
+int func(int num) {
36-
+ return num * num;
37-
+}
38-
+
39-
+void print_int(int num) {
40-
+ printf("%d", num);
41-
+}
42-
+
43-
EOF
44-
cat > patch2.patch <<\EOF
45-
diff --git a/main.c b/main.c
46-
--- a/main.c
47-
+++ b/main.c
48-
@@ -1,7 +1,9 @@
49-
+#include <stdlib.h>
50-
#include <stdio.h>
51-
52-
int func(int num);
53-
void print_int(int num);
54-
+void print_ln();
55-
56-
int main() {
57-
int i;
58-
@@ -10,6 +12,8 @@
59-
print_int(func(i));
60-
}
61-
62-
+ print_ln();
63-
+
64-
return 0;
65-
}
66-
67-
@@ -21,3 +25,7 @@
68-
printf("%d", num);
69-
}
70-
71-
+void print_ln() {
72-
+ printf("\n");
73-
+}
74-
+
75-
EOF
76-
cat > patch3.patch <<\EOF
77-
diff --git a/main.c b/main.c
78-
--- a/main.c
79-
+++ b/main.c
80-
@@ -1,9 +1,7 @@
81-
-#include <stdlib.h>
82-
#include <stdio.h>
83-
84-
int func(int num);
85-
void print_int(int num);
86-
-void print_ln();
87-
88-
int main() {
89-
int i;
90-
@@ -12,8 +10,6 @@
91-
print_int(func(i));
92-
}
93-
94-
- print_ln();
95-
-
96-
return 0;
97-
}
98-
99-
@@ -25,7 +21,3 @@
100-
printf("%d", num);
101-
}
102-
103-
-void print_ln() {
104-
- printf("\n");
105-
-}
106-
-
107-
EOF
108-
cat > patch4.patch <<\EOF
109-
diff --git a/main.c b/main.c
110-
--- a/main.c
111-
+++ b/main.c
112-
@@ -1,13 +1,14 @@
113-
#include <stdio.h>
114-
115-
int func(int num);
116-
-void print_int(int num);
117-
+int func2(int num);
118-
119-
int main() {
120-
int i;
121-
122-
for (i = 0; i < 10; i++) {
123-
- print_int(func(i));
124-
+ printf("%d", func(i));
125-
+ printf("%d", func3(i));
126-
}
127-
128-
return 0;
129-
@@ -17,7 +18,7 @@
130-
return num * num;
131-
}
132-
133-
-void print_int(int num) {
134-
- printf("%d", num);
135-
+int func2(int num) {
136-
+ return num * num * num;
137-
}
138-
139-
EOF
12+
cp ../t4109/patch1.patch .
13+
cp ../t4109/patch2.patch .
14+
cp ../t4109/patch3.patch .
15+
cp ../t4109/patch4.patch .
14016

14117
test_expect_success "S = git apply (1)" \
14218
'git apply patch1.patch patch2.patch'

t/t4109/patch1.patch

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff --git a/main.c b/main.c
2+
new file mode 100644
3+
--- /dev/null
4+
+++ b/main.c
5+
@@ -0,0 +1,23 @@
6+
+#include <stdio.h>
7+
+
8+
+int func(int num);
9+
+void print_int(int num);
10+
+
11+
+int main() {
12+
+ int i;
13+
+
14+
+ for (i = 0; i < 10; i++) {
15+
+ print_int(func(i));
16+
+ }
17+
+
18+
+ return 0;
19+
+}
20+
+
21+
+int func(int num) {
22+
+ return num * num;
23+
+}
24+
+
25+
+void print_int(int num) {
26+
+ printf("%d", num);
27+
+}
28+
+

t/t4109/patch2.patch

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/main.c b/main.c
2+
--- a/main.c
3+
+++ b/main.c
4+
@@ -1,7 +1,9 @@
5+
+#include <stdlib.h>
6+
#include <stdio.h>
7+
8+
int func(int num);
9+
void print_int(int num);
10+
+void print_ln();
11+
12+
int main() {
13+
int i;
14+
@@ -10,6 +12,8 @@
15+
print_int(func(i));
16+
}
17+
18+
+ print_ln();
19+
+
20+
return 0;
21+
}
22+
23+
@@ -21,3 +25,7 @@
24+
printf("%d", num);
25+
}
26+
27+
+void print_ln() {
28+
+ printf("\n");
29+
+}
30+
+

t/t4109/patch3.patch

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cat > patch3.patch <<\EOF
2+
diff --git a/main.c b/main.c
3+
--- a/main.c
4+
+++ b/main.c
5+
@@ -1,9 +1,7 @@
6+
-#include <stdlib.h>
7+
#include <stdio.h>
8+
9+
int func(int num);
10+
void print_int(int num);
11+
-void print_ln();
12+
13+
int main() {
14+
int i;
15+
@@ -12,8 +10,6 @@
16+
print_int(func(i));
17+
}
18+
19+
- print_ln();
20+
-
21+
return 0;
22+
}
23+
24+
@@ -25,7 +21,3 @@
25+
printf("%d", num);
26+
}
27+
28+
-void print_ln() {
29+
- printf("\n");
30+
-}
31+
-

t/t4109/patch4.patch

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/main.c b/main.c
2+
--- a/main.c
3+
+++ b/main.c
4+
@@ -1,13 +1,14 @@
5+
#include <stdio.h>
6+
7+
int func(int num);
8+
-void print_int(int num);
9+
+int func2(int num);
10+
11+
int main() {
12+
int i;
13+
14+
for (i = 0; i < 10; i++) {
15+
- print_int(func(i));
16+
+ printf("%d", func(i));
17+
+ printf("%d", func3(i));
18+
}
19+
20+
return 0;
21+
@@ -17,7 +18,7 @@
22+
return num * num;
23+
}
24+
25+
-void print_int(int num) {
26+
- printf("%d", num);
27+
+int func2(int num) {
28+
+ return num * num * num;
29+
}
30+

t/t4119-apply-config.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ test_expect_success setup '
1919
'
2020

2121
# Also handcraft GNU diff output; note this has trailing whitespace.
22-
cat >gpatch.file <<\EOF &&
22+
tr '_' ' ' >gpatch.file <<\EOF &&
2323
--- file1 2007-02-21 01:04:24.000000000 -0800
2424
+++ file1+ 2007-02-21 01:07:44.000000000 -0800
2525
@@ -1 +1 @@
2626
-A
27-
+B
27+
+B_
2828
EOF
2929

3030
sed -e 's|file1|sub/&|' gpatch.file >gpatch-sub.file &&

0 commit comments

Comments
 (0)