[1/3] posix: add (failing) test for REG_STARTEND
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
Commit Message
This test passes on NetBSD, the illumos gate, and musl
with https://www.openwall.com/lists/musl/2023/04/20/2;
it's nothing revolutionary and the behaviour it tests
is largely guaranteed by the 4.4BSD-Lite manual;
nevertheless, it currently fails with
tst-reg-startend.c: ^a: a^@c: no match$
tst-reg-startend.c: ^a: a^@c: wanted {1, 2}, got {1, 4}$
tst-reg-startend.c: ^a: abc: no match$
tst-reg-startend.c: ^a: abc: wanted {1, 2}, got {1, 4}$
tst-reg-startend.c: ^a.c$: a^@c: no match$
tst-reg-startend.c: ^a.c$: abc: no match$
tst-reg-startend.c: ^a.*c$: a^@c: no match$
tst-reg-startend.c: ^a.*c$: abc: no match$
tst-reg-startend.c: ^a[^c]c$: a^@c: no match$
tst-reg-startend.c: ^a[^c]c$: abc: no match$
tst-reg-startend.c: ^a..: a^@c: no match$
tst-reg-startend.c: ^a..: abc: no match$
tst-reg-startend.c: ..c: a^@c: no match$
The test may also be compiled stand-alone (-DSTANDALONE)
and on all platforms that have the interface
(hence the macro to initialise regmatch_ts,
which start with pointer fields on the illumos gate),
for ease of testing and inclusion in other test suites.
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
Please keep me in CC, as I'm not subscribed.
posix/Makefile | 1 +
posix/tst-reg-startend.c | 124 +++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+)
create mode 100644 posix/tst-reg-startend.c
Comments
tst-reg-startend.c:75:27: error: stray ‘\304’ in program
static const char *const a��_data[2] = {"_aaćdef", "_aćdef"};
^
tst-reg-startend.c:75:28: error: stray ‘\207’ in program
static const char *const a��_data[2] = {"_aaćdef", "_aćdef"};
^
tst-reg-startend.c:75:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_data’
static const char *const ać_data[2] = {"_aaćdef", "_aćdef"};
^~~~~
tst-reg-startend.c:76:20: error: stray ‘\304’ in program
static const bool a��_exp[] = {false, true};
^
tst-reg-startend.c:76:21: error: stray ‘\207’ in program
static const bool a��_exp[] = {false, true};
^
tst-reg-startend.c:76:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_exp’
static const bool ać_exp[] = {false, true};
^~~~
tst-reg-startend.c:79:6: error: stray ‘\304’ in program
testa�� (void)
^
tst-reg-startend.c:79:7: error: stray ‘\207’ in program
testa�� (void)
^
tst-reg-startend.c: In function ‘testa’:
tst-reg-startend.c:89:27: error: stray ‘\304’ in program
if (regexec (&rgx, a��_data[i], 1, &match, REG_STARTEND) == ać_exp[i])
^
tst-reg-startend.c:89:28: error: stray ‘\207’ in program
if (regexec (&rgx, a��_data[i], 1, &match, REG_STARTEND) == ać_exp[i])
^
tst-reg-startend.c:89:26: error: ‘a’ undeclared (first use in this function)
if (regexec (&rgx, ać_data[i], 1, &match, REG_STARTEND) == ać_exp[i])
^
tst-reg-startend.c:89:26: note: each undeclared identifier is reported only once for each function it appears in
tst-reg-startend.c:89:29: error: expected ‘)’ before ‘_data’
if (regexec (&rgx, ać_data[i], 1, &match, REG_STARTEND) == ać_exp[i])
^~~~~
tst-reg-startend.c:89:11: error: too few arguments to function ‘regexec’
if (regexec (&rgx, ać_data[i], 1, &match, REG_STARTEND) == ać_exp[i])
^~~~~~~
In file included from ../include/regex.h:2:0,
from tst-reg-startend.c:15:
../posix/regex.h:679:12: note: declared here
extern int regexec (const regex_t *_Restrict_ __preg,
^~~~~~~
tst-reg-startend.c:89:68: error: stray ‘\304’ in program
if (regexec (&rgx, ać_data[i], 1, &match, REG_STARTEND) == a��_exp[i])
^
tst-reg-startend.c:89:69: error: stray ‘\207’ in program
if (regexec (&rgx, ać_data[i], 1, &match, REG_STARTEND) == a��_exp[i])
^
tst-reg-startend.c:89:70: error: expected ‘)’ before ‘_exp’
if (regexec (&rgx, ać_data[i], 1, &match, REG_STARTEND) == ać_exp[i])
^~~~
tst-reg-startend.c:90:18: error: stray ‘\304’ in program
BASEERR(a��_data), fprintf (stdout, ": %s match\n",
^
tst-reg-startend.c:48:13: note: in definition of macro ‘BASEERR’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^~~~
tst-reg-startend.c:90:19: error: stray ‘\207’ in program
BASEERR(a��_data), fprintf (stdout, ": %s match\n",
^
tst-reg-startend.c:48:13: note: in definition of macro ‘BASEERR’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^~~~
tst-reg-startend.c:90:20: error: expected ‘)’ before ‘_data’
BASEERR(ać_data), fprintf (stdout, ": %s match\n",
^
tst-reg-startend.c:48:13: note: in definition of macro ‘BASEERR’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^~~~
tst-reg-startend.c:48:5: error: too few arguments to function ‘fwrite’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^
tst-reg-startend.c:90:9: note: in expansion of macro ‘BASEERR’
BASEERR(ać_data), fprintf (stdout, ": %s match\n",
^~~~~~~
In file included from ../include/stdio.h:14:0,
from tst-reg-startend.c:16:
../libio/stdio.h:739:15: note: declared here
extern size_t fwrite (const void *__restrict __ptr, size_t __size,
^~~~~~
tst-reg-startend.c:91:37: error: stray ‘\304’ in program
a��_exp[i] ? "no" : "yes");
^
tst-reg-startend.c:91:38: error: stray ‘\207’ in program
a��_exp[i] ? "no" : "yes");
^
tst-reg-startend.c:91:39: error: expected ‘)’ before ‘_exp’
ać_exp[i] ? "no" : "yes");
^~~~
tst-reg-startend.c:90:26: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
BASEERR(ać_data), fprintf (stdout, ": %s match\n",
^
tst-reg-startend.c:94:18: error: stray ‘\304’ in program
BASEERR(a��_data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
^
tst-reg-startend.c:48:13: note: in definition of macro ‘BASEERR’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^~~~
tst-reg-startend.c:94:19: error: stray ‘\207’ in program
BASEERR(a��_data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
^
tst-reg-startend.c:48:13: note: in definition of macro ‘BASEERR’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^~~~
tst-reg-startend.c:94:20: error: expected ‘)’ before ‘_data’
BASEERR(ać_data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
^
tst-reg-startend.c:48:13: note: in definition of macro ‘BASEERR’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^~~~
tst-reg-startend.c:48:5: error: too few arguments to function ‘fwrite’
fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
^
tst-reg-startend.c:94:9: note: in expansion of macro ‘BASEERR’
BASEERR(ać_data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
^~~~~~~
In file included from ../include/stdio.h:14:0,
from tst-reg-startend.c:16:
../libio/stdio.h:739:15: note: declared here
extern size_t fwrite (const void *__restrict __ptr, size_t __size,
^~~~~~
tst-reg-startend.c:94:26: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
BASEERR(ać_data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
^
tst-reg-startend.c: In function ‘do_test’:
tst-reg-startend.c:112:15: error: stray ‘\304’ in program
testa�� ();
^
tst-reg-startend.c:112:16: error: stray ‘\207’ in program
testa�� ();
^
@@ -295,6 +295,7 @@ tests := \
tst-posix_spawn-setsid \
tst-preadwrite \
tst-preadwrite64 \
+ tst-reg-startend \
tst-regcomp-truncated \
tst-regex \
tst-regex2 \
new file mode 100644
@@ -0,0 +1,124 @@
+/* Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+#include <assert.h>
+#include <locale.h>
+#include <string.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+
+#define M(s, e) (regmatch_t) {.rm_so = s, .rm_eo = e}
+#define MEQ(l, r) ((l).rm_so == (r).rm_so && (l).rm_eo == (r).rm_eo)
+
+static const regmatch_t bound = M(1, 4);
+
+static const char *const regex_ac[] =
+ {"^a", "c$", "^a.c$", "^a.*c$", "^a[^c]c$", "^a..", "..c", "[^z]c", NULL};
+static const char *const regex_aa[] =
+ {"^", "^a", "a$", "^\\(a\\).\\1$", "^a[^a]*", NULL};
+static const char *const data_ac[] = {"_a\0cdef", "_abcdef"};
+static const char *const data_aa[] = {"_a\0adef", "_abadef"};
+static const regmatch_t results_ac[] =
+ {M(1, 2), M(3, 4), M(1, 4), M(1, 4), M(1, 4), M(1, 4), M(1, 4), M(2, 4)};
+static const regmatch_t results_aa[] =
+ {M(1, 1), M(1, 2), M(3, 4), M(1, 4), M(1, 3)};
+static_assert(sizeof(regex_ac) / sizeof(*regex_ac) - 1 ==
+ sizeof(results_ac) / sizeof(*results_ac), "");
+static_assert(sizeof(regex_aa) / sizeof(*regex_aa) - 1 ==
+ sizeof(results_aa) / sizeof(*results_aa), "");
+
+
+static bool
+testbunch (const char *const *regexes, const char *const data[static 2],
+ const regmatch_t *results)
+{
+#define BASEERR(data) \
+ err = true, \
+ fprintf (stdout, __FILE__ ": %s: ", *regexes), \
+ fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
+
+ bool err = false;
+ for (; *regexes; ++regexes, ++results)
+ {
+ regex_t rgx;
+ assert (!regcomp (&rgx, *regexes, 0));
+
+ for (size_t i = 0; i < 2; ++i)
+ {
+ regmatch_t match = bound;
+ if (regexec (&rgx, data[i], 1, &match, REG_STARTEND))
+ BASEERR(data), fputs (": no match\n", stdout);
+
+ if (!MEQ(match, *results))
+ BASEERR(data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
+ (int)results->rm_so, (int)results->rm_eo,
+ (int)match.rm_so, (int)match.rm_eo);
+ }
+
+ regfree(&rgx);
+ }
+
+ return err;
+}
+
+
+static const char *const ać_data[2] = {"_aaćdef", "_aćdef"};
+static const bool ać_exp[] = {false, true};
+
+static bool
+testać (void)
+{
+ bool err = false;
+ regex_t rgx;
+ const char *const regexes[] = {"ać"};
+ assert (!regcomp (&rgx, *regexes, 0));
+
+ for (size_t i = 0; i < 2; ++i)
+ {
+ regmatch_t match = bound;
+ if (regexec (&rgx, ać_data[i], 1, &match, REG_STARTEND) == ać_exp[i])
+ BASEERR(ać_data), fprintf (stdout, ": %s match\n",
+ ać_exp[i] ? "no" : "yes");
+
+ if (!MEQ(match, bound))
+ BASEERR(ać_data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
+ (int)bound.rm_so, (int)bound.rm_eo,
+ (int)match.rm_so, (int)match.rm_eo);
+ }
+
+ regfree(&rgx);
+ return err;
+}
+
+
+static int
+do_test (int argc, char **argv)
+{
+ (void) argc, (void) argv;
+ assert (setlocale (LC_ALL, "C.UTF-8"));
+
+ return testbunch (regex_ac, data_ac, results_ac) ||
+ testbunch (regex_aa, data_aa, results_aa) ||
+ testać ();
+}
+
+
+#ifndef STANDALONE
+#include "../test-skeleton.c"
+#else
+int
+main(int argc, char **argv)
+{
+ return do_test(argc, argv);
+}
+#endif