diff options
| author | dev <dev@example> | 2026-11-14 00:06:35 +0000 |
|---|---|---|
| committer | dev <dev@example> | 2026-11-14 00:06:35 +0000 |
| commit | bc7f4da406fbd802b08985ba583e52f040bdba85 (patch) | |
| tree | fa5020a3781dd80dcba654a3417d22d02df4c2da /test/need.c | |
| parent | 50f296cf7609ce77d41b9fb3df51d6aeec8330d6 (diff) | |
| download | access-control-bc7f4da406fbd802b08985ba583e52f040bdba85.tar.gz access-control-bc7f4da406fbd802b08985ba583e52f040bdba85.zip | |
Layout: cmd/, src/, test/, everything built into obj/
The tree had grown sideways: main.c living among the sources it dispatches to,
one test binary covering everything, object files left in the source directory
because the Makefile put them there and, worse, tracked them.
Now the command line is cmd/main.c, the engine is src/ and nothing in it knows
about the command line, and each area of the engine has its own program under
test/ - glob, norm, parse, need, check - each linking the library and reporting
its own count. A failure says which area broke instead of taking the whole run
down with a single "unit: 171" line, which is the only thing a per-file split
buys and it is worth the small duplication the shared test.h absorbs.
Objects go to obj/, test runners to obj/test_runner/, so a build leaves the
tree as it found it. The stale src/*.o and tests/unit that were committed
earlier are gone; they were build output in a source tree and the .gitignore
that should have stopped them arrived after they did.
The Makefile follows the same shape as the other C trees here: directories in
variables, wildcards for the sources, one pattern rule that makes its own
directory, test runners built from the same objects as the binary so they
cannot test a different build than ships, and `test` running every runner with
a foreach so the first failure stops the line. `strict` is `all` with -Werror,
which is what CI now calls instead of passing CFLAGS in from outside; the
sanitizer and install targets are unchanged in what they do.
Behaviour is unchanged: 171 direct checks and 154 behavioural ones, same as
before the move, and make install still stages a working hook symlink.
Diffstat (limited to 'test/need.c')
| -rw-r--r-- | test/need.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/need.c b/test/need.c new file mode 100644 index 0000000..f831111 --- /dev/null +++ b/test/need.c @@ -0,0 +1,47 @@ +/* need.c - What a ref costs beyond what the rule said - which is only ever the case + * for refs outside refs/heads and refs/tags. There is no second list in the + * policy that can raise the price of a ref behind the operator's back. + * + * 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. + */ +#include "test.h" + +static void test_need_for(void) +{ + char raised[64]; + + /* A branch or a tag costs exactly what the rule said: there is no list + * elsewhere in the file that can raise the price of one. */ + CHECK_INT(authz_need_for("refs/heads/dev", LV_WRITE, raised, sizeof(raised)), + LV_WRITE); + CHECK_STR(raised, ""); + CHECK_INT(authz_need_for("refs/heads/main", LV_WRITE, raised, sizeof(raised)), + LV_WRITE); + CHECK_INT(authz_need_for("refs/tags/v1", LV_WRITE, raised, sizeof(raised)), + LV_WRITE); + CHECK_INT(authz_need_for("refs/heads/feature/x", LV_FORCE, raised, sizeof(raised)), + LV_FORCE); + + /* Anything outside refs/heads and refs/tags is for maintainers, whatever a + * rule appears to grant about it. */ + CHECK_INT(authz_need_for("refs/pull/1/head", LV_WRITE, raised, sizeof(raised)), + LV_ADMIN); + CHECK_STR(raised, "neither a branch nor a tag"); + CHECK_INT(authz_need_for("refs/pull/1/head", LV_FORCE, raised, sizeof(raised)), + LV_ADMIN); + CHECK_INT(authz_need_for("refs/notes/x", LV_WRITE, raised, sizeof(raised)), + LV_ADMIN); + CHECK_INT(authz_need_for("refs/notes/x", LV_ADMIN, raised, sizeof(raised)), + LV_ADMIN); + CHECK_STR(raised, ""); /* admin is already the top */ +} + +int main(void) +{ + test_init(""); + + test_need_for(); + + return test_report("need"); +} |
