Commit 4e1e77c
test/posix: Adjust fnmatch tests to conform with POSIX specs
Some of the fnmatch tests didn't match POSIX.
> - zassert_ok(fnmatch("[[?*\\]", "\\", 0));
This pattern includes a back-slash, and because FNM_NOESCAPE was not
specified, it will escape the ], so there isn't actually a range expression
here, nor is there any literal backslash in the pattern. So, this does not
match backslash. Replace this with three tests to check each of these
issues:
> + /* \\ escapes ], no bracket expr, no match */
> + zassert_equal(fnmatch("[[?*\\]", "\\", 0), FNM_NOMATCH);
> + /* \\ unescaped, match */
> + zassert_ok(fnmatch("[[?*\\]", "\\", FNM_NOESCAPE));
> + /* \\ escapes \\, match */
> + zassert_ok(fnmatch("[[?*\\\\]", "\\", 0));
> - zassert_ok(fnmatch("[]?*\\]", "]", 0));
This one has the same issue, except it tries to match ] instead. Again,
because the \ will end up escaping the final ], this is not a range
expression, and so it doesn't match ]. Replace this with three tests to
check each case separately:
> + /* \\ escapes ], no bracket expr, no match */
> + zassert_equal(fnmatch("[]?*\\]", "]", 0), FNM_NOMATCH);
> + /* \\ unescaped, match */
> + zassert_ok(fnmatch("[]?*\\]", "]", FNM_NOESCAPE));
> + /* \\ escapes \\, match */
> + zassert_ok(fnmatch("[]?*\\\\]", "]", 0));
> - /* zassert_ok(fnmatch("*[[:alpha:]]/""*[[:alnum:]]", "a/b",
> - FNM_PATHNAME)); */
> + zassert_ok(fnmatch("*[[:alpha:]]/""*[[:alnum:]]", "a/b",
> + FNM_PATHNAME));
Re-enable this test; it looks good. The "" will be elided by the compiler,
so I'm not sure why it's here.
> - zassert_not_equal(fnmatch("*[![:digit:]]*/[![:d-d]", "a/b",
> - FNM_PATHNAME), 0);
> + zassert_ok(fnmatch("*[![:digit:]]*/[![:d-d]", "a/b", FNM_PATHNAME));
This pattern matches the string:
* - matches zero characters
[![:digit:]] - matches 'a' (it's not a digit)
* - matches zero characters
/ - matches slash (FNM_PATHNAME specified)
[![:d-d] - matches 'b' (not in the set "[:d-d")
> - zassert_not_equal(fnmatch("*[![:digit:]]*/[[:d-d]", "a/[",
> - FNM_PATHNAME), 0);
> + zassert_ok(fnmatch("*[![:digit:]]*/[[:d-d]", "a/[", FNM_PATHNAME));
This pattern matches the string:
* - matches zero characters
[![:digit:]] - matches 'a'
* - matches zero characters
/ - matches / (FNM_PATHNAME is specified)
[[:d-d] - matches [ (in the set "[:d-d")
I've run all of these tests against glibc which agrees with this version,
and also picolibc, which also works with a pending PR that adds support for
character classes, equivalence classes and collating sequences.
Signed-off-by: Keith Packard <keithp@keithp.com>1 parent e49042c commit 4e1e77c
1 file changed
+15
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
35 | 45 | | |
36 | 46 | | |
37 | 47 | | |
| |||
73 | 83 | | |
74 | 84 | | |
75 | 85 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
79 | 89 | | |
80 | 90 | | |
81 | 91 | | |
| |||
0 commit comments