summaryrefslogtreecommitdiffstats
path: root/test/parse.c
diff options
context:
space:
mode:
authordev <dev@example>2026-11-14 01:05:08 +0000
committerdev <dev@example>2026-11-14 01:05:08 +0000
commit312ddd4936f09ae27a180ca495cacf2c06faf33e (patch)
tree2fa46ab568ad55f7e8fb844c3447b1d296b2e340 /test/parse.c
parente737f3d560de2b8172e6dd83901bc1359283303c (diff)
downloadaccess-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/parse.c')
-rw-r--r--test/parse.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/test/parse.c b/test/parse.c
index fb137c5..5c8cb5f 100644
--- a/test/parse.c
+++ b/test/parse.c
@@ -1,10 +1,5 @@
-/* parse.c - Reading the file: what parses, what is refused, and who "@all" turns out to
- * be. One bad line poisons the whole file, so the error cases matter as much
- * as the good ones.
- *
- * 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 parses, what is refused, and who "@all" turns out to be. One bad line
+// poisons the whole file.
#include "test.h"
static void test_parse(void)
@@ -29,14 +24,14 @@ static void test_parse(void)
CHECK_INT(p.rules[0].line, 4);
CHECK_STR(p.rules[1].refs[0], "refs/heads/feature/*");
CHECK_INT(p.rules[1].nrefs, 2);
- CHECK_STR(p.rules[2].refs[0], "refs/heads/main"); /* normalised at parse time */
+ CHECK_STR(p.rules[2].refs[0], "refs/heads/main"); // normalised at parse time
policy_free(&p);
- /* Errors: each of these must stop the file being used at all. The complaints
- * are asserted as counts, and the parser writes them to stderr as it goes, so
- * stderr is set aside here - a wall of expected errors would hide the failures.
- * The descriptor is redirected rather than freopen'd, because freopen would
- * quietly make stderr block-buffered and hand the whole wall back at exit. */
+ // Errors: each of these must stop the file being used at all. The complaints
+ // are asserted as counts, and the parser writes them to stderr as it goes, so
+ // stderr is set aside here - a wall of expected errors would hide the failures.
+ // The descriptor is redirected rather than freopen'd, because freopen would
+ // quietly make stderr block-buffered and hand the whole wall back at exit.
{
int keep = dup(2);
int devnull = open("/dev/null", O_WRONLY);
@@ -67,9 +62,9 @@ static void test_parse(void)
CHECK_INT(rc, -1);
policy_free(&p);
- /* Removed settings are refused by name, not ignored: a policy that
- * still carries one would otherwise mean "everyone with write can fast
- * -forward main" while looking like it said the opposite. */
+ // Removed settings are refused by name, not ignored: a policy that still
+ // carries one would otherwise mean "everyone with write can fast -forward main"
+ // while looking like it said the opposite.
rc = load_text(&p, "set protected-refs refs/heads/main\n");
CHECK_INT(rc, -1);
policy_free(&p);
@@ -79,7 +74,7 @@ static void test_parse(void)
policy_free(&p);
rc = load_text(&p, "alice web write refs/heads/main\nbob web nope refs/heads/dev\n");
- CHECK_INT(rc, -1); /* one bad line poisons the file: nothing is used */
+ CHECK_INT(rc, -1); // one bad line poisons the file: nothing is used
policy_free(&p);
fflush(stderr);
@@ -87,7 +82,7 @@ static void test_parse(void)
close(keep);
}
- /* There is no settings list any more: a rule says what it says. */
+ // There is no settings list any more: a rule says what it says.
rc = load_text(&p, "alice * admin\n");
CHECK_INT(rc, 0);
CHECK_INT(p.nrules, 1);
@@ -106,18 +101,18 @@ static void test_known_users(void)
CHECK_INT(rc, 0);
CHECK(authz_user_known(&p, "alice"));
CHECK(authz_user_known(&p, "bob"));
- CHECK(!authz_user_known(&p, "carol")); /* '@all' never invents a name */
+ CHECK(!authz_user_known(&p, "carol")); // '@all' never invents a name
CHECK(!authz_user_known(&p, ""));
policy_free(&p);
rc = load_text(&p, "@all web write\n");
CHECK_INT(rc, 0);
- CHECK(!authz_user_known(&p, "alice")); /* nobody is known yet */
+ CHECK(!authz_user_known(&p, "alice")); // nobody is known yet
policy_free(&p);
rc = load_text(&p, "ali* web write\n");
CHECK_INT(rc, 0);
- CHECK(authz_user_known(&p, "alice")); /* a pattern is still a name */
+ CHECK(authz_user_known(&p, "alice")); // a pattern is still a name
CHECK(!authz_user_known(&p, "bob"));
policy_free(&p);
}