OpenCoverage

test.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/test.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* test.c - GNU test program (ksb and mjb) */-
2-
3/* Modified to run with the GNU shell Apr 25, 1988 by bfox. */-
4-
5/* Copyright (C) 1987-2010 Free Software Foundation, Inc.-
6-
7 This file is part of GNU Bash, the Bourne Again SHell.-
8-
9 Bash is free software: you can redistribute it and/or modify-
10 it under the terms of the GNU General Public License as published by-
11 the Free Software Foundation, either version 3 of the License, or-
12 (at your option) any later version.-
13-
14 Bash is distributed in the hope that it will be useful,-
15 but WITHOUT ANY WARRANTY; without even the implied warranty of-
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
17 GNU General Public License for more details.-
18-
19 You should have received a copy of the GNU General Public License-
20 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
21*/-
22-
23/* Define PATTERN_MATCHING to get the csh-like =~ and !~ pattern-matching-
24 binary operators. */-
25/* #define PATTERN_MATCHING */-
26-
27#if defined (HAVE_CONFIG_H)-
28# include <config.h>-
29#endif-
30-
31#include <stdio.h>-
32-
33#include "bashtypes.h"-
34-
35#if !defined (HAVE_LIMITS_H) && defined (HAVE_SYS_PARAM_H)-
36# include <sys/param.h>-
37#endif-
38-
39#if defined (HAVE_UNISTD_H)-
40# include <unistd.h>-
41#endif-
42-
43#include <errno.h>-
44#if !defined (errno)-
45extern int errno;-
46#endif /* !errno */-
47-
48#if !defined (_POSIX_VERSION) && defined (HAVE_SYS_FILE_H)-
49# include <sys/file.h>-
50#endif /* !_POSIX_VERSION */-
51#include "posixstat.h"-
52#include "filecntl.h"-
53#include "stat-time.h"-
54-
55#include "bashintl.h"-
56-
57#include "shell.h"-
58#include "pathexp.h"-
59#include "test.h"-
60#include "builtins/common.h"-
61-
62#include <glob/strmatch.h>-
63-
64#if !defined (STRLEN)-
65# define STRLEN(s) ((s)[0] ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)-
66#endif-
67-
68#if !defined (STREQ)-
69# define STREQ(a, b) ((a)[0] == (b)[0] && strcmp ((a), (b)) == 0)-
70#endif /* !STREQ */-
71#define STRCOLLEQ(a, b) ((a)[0] == (b)[0] && strcoll ((a), (b)) == 0)-
72-
73#if !defined (R_OK)-
74#define R_OK 4-
75#define W_OK 2-
76#define X_OK 1-
77#define F_OK 0-
78#endif /* R_OK */-
79-
80#define EQ 0-
81#define NE 1-
82#define LT 2-
83#define GT 3-
84#define LE 4-
85#define GE 5-
86-
87#define NT 0-
88#define OT 1-
89#define EF 2-
90-
91/* The following few defines control the truth and false output of each stage.-
92 TRUE and FALSE are what we use to compute the final output value.-
93 SHELL_BOOLEAN is the form which returns truth or falseness in shell terms.-
94 Default is TRUE = 1, FALSE = 0, SHELL_BOOLEAN = (!value). */-
95#define TRUE 1-
96#define FALSE 0-
97#define SHELL_BOOLEAN(value) (!(value))-
98-
99#define TEST_ERREXIT_STATUS 2-
100-
101static procenv_t test_exit_buf;-
102static int test_error_return;-
103#define test_exit(val) \-
104 do { test_error_return = val; sh_longjmp (test_exit_buf, 1); } while (0)-
105-
106extern int sh_stat __P((const char *, struct stat *));-
107-
108static int pos; /* The offset of the current argument in ARGV. */-
109static int argc; /* The number of arguments present in ARGV. */-
110static char **argv; /* The argument list. */-
111static int noeval;-
112-
113static void test_syntax_error __P((char *, char *)) __attribute__((__noreturn__));-
114static void beyond __P((void)) __attribute__((__noreturn__));-
115static void integer_expected_error __P((char *)) __attribute__((__noreturn__));-
116-
117static int unary_operator __P((void));-
118static int binary_operator __P((void));-
119static int two_arguments __P((void));-
120static int three_arguments __P((void));-
121static int posixtest __P((void));-
122-
123static int expr __P((void));-
124static int term __P((void));-
125static int and __P((void));-
126static int or __P((void));-
127-
128static int filecomp __P((char *, char *, int));-
129static int arithcomp __P((char *, char *, int, int));-
130static int patcomp __P((char *, char *, int));-
131-
132static void-
133test_syntax_error (format, arg)-
134 char *format, *arg;-
135{-
136 builtin_error (format, arg);-
137 test_exit (TEST_ERREXIT_STATUS);-
138}
never executed: end of block
0
139-
140/*-
141 * beyond - call when we're beyond the end of the argument list (an-
142 * error condition)-
143 */-
144static void-
145beyond ()-
146{-
147 test_syntax_error (_("argument expected"), (char *)NULL);-
148}
never executed: end of block
0
149-
150/* Syntax error for when an integer argument was expected, but-
151 something else was found. */-
152static void-
153integer_expected_error (pch)-
154 char *pch;-
155{-
156 test_syntax_error (_("%s: integer expression expected"), pch);-
157}
never executed: end of block
0
158-
159/* Increment our position in the argument list. Check that we're not-
160 past the end of the argument list. This check is suppressed if the-
161 argument is FALSE. Made a macro for efficiency. */-
162#define advance(f) do { ++pos; if (f && pos >= argc) beyond (); } while (0)-
163#define unary_advance() do { advance (1); ++pos; } while (0)-
164-
165/*-
166 * expr:-
167 * or-
168 */-
169static int-
170expr ()-
171{-
172 if (pos >= argc)
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
0-13
173 beyond ();
never executed: beyond ();
0
174-
175 return (FALSE ^ or ()); /* Same with this. */
executed 13 times by 1 test: return (0 ^ or ());
Executed by:
  • Self test
13
176}-
177-
178/*-
179 * or:-
180 * and-
181 * and '-o' or-
182 */-
183static int-
184or ()-
185{-
186 int value, v2;-
187-
188 value = and ();-
189 if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'o' && !argv[pos][2])
pos < argcDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
argv[pos][0] == '-'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == 'o'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
!argv[pos][2]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
190 {-
191 advance (0);
dead code: pos >= argc
dead code: beyond ();
-
192 v2 = or ();-
193 return (value || v2);
executed 2 times by 1 test: return (value || v2);
Executed by:
  • Self test
2
194 }-
195-
196 return (value);
executed 11 times by 1 test: return (value);
Executed by:
  • Self test
11
197}-
198-
199/*-
200 * and:-
201 * term-
202 * term '-a' and-
203 */-
204static int-
205and ()-
206{-
207 int value, v2;-
208-
209 value = term ();-
210 if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'a' && !argv[pos][2])
pos < argcDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
argv[pos][0] == '-'Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == 'a'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
!argv[pos][2]Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-14
211 {-
212 advance (0);
dead code: pos >= argc
dead code: beyond ();
-
213 v2 = and ();-
214 return (value && v2);
executed 9 times by 1 test: return (value && v2);
Executed by:
  • Self test
9
215 }-
216 return (value);
executed 13 times by 1 test: return (value);
Executed by:
  • Self test
13
217}-
218-
219/*-
220 * term - parse a term and return 1 or 0 depending on whether the term-
221 * evaluates to true or false, respectively.-
222 *-
223 * term ::=-
224 * '-'('a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'k'|'p'|'r'|'s'|'u'|'w'|'x') filename-
225 * '-'('G'|'L'|'O'|'S'|'N') filename-
226 * '-t' [int]-
227 * '-'('z'|'n') string-
228 * '-'('v'|'R') varname-
229 * '-o' option-
230 * string-
231 * string ('!='|'='|'==') string-
232 * <int> '-'(eq|ne|le|lt|ge|gt) <int>-
233 * file '-'(nt|ot|ef) file-
234 * '(' <expr> ')'-
235 * int ::=-
236 * positive and negative integers-
237 */-
238static int-
239term ()-
240{-
241 int value;-
242-
243 if (pos >= argc)
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
0-25
244 beyond ();
never executed: beyond ();
0
245-
246 /* Deal with leading `not's. */-
247 if (argv[pos][0] == '!' && argv[pos][1] == '\0')
argv[pos][0] == '!'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-24
248 {-
249 value = 0;-
250 while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0')
pos < argcDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
argv[pos][0] == '!'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
argv[pos][1] == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
251 {-
252 advance (1);
never executed: beyond ();
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
253 value = 1 - value;-
254 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
255-
256 return (value ? !term() : term());
executed 1 time by 1 test: return (value ? !term() : term());
Executed by:
  • Self test
1
257 }-
258-
259 /* A paren-bracketed argument. */-
260 if (argv[pos][0] == '(' && argv[pos][1] == '\0') /* ) */
argv[pos][0] == '('Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == '\0'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-21
261 {-
262 advance (1);
never executed: beyond ();
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
263 value = expr ();-
264 if (argv[pos] == 0) /* ( */
argv[pos] == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
1-2
265 test_syntax_error (_("`)' expected"), (char *)NULL);
executed 1 time by 1 test: test_syntax_error ( dcgettext (((void *)0), "`)' expected" , 5) , (char *) ((void *)0) );
Executed by:
  • Self test
1
266 else if (argv[pos][0] != ')' || argv[pos][1]) /* ( */
argv[pos][0] != ')'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
argv[pos][1]Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
267 test_syntax_error (_("`)' expected, found %s"), argv[pos]);
executed 1 time by 1 test: test_syntax_error ( dcgettext (((void *)0), "`)' expected, found %s" , 5) , argv[pos]);
Executed by:
  • Self test
1
268 advance (0);
dead code: pos >= argc
dead code: beyond ();
-
269 return (value);
executed 1 time by 1 test: return (value);
Executed by:
  • Self test
1
270 }-
271-
272 /* are there enough arguments left that this could be dyadic? */-
273 if ((pos + 3 <= argc) && test_binop (argv[pos + 1]))
(pos + 3 <= argc)Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
test_binop (argv[pos + 1])Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-15
274 value = binary_operator ();
executed 9 times by 1 test: value = binary_operator ();
Executed by:
  • Self test
9
275-
276 /* Might be a switch type argument */-
277 else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
argv[pos][0] == '-'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
argv[pos][1]Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
argv[pos][2] == '\0'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
278 {-
279 if (test_unop (argv[pos]))
test_unop (argv[pos])Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
280 value = unary_operator ();
executed 8 times by 1 test: value = unary_operator ();
Executed by:
  • Self test
8
281 else-
282 test_syntax_error (_("%s: unary operator expected"), argv[pos]);
never executed: test_syntax_error ( dcgettext (((void *)0), "%s: unary operator expected" , 5) , argv[pos]);
0
283 }-
284 else-
285 {-
286 value = argv[pos][0] != '\0';-
287 advance (0);
dead code: pos >= argc
dead code: beyond ();
-
288 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
289-
290 return (value);
executed 21 times by 1 test: return (value);
Executed by:
  • Self test
21
291}-
292-
293static int-
294stat_mtime (fn, st, ts)-
295 char *fn;-
296 struct stat *st;-
297 struct timespec *ts;-
298{-
299 int r;-
300-
301 r = sh_stat (fn, st);-
302 if (r < 0)
r < 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
2-15
303 return r;
executed 2 times by 1 test: return r;
Executed by:
  • Self test
2
304 *ts = get_stat_mtime (st);-
305 return 0;
executed 15 times by 1 test: return 0;
Executed by:
  • Self test
15
306}-
307-
308static int-
309filecomp (s, t, op)-
310 char *s, *t;-
311 int op;-
312{-
313 struct stat st1, st2;-
314 struct timespec ts1, ts2;-
315 int r1, r2;-
316-
317 if ((r1 = stat_mtime (s, &st1, &ts1)) < 0)
(r1 = stat_mti...t1, &ts1)) < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
1-8
318 {-
319 if (op == EF)
op == 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
320 return (FALSE);
executed 1 time by 1 test: return (0);
Executed by:
  • Self test
1
321 }
never executed: end of block
0
322 if ((r2 = stat_mtime (t, &st2, &ts2)) < 0)
(r2 = stat_mti...t2, &ts2)) < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
1-7
323 {-
324 if (op == EF)
op == 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
325 return (FALSE);
executed 1 time by 1 test: return (0);
Executed by:
  • Self test
1
326 }
never executed: end of block
0
327 -
328 switch (op)-
329 {-
330 case OT: return (r1 < r2 || (r2 == 0 && timespec_cmp (ts1, ts2) < 0));
executed 2 times by 1 test: return (r1 < r2 || (r2 == 0 && timespec_cmp (ts1, ts2) < 0));
Executed by:
  • Self test
executed 2 times by 1 test: case 1:
Executed by:
  • Self test
2
331 case NT: return (r1 > r2 || (r1 == 0 && timespec_cmp (ts1, ts2) > 0));
executed 2 times by 1 test: return (r1 > r2 || (r1 == 0 && timespec_cmp (ts1, ts2) > 0));
Executed by:
  • Self test
executed 2 times by 1 test: case 0:
Executed by:
  • Self test
2
332 case EF: return (same_file (s, t, &st1, &st2));
executed 3 times by 1 test: return (same_file (s, t, &st1, &st2));
Executed by:
  • Self test
executed 3 times by 1 test: case 2:
Executed by:
  • Self test
3
333 }-
334 return (FALSE);
never executed: return (0);
0
335}-
336-
337static int-
338arithcomp (s, t, op, flags)-
339 char *s, *t;-
340 int op, flags;-
341{-
342 intmax_t l, r;-
343 int expok;-
344-
345 if (flags & TEST_ARITHEXP)
flags & 0x02Description
TRUEevaluated 153 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 341 times by 1 test
Evaluated by:
  • Self test
153-341
346 {-
347 l = evalexp (s, 0, &expok);-
348 if (expok == 0)
expok == 0Description
TRUEnever evaluated
FALSEevaluated 153 times by 1 test
Evaluated by:
  • Self test
0-153
349 return (FALSE); /* should probably longjmp here */
never executed: return (0);
0
350 r = evalexp (t, 0, &expok);-
351 if (expok == 0)
expok == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 152 times by 1 test
Evaluated by:
  • Self test
1-152
352 return (FALSE); /* ditto */
executed 1 time by 1 test: return (0);
Executed by:
  • Self test
1
353 }
executed 152 times by 1 test: end of block
Executed by:
  • Self test
152
354 else-
355 {-
356 if (legal_number (s, &l) == 0)
legal_number (s, &l) == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 337 times by 1 test
Evaluated by:
  • Self test
4-337
357 integer_expected_error (s);
executed 4 times by 1 test: integer_expected_error (s);
Executed by:
  • Self test
4
358 if (legal_number (t, &r) == 0)
legal_number (t, &r) == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 333 times by 1 test
Evaluated by:
  • Self test
4-333
359 integer_expected_error (t);
executed 4 times by 1 test: integer_expected_error (t);
Executed by:
  • Self test
4
360 }
executed 333 times by 1 test: end of block
Executed by:
  • Self test
333
361-
362 switch (op)-
363 {-
364 case EQ: return (l == r);
executed 353 times by 1 test: return (l == r);
Executed by:
  • Self test
executed 353 times by 1 test: case 0:
Executed by:
  • Self test
353
365 case NE: return (l != r);
executed 8 times by 1 test: return (l != r);
Executed by:
  • Self test
executed 8 times by 1 test: case 1:
Executed by:
  • Self test
8
366 case LT: return (l < r);
executed 20 times by 1 test: return (l < r);
Executed by:
  • Self test
executed 20 times by 1 test: case 2:
Executed by:
  • Self test
20
367 case GT: return (l > r);
executed 98 times by 1 test: return (l > r);
Executed by:
  • Self test
executed 98 times by 1 test: case 3:
Executed by:
  • Self test
98
368 case LE: return (l <= r);
executed 4 times by 1 test: return (l <= r);
Executed by:
  • Self test
executed 4 times by 1 test: case 4:
Executed by:
  • Self test
4
369 case GE: return (l >= r);
executed 2 times by 1 test: return (l >= r);
Executed by:
  • Self test
executed 2 times by 1 test: case 5:
Executed by:
  • Self test
2
370 }-
371-
372 return (FALSE);
never executed: return (0);
0
373}-
374-
375static int-
376patcomp (string, pat, op)-
377 char *string, *pat;-
378 int op;-
379{-
380 int m;-
381-
382 m = strmatch (pat, string, FNMATCH_EXTFLAG|FNMATCH_IGNCASE);-
383 return ((op == EQ) ? (m == 0) : (m != 0));
executed 422 times by 1 test: return ((op == 0) ? (m == 0) : (m != 0));
Executed by:
  • Self test
422
384}-
385-
386int-
387binary_test (op, arg1, arg2, flags)-
388 char *op, *arg1, *arg2;-
389 int flags;-
390{-
391 int patmatch;-
392-
393 patmatch = (flags & TEST_PATMATCH);-
394-
395 if (op[0] == '=' && (op[1] == '\0' || (op[1] == '=' && op[2] == '\0')))
op[0] == '='Description
TRUEevaluated 797 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2003 times by 1 test
Evaluated by:
  • Self test
op[1] == '\0'Description
TRUEevaluated 720 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 77 times by 1 test
Evaluated by:
  • Self test
op[1] == '='Description
TRUEevaluated 77 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
op[2] == '\0'Description
TRUEevaluated 77 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2003
396 return (patmatch ? patcomp (arg1, arg2, EQ) : STREQ (arg1, arg2));
executed 797 times by 1 test: return (patmatch ? patcomp (arg1, arg2, 0) : ((arg1)[0] == (arg2)[0] && __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( arg1 ) && __builtin_constant_p ( arg2 ) && (__s1_len = __builtin_strlen ( arg1 ), __s2_len = __builtin_strlen ( arg...result = (((const unsigned char *) (const char *) ( arg2 ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( arg2 ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( arg1 , arg2 )))); }) == 0));
Executed by:
  • Self test
never executed: __result = (((const unsigned char *) (const char *) ( arg1 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( arg2 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-797
397 else if ((op[0] == '>' || op[0] == '<') && op[1] == '\0')
op[0] == '>'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2000 times by 1 test
Evaluated by:
  • Self test
op[0] == '<'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1998 times by 1 test
Evaluated by:
  • Self test
op[1] == '\0'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2000
398 {-
399#if defined (HAVE_STRCOLL)-
400 if (shell_compatibility_level > 40 && flags & TEST_LOCALE)
shell_compatibility_level > 40Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
flags & 0x04Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-5
401 return ((op[0] == '>') ? (strcoll (arg1, arg2) > 0) : (strcoll (arg1, arg2) < 0));
executed 2 times by 1 test: return ((op[0] == '>') ? (strcoll (arg1, arg2) > 0) : (strcoll (arg1, arg2) < 0));
Executed by:
  • Self test
2
402 else-
403#endif-
404 return ((op[0] == '>') ? (strcmp (arg1, arg2) > 0) : (strcmp (arg1, arg2) < 0));
executed 3 times by 1 test: return ((op[0] == '>') ? ( __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( arg1 ) && __builtin_constant_p ( arg2 ) && (__s1_len = __builtin_strlen ( arg1 ), __s2_len = __builtin_strlen ( arg2 ), (!((size_t)(const void *)(( arg1 ) + 1) ..._result = (((const unsigned char *) (const char *) ( arg2 ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( arg2 ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( arg1 , arg2 )))); }) < 0));
Executed by:
  • Self test
never executed: __result = (((const unsigned char *) (const char *) ( arg1 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( arg2 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( arg1 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( arg2 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-3
405 }-
406 else if (op[0] == '!' && op[1] == '=' && op[2] == '\0')
op[0] == '!'Description
TRUEevaluated 1495 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 503 times by 1 test
Evaluated by:
  • Self test
op[1] == '='Description
TRUEevaluated 1495 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
op[2] == '\0'Description
TRUEevaluated 1495 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1495
407 return (patmatch ? patcomp (arg1, arg2, NE) : (STREQ (arg1, arg2) == 0));
executed 1495 times by 1 test: return (patmatch ? patcomp (arg1, arg2, 1) : (((arg1)[0] == (arg2)[0] && __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( arg1 ) && __builtin_constant_p ( arg2 ) && (__s1_len = __builtin_strlen ( arg1 ), __s2_len = __builtin_strlen ( ar... = (((const unsigned char *) (const char *) ( arg2 ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( arg2 ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( arg1 , arg2 )))); }) == 0) == 0));
Executed by:
  • Self test
never executed: __result = (((const unsigned char *) (const char *) ( arg1 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( arg2 ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1495
408 -
409-
410 else if (op[2] == 't')
op[2] == 't'Description
TRUEevaluated 122 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 381 times by 1 test
Evaluated by:
  • Self test
122-381
411 {-
412 switch (op[1])-
413 {-
414 case 'n': return (filecomp (arg1, arg2, NT)); /* -nt */
executed 2 times by 1 test: return (filecomp (arg1, arg2, 0));
Executed by:
  • Self test
executed 2 times by 1 test: case 'n':
Executed by:
  • Self test
2
415 case 'o': return (filecomp (arg1, arg2, OT)); /* -ot */
executed 2 times by 1 test: return (filecomp (arg1, arg2, 1));
Executed by:
  • Self test
executed 2 times by 1 test: case 'o':
Executed by:
  • Self test
2
416 case 'l': return (arithcomp (arg1, arg2, LT, flags)); /* -lt */
executed 20 times by 1 test: return (arithcomp (arg1, arg2, 2, flags));
Executed by:
  • Self test
executed 20 times by 1 test: case 'l':
Executed by:
  • Self test
20
417 case 'g': return (arithcomp (arg1, arg2, GT, flags)); /* -gt */
executed 98 times by 1 test: return (arithcomp (arg1, arg2, 3, flags));
Executed by:
  • Self test
executed 98 times by 1 test: case 'g':
Executed by:
  • Self test
98
418 }-
419 }
never executed: end of block
0
420 else if (op[1] == 'e')
op[1] == 'e'Description
TRUEevaluated 367 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
14-367
421 {-
422 switch (op[2])-
423 {-
424 case 'f': return (filecomp (arg1, arg2, EF)); /* -ef */
executed 5 times by 1 test: return (filecomp (arg1, arg2, 2));
Executed by:
  • Self test
executed 5 times by 1 test: case 'f':
Executed by:
  • Self test
5
425 case 'q': return (arithcomp (arg1, arg2, EQ, flags)); /* -eq */
executed 362 times by 1 test: return (arithcomp (arg1, arg2, 0, flags));
Executed by:
  • Self test
executed 362 times by 1 test: case 'q':
Executed by:
  • Self test
362
426 }-
427 }
never executed: end of block
0
428 else if (op[2] == 'e')
op[2] == 'e'Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-14
429 {-
430 switch (op[1])-
431 {-
432 case 'n': return (arithcomp (arg1, arg2, NE, flags)); /* -ne */
executed 8 times by 1 test: return (arithcomp (arg1, arg2, 1, flags));
Executed by:
  • Self test
executed 8 times by 1 test: case 'n':
Executed by:
  • Self test
8
433 case 'g': return (arithcomp (arg1, arg2, GE, flags)); /* -ge */
executed 2 times by 1 test: return (arithcomp (arg1, arg2, 5, flags));
Executed by:
  • Self test
executed 2 times by 1 test: case 'g':
Executed by:
  • Self test
2
434 case 'l': return (arithcomp (arg1, arg2, LE, flags)); /* -le */
executed 4 times by 1 test: return (arithcomp (arg1, arg2, 4, flags));
Executed by:
  • Self test
executed 4 times by 1 test: case 'l':
Executed by:
  • Self test
4
435 }-
436 }
never executed: end of block
0
437-
438 return (FALSE); /* should never get here */
never executed: return (0);
0
439}-
440-
441-
442static int-
443binary_operator ()-
444{-
445 int value;-
446 char *w;-
447-
448 w = argv[pos + 1];-
449 if ((w[0] == '=' && (w[1] == '\0' || (w[1] == '=' && w[2] == '\0'))) || /* =, == */
w[0] == '='Description
TRUEevaluated 406 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1814 times by 1 test
Evaluated by:
  • Self test
w[1] == '\0'Description
TRUEevaluated 402 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
w[1] == '='Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
w[2] == '\0'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1814
450 ((w[0] == '>' || w[0] == '<') && w[1] == '\0') || /* <, > */
w[0] == '>'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1812 times by 1 test
Evaluated by:
  • Self test
w[0] == '<'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1811 times by 1 test
Evaluated by:
  • Self test
w[1] == '\0'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1812
451 (w[0] == '!' && w[1] == '=' && w[2] == '\0')) /* != */
w[0] == '!'Description
TRUEevaluated 1464 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 347 times by 1 test
Evaluated by:
  • Self test
w[1] == '='Description
TRUEevaluated 1464 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
w[2] == '\0'Description
TRUEevaluated 1464 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1464
452 {-
453 value = binary_test (w, argv[pos], argv[pos + 2], 0);-
454 pos += 3;-
455 return (value);
executed 1873 times by 1 test: return (value);
Executed by:
  • Self test
1873
456 }-
457-
458#if defined (PATTERN_MATCHING)-
459 if ((w[0] == '=' || w[0] == '!') && w[1] == '~' && w[2] == '\0')-
460 {-
461 value = patcomp (argv[pos], argv[pos + 2], w[0] == '=' ? EQ : NE);-
462 pos += 3;-
463 return (value);-
464 }-
465#endif-
466-
467 if ((w[0] != '-' || w[3] != '\0') || test_binop (w) == 0)
w[0] != '-'Description
TRUEnever evaluated
FALSEevaluated 347 times by 1 test
Evaluated by:
  • Self test
w[3] != '\0'Description
TRUEnever evaluated
FALSEevaluated 347 times by 1 test
Evaluated by:
  • Self test
test_binop (w) == 0Description
TRUEnever evaluated
FALSEevaluated 347 times by 1 test
Evaluated by:
  • Self test
0-347
468 {-
469 test_syntax_error (_("%s: binary operator expected"), w);-
470 /* NOTREACHED */-
471 return (FALSE);
never executed: return (0);
0
472 }-
473-
474 value = binary_test (w, argv[pos], argv[pos + 2], 0);-
475 pos += 3;-
476 return value;
executed 339 times by 1 test: return value;
Executed by:
  • Self test
339
477}-
478-
479static int-
480unary_operator ()-
481{-
482 char *op;-
483 intmax_t r;-
484-
485 op = argv[pos];-
486 if (test_unop (op) == 0)
test_unop (op) == 0Description
TRUEnever evaluated
FALSEevaluated 2117 times by 1 test
Evaluated by:
  • Self test
0-2117
487 return (FALSE);
never executed: return (0);
0
488-
489 /* the only tricky case is `-t', which may or may not take an argument. */-
490 if (op[1] == 't')
op[1] == 't'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2109 times by 1 test
Evaluated by:
  • Self test
8-2109
491 {-
492 advance (0);
dead code: pos >= argc
dead code: beyond ();
-
493 if (pos < argc)
pos < argcDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
494 {-
495 if (legal_number (argv[pos], &r))
legal_number (argv[pos], &r)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
2-6
496 {-
497 advance (0);
dead code: pos >= argc
dead code: beyond ();
-
498 return (unary_test (op, argv[pos - 1]));
executed 2 times by 1 test: return (unary_test (op, argv[pos - 1]));
Executed by:
  • Self test
2
499 }-
500 else-
501 return (FALSE);
executed 6 times by 1 test: return (0);
Executed by:
  • Self test
6
502 }-
503 else-
504 return (unary_test (op, "1"));
never executed: return (unary_test (op, "1"));
0
505 }-
506-
507 /* All of the unary operators take an argument, so we first call-
508 unary_advance (), which checks to make sure that there is an-
509 argument, and then advances pos right past it. This means that-
510 pos - 1 is the location of the argument. */-
511 unary_advance ();
never executed: beyond ();
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 2109 times by 1 test
Evaluated by:
  • Self test
0-2109
512 return (unary_test (op, argv[pos - 1]));
executed 2109 times by 1 test: return (unary_test (op, argv[pos - 1]));
Executed by:
  • Self test
2109
513}-
514-
515int-
516unary_test (op, arg)-
517 char *op, *arg;-
518{-
519 intmax_t r;-
520 struct stat stat_buf;-
521 SHELL_VAR *v;-
522 -
523 switch (op[1])-
524 {-
525 case 'a': /* file exists in the file system? */
executed 2 times by 1 test: case 'a':
Executed by:
  • Self test
2
526 case 'e':
executed 7 times by 1 test: case 'e':
Executed by:
  • Self test
7
527 return (sh_stat (arg, &stat_buf) == 0);
executed 9 times by 1 test: return (sh_stat (arg, &stat_buf) == 0);
Executed by:
  • Self test
9
528-
529 case 'r': /* file is readable? */
executed 27 times by 1 test: case 'r':
Executed by:
  • Self test
27
530 return (sh_eaccess (arg, R_OK) == 0);
executed 27 times by 1 test: return (sh_eaccess (arg, 4 ) == 0);
Executed by:
  • Self test
27
531-
532 case 'w': /* File is writeable? */
executed 10 times by 1 test: case 'w':
Executed by:
  • Self test
10
533 return (sh_eaccess (arg, W_OK) == 0);
executed 10 times by 1 test: return (sh_eaccess (arg, 2 ) == 0);
Executed by:
  • Self test
10
534-
535 case 'x': /* File is executable? */
executed 120 times by 1 test: case 'x':
Executed by:
  • Self test
120
536 return (sh_eaccess (arg, X_OK) == 0);
executed 120 times by 1 test: return (sh_eaccess (arg, 1 ) == 0);
Executed by:
  • Self test
120
537-
538 case 'O': /* File is owned by you? */
executed 1 time by 1 test: case 'O':
Executed by:
  • Self test
1
539 return (sh_stat (arg, &stat_buf) == 0 &&
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (uid_t) current_user.euid == (uid_t) stat_buf.st_uid);
Executed by:
  • Self test
1
540 (uid_t) current_user.euid == (uid_t) stat_buf.st_uid);
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (uid_t) current_user.euid == (uid_t) stat_buf.st_uid);
Executed by:
  • Self test
1
541-
542 case 'G': /* File is owned by your group? */
executed 1 time by 1 test: case 'G':
Executed by:
  • Self test
1
543 return (sh_stat (arg, &stat_buf) == 0 &&
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (gid_t) current_user.egid == (gid_t) stat_buf.st_gid);
Executed by:
  • Self test
1
544 (gid_t) current_user.egid == (gid_t) stat_buf.st_gid);
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (gid_t) current_user.egid == (gid_t) stat_buf.st_gid);
Executed by:
  • Self test
1
545-
546 case 'N':
executed 1 time by 1 test: case 'N':
Executed by:
  • Self test
1
547 return (sh_stat (arg, &stat_buf) == 0 &&
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && stat_buf. st_atim.tv_sec <= stat_buf. st_mtim.tv_sec );
Executed by:
  • Self test
1
548 stat_buf.st_atime <= stat_buf.st_mtime);
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && stat_buf. st_atim.tv_sec <= stat_buf. st_mtim.tv_sec );
Executed by:
  • Self test
1
549-
550 case 'f': /* File is a file? */
executed 144 times by 1 test: case 'f':
Executed by:
  • Self test
144
551 if (sh_stat (arg, &stat_buf) < 0)
sh_stat (arg, &stat_buf) < 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 137 times by 1 test
Evaluated by:
  • Self test
7-137
552 return (FALSE);
executed 7 times by 1 test: return (0);
Executed by:
  • Self test
7
553-
554 /* -f is true if the given file exists and is a regular file. */-
555#if defined (S_IFMT)-
556 return (S_ISREG (stat_buf.st_mode) || (stat_buf.st_mode & S_IFMT) == 0);
executed 137 times by 1 test: return ( (((( stat_buf.st_mode )) & 0170000) == (0100000)) || (stat_buf.st_mode & 0170000 ) == 0);
Executed by:
  • Self test
137
557#else-
558 return (S_ISREG (stat_buf.st_mode));-
559#endif /* !S_IFMT */-
560-
561 case 'd': /* File is a directory? */
executed 16 times by 1 test: case 'd':
Executed by:
  • Self test
16
562 return (sh_stat (arg, &stat_buf) == 0 && (S_ISDIR (stat_buf.st_mode)));
executed 16 times by 1 test: return (sh_stat (arg, &stat_buf) == 0 && ( (((( stat_buf.st_mode )) & 0170000) == (0040000)) ));
Executed by:
  • Self test
16
563-
564 case 's': /* File has something in it? */
executed 3 times by 1 test: case 's':
Executed by:
  • Self test
3
565 return (sh_stat (arg, &stat_buf) == 0 && stat_buf.st_size > (off_t) 0);
executed 3 times by 1 test: return (sh_stat (arg, &stat_buf) == 0 && stat_buf.st_size > (off_t) 0);
Executed by:
  • Self test
3
566-
567 case 'S': /* File is a socket? */
executed 1 time by 1 test: case 'S':
Executed by:
  • Self test
1
568#if !defined (S_ISSOCK)-
569 return (FALSE);-
570#else-
571 return (sh_stat (arg, &stat_buf) == 0 && S_ISSOCK (stat_buf.st_mode));
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (((( stat_buf.st_mode )) & 0170000) == (0140000)) );
Executed by:
  • Self test
1
572#endif /* S_ISSOCK */-
573-
574 case 'c': /* File is character special? */
executed 2 times by 1 test: case 'c':
Executed by:
  • Self test
2
575 return (sh_stat (arg, &stat_buf) == 0 && S_ISCHR (stat_buf.st_mode));
executed 2 times by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (((( stat_buf.st_mode )) & 0170000) == (0020000)) );
Executed by:
  • Self test
2
576-
577 case 'b': /* File is block special? */
executed 2 times by 1 test: case 'b':
Executed by:
  • Self test
2
578 return (sh_stat (arg, &stat_buf) == 0 && S_ISBLK (stat_buf.st_mode));
executed 2 times by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (((( stat_buf.st_mode )) & 0170000) == (0060000)) );
Executed by:
  • Self test
2
579-
580 case 'p': /* File is a named pipe? */
executed 3 times by 1 test: case 'p':
Executed by:
  • Self test
3
581#ifndef S_ISFIFO-
582 return (FALSE);-
583#else-
584 return (sh_stat (arg, &stat_buf) == 0 && S_ISFIFO (stat_buf.st_mode));
executed 3 times by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (((( stat_buf.st_mode )) & 0170000) == (0010000)) );
Executed by:
  • Self test
3
585#endif /* S_ISFIFO */-
586-
587 case 'L': /* Same as -h */
never executed: case 'L':
0
588 case 'h': /* File is a symbolic link? */
executed 1 time by 1 test: case 'h':
Executed by:
  • Self test
1
589#if !defined (S_ISLNK) || !defined (HAVE_LSTAT)-
590 return (FALSE);-
591#else-
592 return ((arg[0] != '\0') &&
executed 1 time by 1 test: return ((arg[0] != '\0') && (lstat (arg, &stat_buf) == 0) && (((( stat_buf.st_mode )) & 0170000) == (0120000)) );
Executed by:
  • Self test
1
593 (lstat (arg, &stat_buf) == 0) && S_ISLNK (stat_buf.st_mode));
executed 1 time by 1 test: return ((arg[0] != '\0') && (lstat (arg, &stat_buf) == 0) && (((( stat_buf.st_mode )) & 0170000) == (0120000)) );
Executed by:
  • Self test
1
594#endif /* S_IFLNK && HAVE_LSTAT */-
595-
596 case 'u': /* File is setuid? */
executed 3 times by 1 test: case 'u':
Executed by:
  • Self test
3
597 return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISUID) != 0);
executed 3 times by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & 04000 ) != 0);
Executed by:
  • Self test
3
598-
599 case 'g': /* File is setgid? */
executed 2 times by 1 test: case 'g':
Executed by:
  • Self test
2
600 return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISGID) != 0);
executed 2 times by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & 02000 ) != 0);
Executed by:
  • Self test
2
601-
602 case 'k': /* File has sticky bit set? */
executed 1 time by 1 test: case 'k':
Executed by:
  • Self test
1
603#if !defined (S_ISVTX)-
604 /* This is not Posix, and is not defined on some Posix systems. */-
605 return (FALSE);-
606#else-
607 return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISVTX) != 0);
executed 1 time by 1 test: return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & 01000 ) != 0);
Executed by:
  • Self test
1
608#endif-
609-
610 case 't': /* File fd is a terminal? */
executed 2 times by 1 test: case 't':
Executed by:
  • Self test
2
611 if (legal_number (arg, &r) == 0)
legal_number (arg, &r) == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
612 return (FALSE);
never executed: return (0);
0
613 return ((r == (int)r) && isatty ((int)r));
executed 2 times by 1 test: return ((r == (int)r) && isatty ((int)r));
Executed by:
  • Self test
2
614-
615 case 'n': /* True if arg has some length. */
executed 1808 times by 1 test: case 'n':
Executed by:
  • Self test
1808
616 return (arg[0] != '\0');
executed 1808 times by 1 test: return (arg[0] != '\0');
Executed by:
  • Self test
1808
617-
618 case 'z': /* True if arg has no length. */
executed 45 times by 1 test: case 'z':
Executed by:
  • Self test
45
619 return (arg[0] == '\0');
executed 45 times by 1 test: return (arg[0] == '\0');
Executed by:
  • Self test
45
620-
621 case 'o': /* True if option `arg' is set. */
executed 1 time by 1 test: case 'o':
Executed by:
  • Self test
1
622 return (minus_o_option_value (arg) == 1);
executed 1 time by 1 test: return (minus_o_option_value (arg) == 1);
Executed by:
  • Self test
1
623-
624 case 'v':
executed 28 times by 1 test: case 'v':
Executed by:
  • Self test
28
625 v = find_variable (arg);-
626#if defined (ARRAY_VARS)-
627 if (v == 0 && valid_array_reference (arg, 0))
v == 0Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
valid_array_reference (arg, 0)Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
7-19
628 {-
629 char *t;-
630 int rtype, ret;-
631 t = array_value (arg, 0, 0, &rtype, (arrayind_t *)0);-
632 ret = t ? TRUE : FALSE;
tDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6
633 if (rtype > 0) /* subscript is * or @ */
rtype > 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-7
634 free (t);
executed 7 times by 1 test: sh_xfree((t), "test.c", 634);
Executed by:
  • Self test
7
635 return ret;
executed 12 times by 1 test: return ret;
Executed by:
  • Self test
12
636 }-
637 else if (v && invisible_p (v) == 0 && array_p (v))
vDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib...001000))) == 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0000004)))Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
1-9
638 {-
639 char *t;-
640 /* [[ -v foo ]] == [[ -v foo[0] ]] */-
641 t = array_reference (array_cell (v), 0);-
642 return (t ? TRUE : FALSE);
executed 5 times by 1 test: return (t ? 1 : 0);
Executed by:
  • Self test
5
643 }-
644 else if (v && invisible_p (v) == 0 && assoc_p (v))
vDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib...001000))) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0000040)))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
1-7
645 {-
646 char *t;-
647 t = assoc_reference (assoc_cell (v), "0");-
648 return (t ? TRUE : FALSE);
executed 1 time by 1 test: return (t ? 1 : 0);
Executed by:
  • Self test
1
649 }-
650#endif-
651 return (v && invisible_p (v) == 0 && var_isset (v) ? TRUE : FALSE);
executed 10 times by 1 test: return (v && ((((v)->attributes) & (0x0001000))) == 0 && ((v)->value != 0) ? 1 : 0);
Executed by:
  • Self test
10
652-
653 case 'R':
never executed: case 'R':
0
654 v = find_variable_noref (arg);-
655 return ((v && invisible_p (v) == 0 && var_isset (v) && nameref_p (v)) ? TRUE : FALSE);
never executed: return ((v && ((((v)->attributes) & (0x0001000))) == 0 && ((v)->value != 0) && ((((v)->attributes) & (0x0000800)))) ? 1 : 0);
0
656 }-
657-
658 /* We can't actually get here, but this shuts up gcc. */-
659 return (FALSE);
never executed: return (0);
0
660}-
661-
662/* Return TRUE if OP is one of the test command's binary operators. */-
663int-
664test_binop (op)-
665 char *op;-
666{-
667 if (op[0] == '=' && op[1] == '\0')
op[0] == '='Description
TRUEevaluated 739 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2351 times by 1 test
Evaluated by:
  • Self test
op[1] == '\0'Description
TRUEevaluated 452 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 287 times by 1 test
Evaluated by:
  • Self test
287-2351
668 return (1); /* '=' */
executed 452 times by 1 test: return (1);
Executed by:
  • Self test
452
669 else if ((op[0] == '<' || op[0] == '>') && op[1] == '\0') /* string <, > */
op[0] == '<'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2637 times by 1 test
Evaluated by:
  • Self test
op[0] == '>'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2635 times by 1 test
Evaluated by:
  • Self test
op[1] == '\0'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2637
670 return (1);
executed 3 times by 1 test: return (1);
Executed by:
  • Self test
3
671 else if ((op[0] == '=' || op[0] == '!') && op[1] == '=' && op[2] == '\0')
op[0] == '='Description
TRUEevaluated 287 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2348 times by 1 test
Evaluated by:
  • Self test
op[0] == '!'Description
TRUEevaluated 1510 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 838 times by 1 test
Evaluated by:
  • Self test
op[1] == '='Description
TRUEevaluated 1706 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 91 times by 1 test
Evaluated by:
  • Self test
op[2] == '\0'Description
TRUEevaluated 1706 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2348
672 return (1); /* `==' and `!=' */
executed 1706 times by 1 test: return (1);
Executed by:
  • Self test
1706
673#if defined (PATTERN_MATCHING)-
674 else if (op[2] == '\0' && op[1] == '~' && (op[0] == '=' || op[0] == '!'))-
675 return (1);-
676#endif-
677 else if (op[0] != '-' || op[1] == '\0' || op[2] == '\0' || op[3] != '\0')
op[0] != '-'Description
TRUEevaluated 99 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 830 times by 1 test
Evaluated by:
  • Self test
op[1] == '\0'Description
TRUEnever evaluated
FALSEevaluated 830 times by 1 test
Evaluated by:
  • Self test
op[2] == '\0'Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 788 times by 1 test
Evaluated by:
  • Self test
op[3] != '\0'Description
TRUEnever evaluated
FALSEevaluated 788 times by 1 test
Evaluated by:
  • Self test
0-830
678 return (0);
executed 141 times by 1 test: return (0);
Executed by:
  • Self test
141
679 else-
680 {-
681 if (op[2] == 't')
op[2] == 't'Description
TRUEevaluated 128 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 660 times by 1 test
Evaluated by:
  • Self test
128-660
682 switch (op[1])-
683 {-
684 case 'n': /* -nt */
executed 4 times by 1 test: case 'n':
Executed by:
  • Self test
4
685 case 'o': /* -ot */
executed 4 times by 1 test: case 'o':
Executed by:
  • Self test
4
686 case 'l': /* -lt */
executed 50 times by 1 test: case 'l':
Executed by:
  • Self test
50
687 case 'g': /* -gt */
executed 70 times by 1 test: case 'g':
Executed by:
  • Self test
70
688 return (1);
executed 128 times by 1 test: return (1);
Executed by:
  • Self test
128
689 default:
never executed: default:
0
690 return (0);
never executed: return (0);
0
691 }-
692 else if (op[1] == 'e')
op[1] == 'e'Description
TRUEevaluated 607 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
53-607
693 switch (op[2])-
694 {-
695 case 'q': /* -eq */
executed 597 times by 1 test: case 'q':
Executed by:
  • Self test
597
696 case 'f': /* -ef */
executed 10 times by 1 test: case 'f':
Executed by:
  • Self test
10
697 return (1);
executed 607 times by 1 test: return (1);
Executed by:
  • Self test
607
698 default:
never executed: default:
0
699 return (0);
never executed: return (0);
0
700 }-
701 else if (op[2] == 'e')
op[2] == 'e'Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-53
702 switch (op[1])-
703 {-
704 case 'n': /* -ne */
executed 21 times by 1 test: case 'n':
Executed by:
  • Self test
21
705 case 'g': /* -ge */
executed 20 times by 1 test: case 'g':
Executed by:
  • Self test
20
706 case 'l': /* -le */
executed 12 times by 1 test: case 'l':
Executed by:
  • Self test
12
707 return (1);
executed 53 times by 1 test: return (1);
Executed by:
  • Self test
53
708 default:
never executed: default:
0
709 return (0);
never executed: return (0);
0
710 }-
711 else-
712 return (0);
never executed: return (0);
0
713 }-
714}-
715-
716/* Return non-zero if OP is one of the test command's unary operators. */-
717int-
718test_unop (op)-
719 char *op;-
720{-
721 if (op[0] != '-' || (op[1] && op[2] != 0))
op[0] != '-'Description
TRUEnever evaluated
FALSEevaluated 4367 times by 1 test
Evaluated by:
  • Self test
op[1]Description
TRUEevaluated 4367 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
op[2] != 0Description
TRUEnever evaluated
FALSEevaluated 4367 times by 1 test
Evaluated by:
  • Self test
0-4367
722 return (0);
never executed: return (0);
0
723-
724 switch (op[1])-
725 {-
726 case 'a': case 'b': case 'c': case 'd': case 'e':
executed 4 times by 1 test: case 'a':
Executed by:
  • Self test
executed 4 times by 1 test: case 'b':
Executed by:
  • Self test
executed 4 times by 1 test: case 'c':
Executed by:
  • Self test
executed 33 times by 1 test: case 'd':
Executed by:
  • Self test
executed 17 times by 1 test: case 'e':
Executed by:
  • Self test
4-33
727 case 'f': case 'g': case 'h': case 'k': case 'n':
executed 290 times by 1 test: case 'f':
Executed by:
  • Self test
executed 4 times by 1 test: case 'g':
Executed by:
  • Self test
executed 6 times by 1 test: case 'h':
Executed by:
  • Self test
executed 2 times by 1 test: case 'k':
Executed by:
  • Self test
executed 3587 times by 1 test: case 'n':
Executed by:
  • Self test
2-3587
728 case 'o': case 'p': case 'r': case 's': case 't':
executed 3 times by 1 test: case 'o':
Executed by:
  • Self test
executed 6 times by 1 test: case 'p':
Executed by:
  • Self test
executed 63 times by 1 test: case 'r':
Executed by:
  • Self test
executed 6 times by 1 test: case 's':
Executed by:
  • Self test
executed 16 times by 1 test: case 't':
Executed by:
  • Self test
3-63
729 case 'u': case 'v': case 'w': case 'x': case 'z':
executed 6 times by 1 test: case 'u':
Executed by:
  • Self test
executed 40 times by 1 test: case 'v':
Executed by:
  • Self test
executed 24 times by 1 test: case 'w':
Executed by:
  • Self test
executed 148 times by 1 test: case 'x':
Executed by:
  • Self test
executed 95 times by 1 test: case 'z':
Executed by:
  • Self test
6-148
730 case 'G': case 'L': case 'O': case 'S': case 'N':
executed 2 times by 1 test: case 'G':
Executed by:
  • Self test
never executed: case 'L':
executed 2 times by 1 test: case 'O':
Executed by:
  • Self test
executed 2 times by 1 test: case 'S':
Executed by:
  • Self test
executed 2 times by 1 test: case 'N':
Executed by:
  • Self test
0-2
731 case 'R':
never executed: case 'R':
0
732 return (1);
executed 4366 times by 1 test: return (1);
Executed by:
  • Self test
4366
733 }-
734-
735 return (0);
executed 1 time by 1 test: return (0);
Executed by:
  • Self test
1
736}-
737-
738static int-
739two_arguments ()-
740{-
741 if (argv[pos][0] == '!' && argv[pos][1] == '\0')
argv[pos][0] == '!'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2112 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == '\0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2112
742 return (argv[pos + 1][0] == '\0');
executed 2 times by 1 test: return (argv[pos + 1][0] == '\0');
Executed by:
  • Self test
2
743 else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
argv[pos][0] == '-'Description
TRUEevaluated 2110 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
argv[pos][1]Description
TRUEevaluated 2110 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
argv[pos][2] == '\0'Description
TRUEevaluated 2110 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2110
744 {-
745 if (test_unop (argv[pos]))
test_unop (argv[pos])Description
TRUEevaluated 2109 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-2109
746 return (unary_operator ());
executed 2109 times by 1 test: return (unary_operator ());
Executed by:
  • Self test
2109
747 else-
748 test_syntax_error (_("%s: unary operator expected"), argv[pos]);
executed 1 time by 1 test: test_syntax_error ( dcgettext (((void *)0), "%s: unary operator expected" , 5) , argv[pos]);
Executed by:
  • Self test
1
749 }-
750 else-
751 test_syntax_error (_("%s: unary operator expected"), argv[pos]);
executed 2 times by 1 test: test_syntax_error ( dcgettext (((void *)0), "%s: unary operator expected" , 5) , argv[pos]);
Executed by:
  • Self test
2
752-
753 return (0);
never executed: return (0);
0
754}-
755-
756#define ANDOR(s) (s[0] == '-' && (s[1] == 'a' || s[1] == 'o') && s[2] == 0)-
757-
758/* This could be augmented to handle `-t' as equivalent to `-t 1', but-
759 POSIX requires that `-t' be given an argument. */-
760#define ONE_ARG_TEST(s) ((s)[0] != '\0')-
761-
762static int-
763three_arguments ()-
764{-
765 int value;-
766-
767 if (test_binop (argv[pos+1]))
test_binop (argv[pos+1])Description
TRUEevaluated 2211 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 44 times by 1 test
Evaluated by:
  • Self test
44-2211
768 {-
769 value = binary_operator ();-
770 pos = argc;-
771 }
executed 2203 times by 1 test: end of block
Executed by:
  • Self test
2203
772 else if (ANDOR (argv[pos+1]))
argv[pos+1][0] == '-'Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
argv[pos+1][1] == 'a'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
argv[pos+1][1] == 'o'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
argv[pos+1][2] == 0Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-42
773 {-
774 if (argv[pos+1][1] == 'a')
argv[pos+1][1] == 'a'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
7
775 value = ONE_ARG_TEST(argv[pos]) && ONE_ARG_TEST(argv[pos+2]);
executed 7 times by 1 test: value = ((argv[pos])[0] != '\0') && ((argv[pos+2])[0] != '\0');
Executed by:
  • Self test
((argv[pos])[0] != '\0')Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
((argv[pos+2])[0] != '\0')Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-7
776 else-
777 value = ONE_ARG_TEST(argv[pos]) || ONE_ARG_TEST(argv[pos+2]);
executed 7 times by 1 test: value = ((argv[pos])[0] != '\0') || ((argv[pos+2])[0] != '\0');
Executed by:
  • Self test
((argv[pos])[0] != '\0')Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
((argv[pos+2])[0] != '\0')Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-7
778 pos = argc;-
779 }
executed 14 times by 1 test: end of block
Executed by:
  • Self test
14
780 else if (argv[pos][0] == '!' && argv[pos][1] == '\0')
argv[pos][0] == '!'Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == '\0'Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-27
781 {-
782 advance (1);
never executed: beyond ();
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
0-27
783 value = !two_arguments ();-
784 }
executed 27 times by 1 test: end of block
Executed by:
  • Self test
27
785 else if (argv[pos][0] == '(' && argv[pos+2][0] == ')')
argv[pos][0] == '('Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
argv[pos+2][0] == ')'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
786 {-
787 value = ONE_ARG_TEST(argv[pos+1]);-
788 pos = argc;-
789 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
790 else-
791 test_syntax_error (_("%s: binary operator expected"), argv[pos+1]);
executed 1 time by 1 test: test_syntax_error ( dcgettext (((void *)0), "%s: binary operator expected" , 5) , argv[pos+1]);
Executed by:
  • Self test
1
792-
793 return (value);
executed 2246 times by 1 test: return (value);
Executed by:
  • Self test
2246
794}-
795-
796/* This is an implementation of a Posix.2 proposal by David Korn. */-
797static int-
798posixtest ()-
799{-
800 int value;-
801-
802 switch (argc - 1) /* one extra passed in */-
803 {-
804 case 0:
never executed: case 0:
0
805 value = FALSE;-
806 pos = argc;-
807 break;
never executed: break;
0
808-
809 case 1:
executed 4 times by 1 test: case 1:
Executed by:
  • Self test
4
810 value = ONE_ARG_TEST(argv[1]);-
811 pos = argc;-
812 break;
executed 4 times by 1 test: break;
Executed by:
  • Self test
4
813-
814 case 2:
executed 2087 times by 1 test: case 2:
Executed by:
  • Self test
2087
815 value = two_arguments ();-
816 pos = argc;-
817 break;
executed 2084 times by 1 test: break;
Executed by:
  • Self test
2084
818-
819 case 3:
executed 2254 times by 1 test: case 3:
Executed by:
  • Self test
2254
820 value = three_arguments ();-
821 break;
executed 2245 times by 1 test: break;
Executed by:
  • Self test
2245
822-
823 case 4:
executed 5 times by 1 test: case 4:
Executed by:
  • Self test
5
824 if (argv[pos][0] == '!' && argv[pos][1] == '\0')
argv[pos][0] == '!'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-4
825 {-
826 advance (1);
never executed: beyond ();
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
827 value = !three_arguments ();-
828 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
829 }-
830 else if (argv[pos][0] == '(' && argv[pos][1] == '\0' && argv[argc-1][0] == ')' && argv[argc-1][1] == '\0')
argv[pos][0] == '('Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
argv[pos][1] == '\0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
argv[argc-1][0] == ')'Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
argv[argc-1][1] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-2
831 {-
832 advance (1);
never executed: beyond ();
pos >= argcDescription
TRUEnever evaluated
FALSEnever evaluated
0
833 value = two_arguments ();-
834 pos = argc;-
835 break;
never executed: break;
0
836 }-
837 /* FALLTHROUGH */-
838 default:
code before this statement executed 4 times by 1 test: default:
Executed by:
  • Self test
executed 10 times by 1 test: default:
Executed by:
  • Self test
4-10
839 value = expr ();-
840 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
841-
842 return (value);
executed 4342 times by 1 test: return (value);
Executed by:
  • Self test
4342
843}-
844-
845/*-
846 * [:-
847 * '[' expr ']'-
848 * test:-
849 * test expr-
850 */-
851int-
852test_command (margc, margv)-
853 int margc;-
854 char **margv;-
855{-
856 int value;-
857 int code;-
858-
859 USE_VAR(margc);-
860-
861 code = setjmp_nosigs (test_exit_buf);-
862-
863 if (code)
codeDescription
TRUEevaluated 4357 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4357 times by 1 test
Evaluated by:
  • Self test
4357
864 return (test_error_return);
executed 4357 times by 1 test: return (test_error_return);
Executed by:
  • Self test
4357
865-
866 argv = margv;-
867-
868 if (margv[0] && margv[0][0] == '[' && margv[0][1] == '\0')
margv[0]Description
TRUEevaluated 4357 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
margv[0][0] == '['Description
TRUEevaluated 3810 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 547 times by 1 test
Evaluated by:
  • Self test
margv[0][1] == '\0'Description
TRUEevaluated 3810 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-4357
869 {-
870 --margc;-
871-
872 if (margv[margc] && (margv[margc][0] != ']' || margv[margc][1]))
margv[margc]Description
TRUEevaluated 3810 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
margv[margc][0] != ']'Description
TRUEnever evaluated
FALSEevaluated 3810 times by 1 test
Evaluated by:
  • Self test
margv[margc][1]Description
TRUEnever evaluated
FALSEevaluated 3810 times by 1 test
Evaluated by:
  • Self test
0-3810
873 test_syntax_error (_("missing `]'"), (char *)NULL);
never executed: test_syntax_error ( dcgettext (((void *)0), "missing `]'" , 5) , (char *) ((void *)0) );
0
874-
875 if (margc < 2)
margc < 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3809 times by 1 test
Evaluated by:
  • Self test
1-3809
876 test_exit (SHELL_BOOLEAN (FALSE));
never executed: end of block
0
877 }
executed 3809 times by 1 test: end of block
Executed by:
  • Self test
3809
878-
879 argc = margc;-
880 pos = 1;-
881-
882 if (pos >= argc)
pos >= argcDescription
TRUEnever evaluated
FALSEevaluated 4356 times by 1 test
Evaluated by:
  • Self test
0-4356
883 test_exit (SHELL_BOOLEAN (FALSE));
never executed: end of block
0
884-
885 noeval = 0;-
886 value = posixtest ();-
887-
888 if (pos != argc)
pos != argcDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4340 times by 1 test
Evaluated by:
  • Self test
2-4340
889 test_syntax_error (_("too many arguments"), (char *)NULL);
executed 2 times by 1 test: test_syntax_error ( dcgettext (((void *)0), "too many arguments" , 5) , (char *) ((void *)0) );
Executed by:
  • Self test
2
890-
891 test_exit (SHELL_BOOLEAN (value));-
892}
never executed: end of block
0
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2