Skip to content

Commit 379e51d

Browse files
committed
quote-stress-test: offer to test quoting arguments for MSYS2 sh
It is unfortunate that we need to quote arguments differently on Windows, depending whether we build a command-line for MSYS2's `sh` or for other Windows executables. We already have a test helper to verify the latter, with this patch we can also verify the former. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7530a62 commit 379e51d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

t/helper/test-run-command.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ static int quote_stress_test(int argc, const char **argv)
6767
* were passed in.
6868
*/
6969
char special[] = ".?*\\^_\"'`{}()[]<>@~&+:;$%"; // \t\r\n\a";
70-
int i, j, k, trials = 100, skip = 0;
70+
int i, j, k, trials = 100, skip = 0, msys2 = 0;
7171
struct strbuf out = STRBUF_INIT;
7272
struct argv_array args = ARGV_ARRAY_INIT;
7373
struct option options[] = {
7474
OPT_INTEGER('n', "trials", &trials, "Number of trials"),
7575
OPT_INTEGER('s', "skip", &skip, "Skip <n> trials"),
76+
OPT_BOOL('m', "msys2", &msys2, "Test quoting for MSYS2's sh"),
7677
OPT_END()
7778
};
7879
const char * const usage[] = {
@@ -82,14 +83,20 @@ static int quote_stress_test(int argc, const char **argv)
8283

8384
argc = parse_options(argc, argv, NULL, options, usage, 0);
8485

86+
setenv("MSYS_NO_PATHCONV", "1", 0);
87+
8588
for (i = 0; i < trials; i++) {
8689
struct child_process cp = CHILD_PROCESS_INIT;
8790
size_t arg_count, arg_offset;
8891
int ret = 0;
8992

9093
argv_array_clear(&args);
91-
argv_array_pushl(&args, "test-run-command",
92-
"quote-echo", NULL);
94+
if (msys2)
95+
argv_array_pushl(&args, "sh", "-c",
96+
"printf %s\\\\0 \"$@\"", "skip", NULL);
97+
else
98+
argv_array_pushl(&args, "test-run-command",
99+
"quote-echo", NULL);
93100
arg_offset = args.argc;
94101

95102
if (argc > 0) {

0 commit comments

Comments
 (0)