Commit 8905bb48 8905bb4805cf4ebcff9ba3d99073b81c906399f6 by Sergey Poznyakoff

Fix mu_parseopt. Add testsuite for it.

* include/mailutils/opt.h (mu_parseopt) <po_permuted>: New member.
* libmailutils/opt/help.c (print_option): Fix display of optional
arguments.
* libmailutils/opt/opt.c (next_opt,parse): Fix start-of-arguments
index.
Move permutation into a separate function.
* libmailutils/opt/progname.c (mu_set_progname): Remove eventual lt-
prefix.
* libmailutils/tests/Makefile.am: Add new tests.
* libmailutils/tests/parseopt.c: Use environment to control
mu_parseopt flags.
* libmailutils/tests/testsuite.at: Add new tests.
* libmailutils/tests/strtoc.at: Update.

* libmailutils/tests/parseopt00.at: New file.
* libmailutils/tests/parseopt01.at: New file.
* libmailutils/tests/parseopt02.at: New file.
* libmailutils/tests/parseopt03.at: New file.
* libmailutils/tests/parseopt04.at: New file.
* libmailutils/tests/parseopt05.at: New file.
* libmailutils/tests/parseopt06.at: New file.
* libmailutils/tests/parseopt07.at: New file.
* libmailutils/tests/parseopt08.at: New file.
* libmailutils/tests/parseopt09.at: New file.
* libmailutils/tests/parseopt10.at: New file.
* libmailutils/tests/parseopt11.at: New file.
* libmailutils/tests/parseopt12.at: New file.
* libmailutils/tests/parseopt13.at: New file.
* libmailutils/tests/parseopt14.at: New file.
* libmailutils/tests/parseopt15.at: New file.
* libmailutils/tests/parseopt16.at: New file.
* libmailutils/tests/parseopt17.at: New file.
* libmailutils/tests/parseopt18.at: New file.
* libmailutils/tests/parseopt19.at: New file.
* libmailutils/tests/parseopt20.at: New file.
* libmailutils/tests/parseopt21.at: New file.
* libmailutils/tests/parseopt22.at: New file.
1 parent aac8beae
......@@ -149,6 +149,7 @@ struct mu_parseopt
int po_arg_start;
int po_arg_count;
unsigned po_permuted:1; /* Whether the arguments were permuted */
};
int mu_parseopt (struct mu_parseopt *p,
......
......@@ -132,6 +132,14 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
if (opt->opt_arg)
{
*argsused = 1;
if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
{
if (delim == '=')
w += printf ("[=%s]", gettext (opt->opt_arg));
else
w += printf ("[%s]", gettext (opt->opt_arg));
}
else
w += printf ("%c%s", delim, gettext (opt->opt_arg));
}
if (w >= DESCRCOLUMN)
......
......@@ -228,25 +228,9 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
return NULL;
}
/* Consume next option from PO. On success, update PO members as
described below and return 0. On end of options, return 1.
If the consumed option is a short option, then
po_chr keeps its option character, and
po_cur points to the next option character to be processed
Otherwise, if the consumed option is a long one, then
po_chr is 0
po_cur points to the first character after --
*/
static int
next_opt (struct mu_parseopt *po)
static void
permute (struct mu_parseopt *po)
{
if (!*po->po_cur)
{
if (!(po->po_flags & MU_PARSEOPT_IN_ORDER) && po->po_arg_count)
{
/* Array to save arguments in */
......@@ -274,10 +258,29 @@ next_opt (struct mu_parseopt *po)
/* Fix up start index */
po->po_arg_start += n;
po->po_permuted = 1;
}
}
if (po->po_ind == po->po_argc)
return 1;
/* Consume next option from PO. On success, update PO members as
described below and return 0. On end of options, return 1.
If the consumed option is a short option, then
po_chr keeps its option character, and
po_cur points to the next option character to be processed
Otherwise, if the consumed option is a long one, then
po_chr is 0
po_cur points to the first character after --
*/
static int
next_opt (struct mu_parseopt *po)
{
if (!*po->po_cur)
{
permute (po);
while (1)
{
......@@ -288,6 +291,8 @@ next_opt (struct mu_parseopt *po)
break;
if (!(po->po_flags & MU_PARSEOPT_IN_ORDER))
{
if (!po->po_permuted)
po->po_arg_start = po->po_ind - 1;
po->po_arg_count++;
continue;
}
......@@ -298,8 +303,12 @@ next_opt (struct mu_parseopt *po)
if (*++po->po_cur == '-')
{
if (*++po->po_cur == 0)
{
/* End of options */
permute (po);
++po->po_ind;
return 1;
}
/* It's a long option */
po->po_chr = 0;
......@@ -331,9 +340,12 @@ parse (struct mu_parseopt *po)
{
char *p = strrchr (po->po_argv[0], '/');
if (p)
po->po_prog_name = p + 1;
p++;
else
po->po_prog_name = (char*) po->po_argv[0];
p = (char*) po->po_argv[0];
if (strlen (p) > 3 && memcmp (p, "lt-", 3) == 0)
p += 3;
po->po_prog_name = p;
}
}
else if (!(po->po_flags & MU_PARSEOPT_PROG_NAME))
......@@ -341,6 +353,7 @@ parse (struct mu_parseopt *po)
po->po_arg_start = po->po_ind;
po->po_arg_count = 0;
po->po_permuted = 0;
po->po_cur = "";
......@@ -433,8 +446,8 @@ parse (struct mu_parseopt *po)
}
}
if (po->po_arg_count)
po->po_ind = po->po_arg_start;
if (!po->po_permuted)
po->po_arg_start = po->po_ind - 1 - po->po_arg_count;
return 0;
}
......
......@@ -38,6 +38,8 @@ mu_set_progname (char const *arg)
++p;
else
p = (char*) arg;
if (strlen (p) > 3 && memcmp (p, "lt-", 3) == 0)
p += 3;
free (mu_progname);
mu_progname = mu_strdup (p);
}
......
......@@ -104,6 +104,29 @@ TESTSUITE_AT = \
modmesg03.at\
modtofsaf.at\
msgset.at\
parseopt00.at\
parseopt01.at\
parseopt02.at\
parseopt03.at\
parseopt04.at\
parseopt05.at\
parseopt06.at\
parseopt07.at\
parseopt08.at\
parseopt09.at\
parseopt10.at\
parseopt11.at\
parseopt12.at\
parseopt13.at\
parseopt14.at\
parseopt15.at\
parseopt16.at\
parseopt17.at\
parseopt18.at\
parseopt19.at\
parseopt20.at\
parseopt21.at\
parseopt22.at\
prop.at\
scantime.at\
strftime.at\
......
......@@ -21,8 +21,8 @@
#include <mailutils/opt.h>
char *file_name;
char *find_value;
char *opt_value = "initial";
char *find_value;
int jobs = 0;
int x_option;
int a_option;
......@@ -34,9 +34,6 @@ struct mu_option group_a[] = {
"set file name",
mu_c_string, &file_name
},
{ "find", 'F', "VALUE", MU_OPTION_DEFAULT,
"find VALUE",
mu_c_string, &find_value },
{ "optional", 'o', "FILE", MU_OPTION_ARG_OPTIONAL,
"optional argument",
mu_c_string, &opt_value },
......@@ -55,6 +52,9 @@ struct mu_option group_b[] = {
"another option",
mu_c_incr, &d_option },
{ "verbose", 'v', NULL, MU_OPTION_ALIAS },
{ "find", 'F', "VALUE", MU_OPTION_DEFAULT,
"find VALUE",
mu_c_string, &find_value },
{ "jobs", 'j', "N", MU_OPTION_DEFAULT,
"sets numeric value",
mu_c_int, &jobs },
......@@ -71,23 +71,40 @@ main (int argc, char *argv[])
struct mu_parseopt po;
int rc;
int i;
int flags = MU_PARSEOPT_DEFAULT;
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
rc = mu_parseopt (&po, argc, argv, optv, MU_PARSEOPT_DEFAULT);
if (getenv ("MU_PARSEOPT_DEFAULT"))
flags = MU_PARSEOPT_DEFAULT;
else
{
if (getenv ("MU_PARSEOPT_IN_ORDER"))
flags |= MU_PARSEOPT_IN_ORDER;
if (getenv ("MU_PARSEOPT_IGNORE_ERRORS"))
flags |= MU_PARSEOPT_IGNORE_ERRORS;
if (getenv ("MU_PARSEOPT_IN_ORDER"))
flags |= MU_PARSEOPT_IN_ORDER;
if (getenv ("MU_PARSEOPT_NO_ERREXIT"))
flags |= MU_PARSEOPT_NO_ERREXIT;
if (getenv ("MU_PARSEOPT_NO_STDOPT"))
flags |= MU_PARSEOPT_NO_STDOPT;
}
rc = mu_parseopt (&po, argc, argv, optv, flags);
printf ("rc=%d\n", rc);
mu_parseopt_apply (&po);
argc -= po.po_ind;
argv += po.po_ind;
argc -= po.po_arg_start;
argv += po.po_arg_start;
mu_parseopt_free (&po);
printf ("file_name=%s\n", S(file_name));
printf ("find_value=%s\n", S(find_value));
printf ("opt_value=%s\n", S(opt_value));
printf ("x_option=%d\n", x_option);
printf ("a_option=%d\n", a_option);
printf ("find_value=%s\n", S(find_value));
printf ("d_option=%d\n", d_option);
printf ("jobs=%d\n", jobs);
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([empty command line])
AT_KEYWORDS([parseopt parseopt00])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt
],
[0],
[rc=0
file_name=(null)
opt_value=initial
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([command line without options])
AT_KEYWORDS([parseopt parseopt_noopt parseopt01])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt command line arguments
],
[0],
[rc=0
file_name=(null)
opt_value=initial
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([short options])
AT_KEYWORDS([parseopt parseopt_short parseopt02])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt -f file -x -a -d command line arguments
],
[0],
[rc=0
file_name=file
opt_value=initial
x_option=1
a_option=1
find_value=(null)
d_option=1
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([short option with argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_arg parseopt03])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt -ffile -x -a -d command line arguments
],
[0],
[rc=0
file_name=file
opt_value=initial
x_option=1
a_option=1
find_value=(null)
d_option=1
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([short option with optional argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_arg parseopt04])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt -ofile command line arguments
],
[0],
[rc=0
file_name=(null)
opt_value=file
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([short option without optional argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_noarg parseopt05])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt -o command line arguments
],
[0],
[rc=0
file_name=(null)
opt_value=(null)
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([incremental short option])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_incr parseopt06])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt -d -d command line arguments
],
[0],
[rc=0
file_name=(null)
opt_value=initial
x_option=0
a_option=0
find_value=(null)
d_option=2
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([short option clustering])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_cluster parseopt07])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt -xffile -dado10 command line arguments
],
[0],
[rc=0
file_name=file
opt_value=10
x_option=1
a_option=1
find_value=(null)
d_option=2
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([long options])
AT_KEYWORDS([parseopt parseopt_long parseopt08])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --file=file --all command line arguments
],
[0],
[rc=0
file_name=file
opt_value=initial
x_option=0
a_option=1
find_value=(null)
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([long option with argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_arg parseopt09])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --file file command line arguments
],
[0],
[rc=0
file_name=file
opt_value=initial
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([long option with optional argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_arg parseopt10])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --optional=file command line arguments
],
[0],
[rc=0
file_name=(null)
opt_value=file
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([long option without optional argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_noarg parseopt11])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --optional command line arguments
],
[0],
[rc=0
file_name=(null)
opt_value=(null)
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([incremental long option])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_incr parseopt12])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --debug --debug command line arguments
],
[0],
[rc=0
file_name=(null)
opt_value=initial
x_option=0
a_option=0
find_value=(null)
d_option=2
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([abbreviated long options])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt13])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --fil=file --fin=Word command line arguments
],
[0],
[rc=0
file_name=file
opt_value=initial
x_option=0
a_option=0
find_value=Word
d_option=0
jobs=0
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([ambiguous abbreviated long options])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt_long_ambig parseopt14])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --fi=file --fi=Word command line arguments
],
[1],
[],
[parseopt: option '--fi' is ambiguous; possibilities:
--file
--find
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([mixed long and short options])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt15.at])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
parseopt --file=filename -o -xa --find word -j10 command line arguments
],
[0],
[rc=0
file_name=filename
opt_value=(null)
x_option=1
a_option=1
find_value=word
d_option=0
jobs=10
argv:
0: command
1: line
2: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([option aliases])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt16.at])
AT_CHECK([
parseopt -vvv
],
[0],
[rc=0
file_name=(null)
opt_value=initial
x_option=0
a_option=0
find_value=(null)
d_option=3
jobs=0
argv:
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([argument permutation])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt17.at])
AT_CHECK([
parseopt more --file=file arguments follow -x -o options
],
[0],
[rc=0
file_name=file
opt_value=(null)
x_option=1
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: more
1: arguments
2: follow
3: options
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([double-dash])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
AT_CHECK([
parseopt -x --file=foobar -- -a --optional arg
],
[0],
[rc=0
file_name=foobar
opt_value=initial
x_option=1
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: -a
1: --optional
2: arg
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([double-dash with permutation])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt19.at])
AT_CHECK([
parseopt -x more --file=foobar -- -a --optional arg
],
[0],
[rc=0
file_name=foobar
opt_value=initial
x_option=1
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: more
1: -a
2: --optional
3: arg
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([short option without required argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_noarg parseopt20])
AT_CHECK([
parseopt -f
],
[1],
[],
[parseopt: option '-f' requires an argument
])
AT_CLEANUP
\ No newline at end of file
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([long option without required argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_noarg parseopt21])
AT_CHECK([
parseopt --file
],
[1],
[],
[parseopt: option '--file' requires an argument
])
AT_CLEANUP
\ No newline at end of file
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([unrecognized option])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22])
AT_CHECK([
parseopt -X
],
[1],
[],
[parseopt: unrecognized option '-X'
])
AT_CLEANUP
\ No newline at end of file
......@@ -15,7 +15,5 @@
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([mu_str_to_c])
AT_CHECK([strtoc])
AT_CLEANUP
......
......@@ -56,6 +56,31 @@ AT_INIT
AT_BANNER([Conversions])
m4_include([strtoc.at])
AT_BANNER([Command line parser])
m4_include([parseopt00.at])
m4_include([parseopt01.at])
m4_include([parseopt02.at])
m4_include([parseopt03.at])
m4_include([parseopt04.at])
m4_include([parseopt05.at])
m4_include([parseopt06.at])
m4_include([parseopt07.at])
m4_include([parseopt08.at])
m4_include([parseopt09.at])
m4_include([parseopt10.at])
m4_include([parseopt11.at])
m4_include([parseopt12.at])
m4_include([parseopt13.at])
m4_include([parseopt14.at])
m4_include([parseopt15.at])
m4_include([parseopt16.at])
m4_include([parseopt17.at])
m4_include([parseopt18.at])
m4_include([parseopt19.at])
m4_include([parseopt20.at])
m4_include([parseopt21.at])
m4_include([parseopt22.at])
AT_BANNER([Standard streams])
m4_include([strin.at])
m4_include([strout.at])
......