1 /* Testing of long double conversions in argp.h functions.
2 Copyright (C) 2018-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <support/capture_subprocess.h>
23 #include <support/check.h>
25 static const struct argp_option
28 { "error", 'e', "format", OPTION_ARG_OPTIONAL
,
29 "Run argp_error function with a format string", 0 },
30 { "failure", 'f', "format", OPTION_ARG_OPTIONAL
,
31 "Run argp_failure function with a format string", 0 },
32 { NULL
, 0, NULL
, 0, NULL
}
36 parser (int key
, char *arg
, struct argp_state
*state
)
41 argp_error (state
, "%Lf%f%Lf%f", (long double) -1, (double) -2,
42 (long double) -3, (double) -4);
45 argp_failure (state
, 0, 0, "%Lf%f%Lf%f", (long double) -1,
46 (double) -2, (long double) -3, (double) -4);
49 return ARGP_ERR_UNKNOWN
;
61 char *argv
[3] = { (char *) "test-argp", NULL
, NULL
};
67 argp_parse (&argp
, argc
, argv
, 0, &remaining
, NULL
);
71 do_one_test (const char *expected
)
73 struct support_capture_subprocess result
;
74 result
= support_capture_subprocess ((void *) &do_test_call
, NULL
);
76 TEST_COMPARE_STRING (result
.err
.buffer
, expected
);
84 const char *param_error
= "--error";
85 const char *expected_error
=
86 "test-argp: -1.000000-2.000000-3.000000-4.000000\n"
87 "Try `test-argp --help' or `test-argp --usage' for more information.\n";
89 const char *param_failure
= "--failure";
90 const char *expected_failure
=
91 "test-argp: -1.000000-2.000000-3.000000-4.000000\n";
93 argv
[1] = (char *) param_error
;
94 do_one_test (expected_error
);
96 argv
[1] = (char *) param_failure
;
97 do_one_test (expected_failure
);
102 #include <support/test-driver.c>