annotate tests/test-sh-quote.c @ 40231:9b3c79fdfe0b

strtod: fix clash with strtold Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817). * lib/strtod.c (compute_minus_zero, minus_zero): Simplify by remving the macro / external variable, and having just a function. User changed. This avoids the need for an external variable that might clash.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 11 Mar 2019 16:40:29 -0700
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of sh-quote module.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2012-2019 Free Software Foundation, Inc.
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2012. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* Specification. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include "sh-quote.h"
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <limits.h>
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <string.h>
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "macros.h"
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 static void
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 check_one (const char *input, const char *expected)
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 {
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 char buf[1000];
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 size_t output_len;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 char *output;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 char *bufend;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 output_len = shell_quote_length (input);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 output = shell_quote (input);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 ASSERT (strlen (output) == output_len);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 ASSERT (output_len <= sizeof (buf) - 2);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 memset (buf, '\0', output_len + 1);
18459
0a0fb98e47c9 sh-quote, system-quote: revert regression of unit test.
Bruno Haible <bruno@clisp.org>
parents: 18458
diff changeset
44 buf[output_len + 1] = '%';
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 bufend = shell_quote_copy (buf, input);
16839
85883252217c sh-quote tests: Make tests stricter.
Bruno Haible <bruno@clisp.org>
parents: 16831
diff changeset
46 ASSERT (bufend == buf + output_len);
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 ASSERT (memcmp (buf, output, output_len + 1) == 0);
18459
0a0fb98e47c9 sh-quote, system-quote: revert regression of unit test.
Bruno Haible <bruno@clisp.org>
parents: 18458
diff changeset
48 ASSERT (buf[output_len + 1] == '%');
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 ASSERT (strcmp (output, expected) == 0);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 free (output);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 int
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 main (void)
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 {
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 /* Check the shell_quote_length, shell_quote_copy, shell_quote functions. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 {
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 int c;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 /* Empty argument. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 check_one ("", "''");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Identifier or number. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 check_one ("foo", "foo");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 check_one ("phr0ck", "phr0ck");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 /* Whitespace would be interpreted as argument separator by the shell. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 check_one ("foo\tbar", "'foo\tbar'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 check_one ("foo\nbar", "'foo\nbar'");
16839
85883252217c sh-quote tests: Make tests stricter.
Bruno Haible <bruno@clisp.org>
parents: 16831
diff changeset
72 check_one ("foo\rbar", "'foo\rbar'");
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 check_one ("foo bar", "'foo bar'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 /* '!' at the beginning of argv[0] would introduce a negated command. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 check_one ("!foo", "'!foo'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 /* '"' would be interpreted as the start of a string. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 check_one ("\"foo\"bar", "'\"foo\"bar'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 /* '#' at the beginning of an argument would be interpreted as the start
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 of a comment. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 check_one ("#foo", "'#foo'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 /* '$' at the beginning of an argument would be interpreted as a variable
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 reference. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 check_one ("$foo", "'$foo'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 /* '&' at the beginning of an argument would be interpreted as a background
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 task indicator. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 check_one ("&", "'&'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 /* "'" would be interpreted as the start of a string. */
18458
f430af2a84d8 quotearg: fix stale tests
Pádraig Brady <P@draigBrady.com>
parents: 18189
diff changeset
94 check_one ("'foo'bar", "\"'foo'bar\"");
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 /* '(' at the beginning of argv[0] would introduce a subshell command. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 check_one ("(", "'('");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 /* ')' at the beginning of an argument would be interpreted as the end of
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 the command. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 check_one (")", "')'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 /* '*' would be interpreted as a wildcard character. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 check_one ("*", "'*'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 check_one ("*foo", "'*foo'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 /* ';' at the beginning of an argument would be interpreted as an empty
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 statement in argv[0] and as the end of the command otherwise. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 check_one (";", "';'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 check_one ("foo;", "'foo;'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 /* '<' would be interpreted as a redirection of stdin. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 check_one ("<", "'<'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 /* '=' inside argv[0] would be interpreted as an environment variable
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 assignment. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 check_one ("foo=bar", "'foo=bar'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 /* '>' would be interpreted as a redirection of stdout. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 check_one (">", "'>'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 /* '?' would be interpreted as a wildcard character. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 check_one ("?", "'?'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 check_one ("foo?bar", "'foo?bar'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 /* '^' would be interpreted in old /bin/sh, e.g. SunOS 4.1.4. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 check_one ("^", "'^'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 /* "[...]" would be interpreted as a wildcard pattern. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 check_one ("[", "'['");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 check_one ("]", "]"); /* or "']'" */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 /* '\' would be interpreted as an escape character. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 check_one ("\\foo", "'\\foo'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 /* '`' would be interpreted as the start of a command substitution. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 check_one ("`foo", "'`foo'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 /* '{' at the beginning of argv[0] would introduce a complex command. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 check_one ("{", "'{'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 /* '|' at the beginning of an argument would be interpreted as a pipe
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 between commands. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 check_one ("|", "'|'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 /* '}' at the beginning of an argument would be interpreted as the end of
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 the command. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 check_one ("}", "'}'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 /* '~' at the beginning of an argument would be interpreted as a reference
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 to a user's home directory. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 check_one ("~", "'~'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 check_one ("~foo", "'~foo'");
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 /* A string that contains both ' and ". */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 check_one ("foo'bar\"baz", "'foo'\\''bar\"baz'"); /* or "\"foo'bar\\\"baz\"" */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 /* All other characters don't need quoting. */
16839
85883252217c sh-quote tests: Make tests stricter.
Bruno Haible <bruno@clisp.org>
parents: 16831
diff changeset
159 for (c = 1; c <= UCHAR_MAX; c++)
16831
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 if (strchr ("\t\n\r !\"#$&'()*;<=>?^[\\]`{|}~", c) == NULL)
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 {
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 char s[5];
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 s[0] = 'a';
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 s[1] = (char) c;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 s[2] = 'z';
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 s[3] = (char) c;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 s[4] = '\0';
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 check_one (s, s);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 }
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 }
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 /* Check the shell_quote_argv function. */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 {
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 char *argv[1];
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 char *result;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 argv[0] = NULL;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 result = shell_quote_argv (argv);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (strcmp (result, "") == 0);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 free (result);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 }
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 {
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 char *argv[2];
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 char *result;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 argv[0] = (char *) "foo bar/baz";
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 argv[1] = NULL;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 result = shell_quote_argv (argv);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 ASSERT (strcmp (result, "'foo bar/baz'") == 0); /* or "\"foo bar/baz\"" */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 free (result);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 }
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 {
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 char *argv[3];
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 char *result;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 argv[0] = (char *) "foo bar/baz";
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 argv[1] = (char *) "$";
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 argv[2] = NULL;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 result = shell_quote_argv (argv);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 ASSERT (strcmp (result, "'foo bar/baz' '$'") == 0); /* or "\"foo bar/baz\" \"\\$\"" */
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 free (result);
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 }
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 return 0;
f9fc08c5e5c2 Tests for module 'sh-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 }