diff options
| author | dev <dev@example> | 2026-11-14 01:05:08 +0000 |
|---|---|---|
| committer | dev <dev@example> | 2026-11-14 01:05:08 +0000 |
| commit | 312ddd4936f09ae27a180ca495cacf2c06faf33e (patch) | |
| tree | 2fa46ab568ad55f7e8fb844c3447b1d296b2e340 /test/glob.c | |
| parent | e737f3d560de2b8172e6dd83901bc1359283303c (diff) | |
| download | access-control-312ddd4936f09ae27a180ca495cacf2c06faf33e.tar.gz access-control-312ddd4936f09ae27a180ca495cacf2c06faf33e.zip | |
Comments: cut to what the code cannot say
The comments had grown into essays. A file header explaining why the file
exists, then a paragraph above each function restating what the next eight
lines do, then a paragraph above that one explaining why that matters. The
reader gets no further than the first paragraph, and the second is the one that
goes stale: it describes code that has since changed, and nothing fails when it
does.
Cut by about half. What is left is the three things a comment can do that code
cannot: say why the constraint exists (no regex because a hook must not depend
on what might be missing at 3am), say what is not obvious from the shape (a
bare ref name is a branch, never a tag; the seventh field of /etc/passwd is the
shell), and say where it hurts (the NULL in an execvp array, the mode and owner
that have to survive an atomic rewrite, the child that must not keep the hook's
stdin).
Block comments became // lines, which is also what the other C trees here use,
and the file headers went to two or three lines. Section banners stayed: they
are navigation, not prose.
Behaviour is unchanged and the suites prove it: 171 direct checks, 162
behavioural, clean under -Werror and under ASan/UBSan.
Diffstat (limited to 'test/glob.c')
| -rw-r--r-- | test/glob.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/test/glob.c b/test/glob.c index ee1bece..cbb97c8 100644 --- a/test/glob.c +++ b/test/glob.c @@ -1,9 +1,4 @@ -/* glob.c - What a glob matches. Written out rather than reached for with fnmatch(3) - * or regex(3), so this is the file that says what "*" and "[!a-z]" mean here. - * - * Part of the direct suite: this links the library, not the command - * line. test/run.sh is the other half, and drives the program the way git does. - */ +// What a glob matches, since nothing here uses fnmatch or regex. #include "test.h" static void test_glob(void) @@ -13,7 +8,7 @@ static void test_glob(void) CHECK(!glob_match("", "x")); CHECK(glob_match("", "")); CHECK(glob_match("refs/heads/*", "refs/heads/main")); - CHECK(glob_match("refs/heads/*", "refs/heads/a/b/c")); /* '*' crosses '/' */ + CHECK(glob_match("refs/heads/*", "refs/heads/a/b/c")); // '*' crosses '/' CHECK(!glob_match("refs/heads/*", "refs/tags/v1")); CHECK(glob_match("refs/heads/feature/*", "refs/heads/feature/login")); CHECK(!glob_match("refs/heads/feature/*", "refs/heads/featurey")); @@ -26,17 +21,17 @@ static void test_glob(void) CHECK(!glob_match("refs/heads/[!ab]*", "refs/heads/alpha")); CHECK(glob_match("refs/heads/[a-c]1", "refs/heads/b1")); CHECK(!glob_match("refs/heads/[a-c]1", "refs/heads/d1")); - CHECK(glob_match("refs/heads/]", "refs/heads/]")); /* ']' first is a member */ - CHECK(glob_match("refs/heads/a[-]z", "refs/heads/a-z")); /* trailing '-' literal */ - CHECK(glob_match("refs/heads/[", "refs/heads/[")); /* unclosed is literal */ + CHECK(glob_match("refs/heads/]", "refs/heads/]")); // ']' first is a member + CHECK(glob_match("refs/heads/a[-]z", "refs/heads/a-z")); // trailing '-' literal + CHECK(glob_match("refs/heads/[", "refs/heads/[")); // unclosed is literal CHECK(glob_match("a*b*c", "aXXbYYc")); CHECK(!glob_match("a*b*c", "aXXbYY")); CHECK(glob_match("*.git", "team.git")); CHECK(glob_match("team*", "team")); CHECK(glob_match("refs/heads/ma?n", "refs/heads/main")); - CHECK(!glob_match("refs/heads/main", "refs/heads/MAIN")); /* case matters */ + CHECK(!glob_match("refs/heads/main", "refs/heads/MAIN")); // case matters CHECK(glob_match("refs/*/x", "refs/a/b/x")); - CHECK(glob_match("**", "x")); /* redundant stars */ + CHECK(glob_match("**", "x")); // redundant stars CHECK(!glob_match("refs/heads/*", "")); } |
