]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/runptests.c
Use --enable-obsolete in build-many-glibcs.py for nios2-linux-gnu
[thirdparty/glibc.git] / posix / runptests.c
CommitLineData
92040cbc 1/* POSIX regex testsuite from IEEE 2003.2.
dff8da6b 2 Copyright (C) 1998-2024 Free Software Foundation, Inc.
92040cbc 3 This file is part of the GNU C Library.
92040cbc
UD
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
92040cbc
UD
9
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
41bdb6e2 13 Lesser General Public License for more details.
92040cbc 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
92040cbc
UD
18
19#include <sys/types.h>
20#include <regex.h>
21#include <stdio.h>
ba9234d9 22#include <string.h>
92040cbc
UD
23
24/* Data structure to describe the tests. */
25struct test
26{
27 int start;
28 int end;
29 const char *reg;
30 const char *str;
31 int options;
32} tests[] =
33{
34#include "ptestcases.h"
35};
36
37
38int
39main (int argc, char *argv[])
40{
41 size_t cnt;
42 int errors = 0;
43
44 for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
45 if (tests[cnt].str == NULL)
46 {
47 printf ("\n%s\n%.*s\n", tests[cnt].reg,
48 (int) strlen (tests[cnt].reg),
49 "-----------------------------------------------------");
50 }
813ec65a
UD
51 else if (tests[cnt].reg == NULL)
52 printf ("!!! %s\n", tests[cnt].str);
92040cbc
UD
53 else
54 {
55 regex_t re;
56 regmatch_t match[20];
57 int err;
58
59 printf ("regexp: \"%s\", string: \"%s\" -> ", tests[cnt].reg,
60 tests[cnt].str);
61
62 /* Compile the expression. */
63 err = regcomp (&re, tests[cnt].reg, tests[cnt].options);
64 if (err != 0)
65 {
648c1337
UD
66 if (tests[cnt].start == -2)
67 puts ("compiling failed, OK");
92040cbc
UD
68 else
69 {
70 char buf[100];
71 regerror (err, &re, buf, sizeof (buf));
72 printf ("FAIL: %s\n", buf);
73 ++errors;
74 }
75
76 continue;
77 }
648c1337
UD
78 else if (tests[cnt].start == -2)
79 {
7f0d9e61 80 puts ("compiling succeeds, FAIL");
648c1337
UD
81 errors++;
82 continue;
83 }
92040cbc
UD
84
85 /* Run the actual test. */
86 err = regexec (&re, tests[cnt].str, 20, match, 0);
87
88 if (err != 0)
89 {
90 if (tests[cnt].start == -1)
91 puts ("no match, OK");
92 else
93 {
94 puts ("no match, FAIL");
95 ++errors;
96 }
97 }
98 else
99 {
100 if (match[0].rm_so == 0 && tests[cnt].start == 0
101 && match[0].rm_eo == 0 && tests[cnt].end == 0)
102 puts ("match, OK");
103 else if (match[0].rm_so + 1 == tests[cnt].start
104 && match[0].rm_eo == tests[cnt].end)
105 puts ("match, OK");
106 else
107 {
108 printf ("wrong match (%d to %d): FAIL\n",
109 match[0].rm_so, match[0].rm_eo);
110 ++errors;
111 }
112 }
113
114 /* Free all resources. */
115 regfree (&re);
116 }
117
de477abc 118 printf ("\n%zu tests, %d errors\n", cnt, errors);
92040cbc 119
97fd3a30 120 return errors != 0;
92040cbc 121}