Skip to content

Commit 6909474

Browse files
committed
Merge branch 'am/update-pathspec-f-f-tests'
Test updates. * am/update-pathspec-f-f-tests: t: directly test parse_pathspec_file() t: fix quotes tests for --pathspec-from-file
2 parents 043426c + d0d0a35 commit 6909474

10 files changed

+189
-11
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ TEST_BUILTINS_OBJS += test-mktemp.o
721721
TEST_BUILTINS_OBJS += test-oidmap.o
722722
TEST_BUILTINS_OBJS += test-online-cpus.o
723723
TEST_BUILTINS_OBJS += test-parse-options.o
724+
TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
724725
TEST_BUILTINS_OBJS += test-path-utils.o
725726
TEST_BUILTINS_OBJS += test-pkt-line.o
726727
TEST_BUILTINS_OBJS += test-prio-queue.o

t/helper/test-parse-pathspec-file.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "test-tool.h"
2+
#include "parse-options.h"
3+
#include "pathspec.h"
4+
#include "gettext.h"
5+
6+
int cmd__parse_pathspec_file(int argc, const char **argv)
7+
{
8+
struct pathspec pathspec;
9+
const char *pathspec_from_file = 0;
10+
int pathspec_file_nul = 0, i;
11+
12+
static const char *const usage[] = {
13+
"test-tool parse-pathspec-file --pathspec-from-file [--pathspec-file-nul]",
14+
NULL
15+
};
16+
17+
struct option options[] = {
18+
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
19+
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
20+
OPT_END()
21+
};
22+
23+
parse_options(argc, argv, 0, options, usage, 0);
24+
25+
parse_pathspec_file(&pathspec, 0, 0, 0, pathspec_from_file,
26+
pathspec_file_nul);
27+
28+
for (i = 0; i < pathspec.nr; i++)
29+
printf("%s\n", pathspec.items[i].original);
30+
31+
clear_pathspec(&pathspec);
32+
return 0;
33+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static struct test_cmd cmds[] = {
3939
{ "oidmap", cmd__oidmap },
4040
{ "online-cpus", cmd__online_cpus },
4141
{ "parse-options", cmd__parse_options },
42+
{ "parse-pathspec-file", cmd__parse_pathspec_file },
4243
{ "path-utils", cmd__path_utils },
4344
{ "pkt-line", cmd__pkt_line },
4445
{ "prio-queue", cmd__prio_queue },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int cmd__mktemp(int argc, const char **argv);
2929
int cmd__oidmap(int argc, const char **argv);
3030
int cmd__online_cpus(int argc, const char **argv);
3131
int cmd__parse_options(int argc, const char **argv);
32+
int cmd__parse_pathspec_file(int argc, const char** argv);
3233
int cmd__path_utils(int argc, const char **argv);
3334
int cmd__pkt_line(int argc, const char **argv);
3435
int cmd__prio_queue(int argc, const char **argv);

t/t0067-parse_pathspec_file.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/bin/sh
2+
3+
test_description='Test parse_pathspec_file()'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'one item from stdin' '
8+
cat >expect <<-\EOF &&
9+
fileA.t
10+
EOF
11+
12+
echo fileA.t |
13+
test-tool parse-pathspec-file --pathspec-from-file=- >actual &&
14+
15+
test_cmp expect actual
16+
'
17+
18+
test_expect_success 'one item from file' '
19+
cat >expect <<-\EOF &&
20+
fileA.t
21+
EOF
22+
23+
echo fileA.t >list &&
24+
test-tool parse-pathspec-file --pathspec-from-file=list >actual &&
25+
26+
test_cmp expect actual
27+
'
28+
29+
test_expect_success 'NUL delimiters' '
30+
cat >expect <<-\EOF &&
31+
fileA.t
32+
fileB.t
33+
EOF
34+
35+
printf "fileA.t\0fileB.t\0" |
36+
test-tool parse-pathspec-file --pathspec-from-file=- --pathspec-file-nul >actual &&
37+
38+
test_cmp expect actual
39+
'
40+
41+
test_expect_success 'LF delimiters' '
42+
cat >expect <<-\EOF &&
43+
fileA.t
44+
fileB.t
45+
EOF
46+
47+
printf "fileA.t\nfileB.t\n" |
48+
test-tool parse-pathspec-file --pathspec-from-file=- >actual &&
49+
50+
test_cmp expect actual
51+
'
52+
53+
test_expect_success 'no trailing delimiter' '
54+
cat >expect <<-\EOF &&
55+
fileA.t
56+
fileB.t
57+
EOF
58+
59+
printf "fileA.t\nfileB.t" |
60+
test-tool parse-pathspec-file --pathspec-from-file=- >actual &&
61+
62+
test_cmp expect actual
63+
'
64+
65+
test_expect_success 'CRLF delimiters' '
66+
cat >expect <<-\EOF &&
67+
fileA.t
68+
fileB.t
69+
EOF
70+
71+
printf "fileA.t\r\nfileB.t\r\n" |
72+
test-tool parse-pathspec-file --pathspec-from-file=- >actual &&
73+
74+
test_cmp expect actual
75+
'
76+
77+
test_expect_success 'quotes' '
78+
cat >expect <<-\EOF &&
79+
fileA.t
80+
EOF
81+
82+
cat >list <<-\EOF &&
83+
"file\101.t"
84+
EOF
85+
86+
test-tool parse-pathspec-file --pathspec-from-file=list >actual &&
87+
88+
test_cmp expect actual
89+
'
90+
91+
test_expect_success '--pathspec-file-nul takes quotes literally' '
92+
# Note: there is an extra newline because --pathspec-file-nul takes
93+
# input \n literally, too
94+
cat >expect <<-\EOF &&
95+
"file\101.t"
96+
97+
EOF
98+
99+
cat >list <<-\EOF &&
100+
"file\101.t"
101+
EOF
102+
103+
test-tool parse-pathspec-file --pathspec-from-file=list --pathspec-file-nul >actual &&
104+
105+
test_cmp expect actual
106+
'
107+
108+
test_done

t/t2026-checkout-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ test_expect_success 'CRLF delimiters' '
109109
test_expect_success 'quotes' '
110110
restore_checkpoint &&
111111
112-
printf "\"file\\101.t\"" | git checkout --pathspec-from-file=- HEAD^1 &&
112+
cat >list <<-\EOF &&
113+
"file\101.t"
114+
EOF
115+
116+
git checkout --pathspec-from-file=list HEAD^1 &&
113117
114118
cat >expect <<-\EOF &&
115119
M fileA.t
@@ -120,7 +124,10 @@ test_expect_success 'quotes' '
120124
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
121125
restore_checkpoint &&
122126
123-
printf "\"file\\101.t\"" >list &&
127+
cat >list <<-\EOF &&
128+
"file\101.t"
129+
EOF
130+
124131
test_must_fail git checkout --pathspec-from-file=list --pathspec-file-nul HEAD^1
125132
'
126133

t/t2072-restore-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ test_expect_success 'CRLF delimiters' '
109109
test_expect_success 'quotes' '
110110
restore_checkpoint &&
111111
112-
printf "\"file\\101.t\"" | git restore --pathspec-from-file=- --source=HEAD^1 &&
112+
cat >list <<-\EOF &&
113+
"file\101.t"
114+
EOF
115+
116+
git restore --pathspec-from-file=list --source=HEAD^1 &&
113117
114118
cat >expect <<-\EOF &&
115119
M fileA.t
@@ -120,7 +124,10 @@ test_expect_success 'quotes' '
120124
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
121125
restore_checkpoint &&
122126
123-
printf "\"file\\101.t\"" >list &&
127+
cat >list <<-\EOF &&
128+
"file\101.t"
129+
EOF
130+
124131
test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1
125132
'
126133

t/t3704-add-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ test_expect_success 'CRLF delimiters' '
9797
test_expect_success 'quotes' '
9898
restore_checkpoint &&
9999
100-
printf "\"file\\101.t\"" | git add --pathspec-from-file=- &&
100+
cat >list <<-\EOF &&
101+
"file\101.t"
102+
EOF
103+
104+
git add --pathspec-from-file=list &&
101105
102106
cat >expect <<-\EOF &&
103107
A fileA.t
@@ -108,7 +112,10 @@ test_expect_success 'quotes' '
108112
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
109113
restore_checkpoint &&
110114
111-
printf "\"file\\101.t\"" >list &&
115+
cat >list <<-\EOF &&
116+
"file\101.t"
117+
EOF
118+
112119
test_must_fail git add --pathspec-from-file=list --pathspec-file-nul
113120
'
114121

t/t7107-reset-pathspec-file.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ test_expect_success 'CRLF delimiters' '
105105
test_expect_success 'quotes' '
106106
restore_checkpoint &&
107107
108+
cat >list <<-\EOF &&
109+
"file\101.t"
110+
EOF
111+
108112
git rm fileA.t &&
109-
printf "\"file\\101.t\"" | git reset --pathspec-from-file=- &&
113+
git reset --pathspec-from-file=list &&
110114
111115
cat >expect <<-\EOF &&
112116
D fileA.t
@@ -117,8 +121,10 @@ test_expect_success 'quotes' '
117121
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
118122
restore_checkpoint &&
119123
120-
git rm fileA.t &&
121-
printf "\"file\\101.t\"" >list &&
124+
cat >list <<-\EOF &&
125+
"file\101.t"
126+
EOF
127+
122128
# Note: "git reset" has not yet learned to fail on wrong pathspecs
123129
git reset --pathspec-from-file=list --pathspec-file-nul &&
124130

t/t7526-commit-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ test_expect_success 'CRLF delimiters' '
100100
test_expect_success 'quotes' '
101101
restore_checkpoint &&
102102
103-
printf "\"file\\101.t\"" | git commit --pathspec-from-file=- -m "Commit" &&
103+
cat >list <<-\EOF &&
104+
"file\101.t"
105+
EOF
106+
107+
git commit --pathspec-from-file=list -m "Commit" &&
104108
105109
cat >expect <<-\EOF &&
106110
A fileA.t
@@ -111,7 +115,10 @@ test_expect_success 'quotes' '
111115
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
112116
restore_checkpoint &&
113117
114-
printf "\"file\\101.t\"" >list &&
118+
cat >list <<-\EOF &&
119+
"file\101.t"
120+
EOF
121+
115122
test_must_fail git commit --pathspec-from-file=list --pathspec-file-nul -m "Commit"
116123
'
117124

0 commit comments

Comments
 (0)