@matheusbsbs / matheus-bagliano / commits / 379e51d1ae
Fork 0

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 <johannes.schindelin@gmx.de>

Johannes Schindelin committed Sep 20, 2019 at 00:12 UTC 379e51d1ae668a1f26d50eb59b3f8befc1eb8883
1 file changed +10 -3
t/helper/test-run-command.c
+10 -3
@@ -67,12 +67,13 @@ static int quote_stress_test(int argc, const char **argv)
67 * were passed in.
68 */
69 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;
71 struct strbuf out = STRBUF_INIT;
72 struct argv_array args = ARGV_ARRAY_INIT;
73 struct option options[] = {
74 OPT_INTEGER('n', "trials", &trials, "Number of trials"),
75 OPT_INTEGER('s', "skip", &skip, "Skip <n> trials"),
76 + OPT_BOOL('m', "msys2", &msys2, "Test quoting for MSYS2's sh"),
77 OPT_END()
78 };
79 const char * const usage[] = {
@@ -82,14 +83,20 @@ static int quote_stress_test(int argc, const char **argv)
83
84 argc = parse_options(argc, argv, NULL, options, usage, 0);
85
86 + setenv("MSYS_NO_PATHCONV", "1", 0);
87 +
88 for (i = 0; i < trials; i++) {
89 struct child_process cp = CHILD_PROCESS_INIT;
90 size_t arg_count, arg_offset;
91 int ret = 0;
92
93 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);
100 arg_offset = args.argc;
101
102 if (argc > 0) {