Mercurial > hg > octave-shane > gnulib-hg
annotate tests/test-argmatch.c @ 17622:71e733c62cee
savedir: add sorting arg to savedir, streamsavedir; remove fdsavedir
Patch based on an idea by Dick Streefland in
<https://savannah.gnu.org/patch/?7892>.
* NEWS: Document this.
* lib/savedir.c (NAME_SIZE_DEFAULT): Remove.
(direntry_t, comparison_function): New types.
(direntry_cmp_name): New function.
(direntry_cmp_inode) [D_INO_IN_DIRENT]: New function.
(streamsavedir, savedir): New arg OPTION.
(streamsavedir): Simplify memory allocation.
(fdsavedir): Remove.
* lib/savedir.h (enum savedir_option): New type.
(streamsavedir, savedir): New arg OPTION.
(fdsavedir): Remove.
author | Sergey Poznyakoff <gray@gnu.org.ua> |
---|---|
date | Thu, 13 Feb 2014 22:01:39 +0200 |
parents | 344018b6e5d7 |
children |
rev | line source |
---|---|
8325 | 1 /* Test of exact or abbreviated match search. |
17587 | 2 Copyright (C) 1990, 1998-1999, 2001-2014 Free Software Foundation, Inc. |
8325 | 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 | 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 | 8 |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
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 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007, based on test code | |
18 by David MacKenzie <djm@gnu.ai.mit.edu>. */ | |
19 | |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
8754
diff
changeset
|
20 #include <config.h> |
8325 | 21 |
22 #include "argmatch.h" | |
23 | |
24 #include <stdlib.h> | |
25 | |
26 #include "progname.h" | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
27 #include "macros.h" |
8325 | 28 |
9476
b335ae52450d
Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents:
9468
diff
changeset
|
29 /* 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
|
30 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
|
31 #ifdef ARGMATCH_DIE_DECL |
14384
588ed4cdea87
Fix misindentation of preprocessor directives.
Bruno Haible <bruno@clisp.org>
parents:
14351
diff
changeset
|
32 |
15397
7d9ccb480220
argmatch-tests: use _Noreturn
Paul Eggert <eggert@cs.ucla.edu>
parents:
14384
diff
changeset
|
33 _Noreturn ARGMATCH_DIE_DECL; |
9476
b335ae52450d
Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents:
9468
diff
changeset
|
34 ARGMATCH_DIE_DECL { exit (1); } |
14384
588ed4cdea87
Fix misindentation of preprocessor directives.
Bruno Haible <bruno@clisp.org>
parents:
14351
diff
changeset
|
35 |
9476
b335ae52450d
Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents:
9468
diff
changeset
|
36 #endif |
b335ae52450d
Define a sometimes-link-required function using ARGMATCH_DIE_DECL.
Jim Meyering <meyering@redhat.com>
parents:
9468
diff
changeset
|
37 |
8325 | 38 enum backup_type |
39 { | |
40 no_backups, | |
41 simple_backups, | |
42 numbered_existing_backups, | |
43 numbered_backups | |
44 }; | |
45 | |
46 static const char *const backup_args[] = | |
47 { | |
48 "no", "none", "off", | |
49 "simple", "never", "single", | |
50 "existing", "nil", "numbered-existing", | |
51 "numbered", "t", "newstyle", | |
52 NULL | |
53 }; | |
54 | |
55 static const enum backup_type backup_vals[] = | |
56 { | |
57 no_backups, no_backups, no_backups, | |
58 simple_backups, simple_backups, simple_backups, | |
59 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups, | |
60 numbered_backups, numbered_backups, numbered_backups | |
61 }; | |
62 | |
63 int | |
64 main (int argc, char *argv[]) | |
65 { | |
66 set_program_name (argv[0]); | |
67 | |
68 /* Not found. */ | |
69 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1); | |
70 | |
71 /* Exact match. */ | |
72 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1); | |
73 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7); | |
74 | |
75 /* Too long. */ | |
76 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1); | |
77 | |
78 /* Abbreviated. */ | |
79 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3); | |
80 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3); | |
81 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3); | |
82 | |
83 /* Exact match and abbreviated. */ | |
84 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9); | |
85 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2); | |
86 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2); | |
87 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2); | |
88 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2); | |
89 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2); | |
90 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2); | |
91 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2); | |
92 | |
93 /* Ambiguous abbreviated. */ | |
94 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2); | |
95 | |
96 /* Ambiguous abbreviated, but same value. */ | |
97 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3); | |
98 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3); | |
99 | |
100 return 0; | |
101 } |