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
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.
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
2 Copyright (C) 1990, 1998-1999, 2001-2014 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
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 enum backup_type
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 no_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 simple_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 numbered_existing_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 numbered_backups
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
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 static const char *const backup_args[] =
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 {
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 "no", "none", "off",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 "simple", "never", "single",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 "existing", "nil", "numbered-existing",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 "numbered", "t", "newstyle",
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 NULL
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 enum backup_type backup_vals[] =
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_backups, no_backups, no_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 simple_backups, simple_backups, simple_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups,
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 numbered_backups, numbered_backups, numbered_backups
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
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 int
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 main (int argc, char *argv[])
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 set_program_name (argv[0]);
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 /* Not found. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1);
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 /* Exact match. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7);
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 /* Too long. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 /* Abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3);
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 /* Exact match and abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 /* Ambiguous abbreviated. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 /* Ambiguous abbreviated, but same value. */
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3);
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 return 0;
c08f9990bf58 Tests for module 'argmatch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 }