annotate tests/test-argmatch.c @ 12391:5d8d7c606ce6

test-dup2: enhance test Ensure that dup2(cloexec_fd, target) returns an inheritable fd. * modules/dup2-tests (Depends-on): Add cloexec. * tests/test-dup2.c (main): Enhance test. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Sat, 05 Dec 2009 06:19:01 -0700
parents 0be6f1ab456d
children e8d2c6fc33ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of exact or abbreviated match search.
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9476
diff changeset
2 Copyright (C) 1990, 1998-1999, 2001-2008 Free Software Foundation, Inc.
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
4 This program is free software: you can redistribute it and/or modify
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
7 (at your option) any later version.
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007, based on test code
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 by David MacKenzie <djm@gnu.ai.mit.edu>. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8754
diff changeset
20 #include <config.h>
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include "argmatch.h"
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
24 #include <stdio.h>
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdlib.h>
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "progname.h"
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
29 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
30 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
31 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
32 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
33 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9476
diff changeset
35 fflush (stderr); \
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
36 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
37 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
38 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
39 while (0)
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
9476
b335ae52450d Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents: 9468
diff changeset
41 /* Some packages define ARGMATCH_DIE and ARGMATCH_DIE_DECL in <config.h>, and
b335ae52450d Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents: 9468
diff changeset
42 thus must link with a definition of that function. Provide it here. */
b335ae52450d Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents: 9468
diff changeset
43 #ifdef ARGMATCH_DIE_DECL
b335ae52450d Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents: 9468
diff changeset
44 ARGMATCH_DIE_DECL { exit (1); }
b335ae52450d Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents: 9468
diff changeset
45 #endif
b335ae52450d Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents: 9468
diff changeset
46
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 enum backup_type
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 no_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 simple_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 numbered_existing_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 numbered_backups
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 };
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 static const char *const backup_args[] =
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 "no", "none", "off",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 "simple", "never", "single",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 "existing", "nil", "numbered-existing",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 "numbered", "t", "newstyle",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 NULL
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 };
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 static const enum backup_type backup_vals[] =
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 no_backups, no_backups, no_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 simple_backups, simple_backups, simple_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 numbered_backups, numbered_backups, numbered_backups
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 };
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 int
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 main (int argc, char *argv[])
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 set_program_name (argv[0]);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* Not found. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 /* Exact match. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* Too long. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 /* Abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 /* Exact match and abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 /* Ambiguous abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 /* Ambiguous abbreviated, but same value. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 return 0;
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 }