annotate tests/test-argmatch.c @ 8754:1f57552cdb11

Better ASSERT macro.
author Bruno Haible <bruno@clisp.org>
date Sun, 29 Apr 2007 09:15:13 +0000
parents c08f9990bf58
children 633babea5f62
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.
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 1990, 1998-1999, 2001-2007 Free Software Foundation, Inc.
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
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
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
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
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* 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
19 by David MacKenzie <djm@gnu.ai.mit.edu>. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #ifdef HAVE_CONFIG_H
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 # include <config.h>
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #endif
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include "argmatch.h"
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
27 #include <stdio.h>
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdlib.h>
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include "progname.h"
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
32 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
33 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
34 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
35 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
36 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
37 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
38 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
39 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
40 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8325
diff changeset
41 while (0)
8325
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 enum backup_type
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 no_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 simple_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 numbered_existing_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 numbered_backups
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 };
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 static const char *const backup_args[] =
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 "no", "none", "off",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 "simple", "never", "single",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 "existing", "nil", "numbered-existing",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 "numbered", "t", "newstyle",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 NULL
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 };
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 static const enum backup_type backup_vals[] =
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 no_backups, no_backups, no_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 simple_backups, simple_backups, simple_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 numbered_backups, numbered_backups, numbered_backups
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 };
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 int
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 main (int argc, char *argv[])
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 set_program_name (argv[0]);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 /* Not found. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 /* Exact match. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7);
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 /* Too long. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 /* Abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 /* Exact match and abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 /* Ambiguous abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 /* Ambiguous abbreviated, but same value. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3);
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 return 0;
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 }
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107