logo

utils-std

Collection of commonly available Unix tools
commit: 3546c98aad5457db9eea94b3bf4d78f89062b0db
parent bf69fda0e50d4168ad2dda87151d45f7d22451c3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  6 May 2024 17:01:03 +0200

Makefile: Add test-lib/*.c to format target

Diffstat:

MMakefile2+-
Mtest-lib/mode.c38+++++++++++++++++++-------------------
Mtest-lib/strtodur.c19++++++++++++++-----
Mtest-lib/symbolize_mode.c3++-
Mtest-lib/truncation.c18+++++++++---------
5 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/Makefile b/Makefile @@ -58,7 +58,7 @@ install: all coverage: $(GCOV) -b $(EXE) -C_SOURCES = cmd/*.c lib/*.h lib/*.c configure.d/*.c +C_SOURCES = cmd/*.c lib/*.h lib/*.c test-lib/*.c configure.d/*.c format: $(C_SOURCES) clang-format -style=file -assume-filename=.clang-format -i $(C_SOURCES) diff --git a/test-lib/mode.c b/test-lib/mode.c @@ -3,13 +3,13 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L +#include "../lib/mode.h" + #include <assert.h> -#include <stdio.h> // printf -#include <string.h> // strcmp +#include <stdio.h> // printf +#include <string.h> // strcmp #include <sys/stat.h> // umask -#include "../lib/mode.h" - int counter = 0; int err = 0; @@ -58,7 +58,7 @@ add_read() printf("# => add_read\n"); umask(0044); - t_mode( "+r", 0, 00400); + t_mode("+r", 0, 00400); t_mode("a+r", 0, 00444); t_mode("u+r", 0, 00400); t_mode("g+r", 0, 00040); @@ -70,7 +70,7 @@ add_read() t_mode("g+r,o+r", 0, 00044); t_mode("u+r,o+r", 0, 00404); - t_mode( "+r", 00777, 00777); + t_mode("+r", 00777, 00777); t_mode("a+r", 00777, 00777); t_mode("u+r", 00777, 00777); t_mode("g+r", 00777, 00777); @@ -89,7 +89,7 @@ set_read() printf("# => set_read\n"); umask(0044); - t_mode( "=r", 0, 00400); + t_mode("=r", 0, 00400); t_mode("a=r", 0, 00444); t_mode("u=r", 0, 00400); t_mode("g=r", 0, 00040); @@ -101,7 +101,7 @@ set_read() t_mode("g=r,o=r", 0, 00044); t_mode("u=r,o=r", 0, 00404); - t_mode( "=r", 00777, 00400); + t_mode("=r", 00777, 00400); t_mode("a=r", 00777, 00444); t_mode("u=r", 00777, 00477); t_mode("g=r", 00777, 00747); @@ -120,7 +120,7 @@ del_read() printf("# => del_read\n"); umask(0044); - t_mode( "-r", 0, 0); + t_mode("-r", 0, 0); t_mode("a-r", 0, 0); t_mode("u-r", 0, 0); t_mode("g-r", 0, 0); @@ -132,7 +132,7 @@ del_read() t_mode("g-r,o-r", 0, 0); t_mode("u-r,o-r", 0, 0); - t_mode( "-r", 00777, 00377); + t_mode("-r", 00777, 00377); t_mode("a-r", 00777, 00333); t_mode("u-r", 00777, 00377); t_mode("g-r", 00777, 00737); @@ -149,56 +149,56 @@ static void search() { printf("# => search\n"); - t_mode( "-X", 0, 0); + t_mode("-X", 0, 0); t_mode("a-X", 0, 0); t_mode("u-X", 0, 0); t_mode("g-X", 0, 0); t_mode("o-X", 0, 0); - t_mode( "+X", 0, 0); + t_mode("+X", 0, 0); t_mode("a+X", 0, 0); t_mode("u+X", 0, 0); t_mode("g+X", 0, 0); t_mode("o+X", 0, 0); - t_mode( "=X", 0, 0); + t_mode("=X", 0, 0); t_mode("a=X", 0, 0); t_mode("u=X", 0, 0); t_mode("g=X", 0, 0); t_mode("o=X", 0, 0); // S_IFDIR = 0040000 - t_mode( "-X", 0040777, 0040666); + t_mode("-X", 0040777, 0040666); t_mode("a-X", 0040777, 0040666); t_mode("u-X", 0040777, 0040677); t_mode("g-X", 0040777, 0040767); t_mode("o-X", 0040777, 0040776); - t_mode( "+X", 0040777, 0040777); + t_mode("+X", 0040777, 0040777); t_mode("a+X", 0040777, 0040777); t_mode("u+X", 0040777, 0040777); t_mode("g+X", 0040777, 0040777); t_mode("o+X", 0040777, 0040777); - t_mode( "=X", 0040777, 0040111); + t_mode("=X", 0040777, 0040111); t_mode("a=X", 0040777, 0040111); t_mode("u=X", 0040777, 0040177); t_mode("g=X", 0040777, 0040717); t_mode("o=X", 0040777, 0040771); - t_mode( "-X", 0040000, 0040000); + t_mode("-X", 0040000, 0040000); t_mode("a-X", 0040000, 0040000); t_mode("u-X", 0040000, 0040000); t_mode("g-X", 0040000, 0040000); t_mode("o-X", 0040000, 0040000); - t_mode( "+X", 0040000, 0040111); + t_mode("+X", 0040000, 0040111); t_mode("a+X", 0040000, 0040111); t_mode("u+X", 0040000, 0040100); t_mode("g+X", 0040000, 0040010); t_mode("o+X", 0040000, 0040001); - t_mode( "=X", 0040000, 0040111); + t_mode("=X", 0040000, 0040111); t_mode("a=X", 0040000, 0040111); t_mode("u=X", 0040000, 0040100); t_mode("g=X", 0040000, 0040010); diff --git a/test-lib/strtodur.c b/test-lib/strtodur.c @@ -21,13 +21,22 @@ t_strtodur(char *str, time_t ex_sec, long ex_nsec) if(dur.tv_sec == ex_sec && dur.tv_nsec == ex_nsec && ret == 0) { - printf("ok %d - strtodur(\"%s\", _) -> {.tv_sec = %ld, .tv_nsec = %ld}\n", id, str, dur.tv_sec, dur.tv_nsec); + printf("ok %d - strtodur(\"%s\", _) -> {.tv_sec = %ld, .tv_nsec = %ld}\n", + id, + str, + dur.tv_sec, + dur.tv_nsec); return; } err = 1; - printf("not ok %d - strtodur(\"%s\", _) -> {.tv_sec = %ld, .tv_nsec = %ld}\n", id, str, dur.tv_sec, dur.tv_nsec); - if(dur.tv_sec != ex_sec || dur.tv_nsec != ex_nsec) printf("# Expected: {.tv_sec = %ld, .tv_nsec = %ld}\n", ex_sec, ex_nsec); + printf("not ok %d - strtodur(\"%s\", _) -> {.tv_sec = %ld, .tv_nsec = %ld}\n", + id, + str, + dur.tv_sec, + dur.tv_nsec); + if(dur.tv_sec != ex_sec || dur.tv_nsec != ex_nsec) + printf("# Expected: {.tv_sec = %ld, .tv_nsec = %ld}\n", ex_sec, ex_nsec); if(ret != 0) printf("# Exit status: %d\n", ret); } @@ -47,8 +56,8 @@ main() t_strtodur("1.", 1, 0); t_strtodur("1,", 1, 0); - t_strtodur(".1", 0, 1000000000*0.1); - t_strtodur("0.1", 0, 1000000000*0.1); + t_strtodur(".1", 0, 1000000000 * 0.1); + t_strtodur("0.1", 0, 1000000000 * 0.1); assert(counter == plan); return err; diff --git a/test-lib/symbolize_mode.c b/test-lib/symbolize_mode.c @@ -4,8 +4,9 @@ #define _POSIX_C_SOURCE 200809L #include "../lib/mode.h" + #include <assert.h> -#include <stdio.h> // printf +#include <stdio.h> // printf #include <string.h> // strcmp int counter = 0; diff --git a/test-lib/truncation.c b/test-lib/truncation.c @@ -37,9 +37,9 @@ set() { t_parse_size("0", 0L, OP_SET); t_parse_size("666", 666L, OP_SET); - t_parse_size("666M", 666*1024*1024L, OP_SET); - t_parse_size("666MB", 666*1000*1000L, OP_SET); - t_parse_size("666MiB", 666*1024*1024L, OP_SET); + t_parse_size("666M", 666 * 1024 * 1024L, OP_SET); + t_parse_size("666MB", 666 * 1000 * 1000L, OP_SET); + t_parse_size("666MiB", 666 * 1024 * 1024L, OP_SET); } static void @@ -47,9 +47,9 @@ inc() { t_parse_size("+0", 0L, OP_INC); t_parse_size("+666", 666L, OP_INC); - t_parse_size("+666M", 666*1024*1024L, OP_INC); - t_parse_size("+666MB", 666*1000*1000L, OP_INC); - t_parse_size("+666MiB", 666*1024*1024L, OP_INC); + t_parse_size("+666M", 666 * 1024 * 1024L, OP_INC); + t_parse_size("+666MB", 666 * 1000 * 1000L, OP_INC); + t_parse_size("+666MiB", 666 * 1024 * 1024L, OP_INC); } static void @@ -57,9 +57,9 @@ dec() { t_parse_size("-0", 0L, OP_DEC); t_parse_size("-666", 666L, OP_DEC); - t_parse_size("-666M", 666*1024*1024L, OP_DEC); - t_parse_size("-666MB", 666*1000*1000L, OP_DEC); - t_parse_size("-666MiB", 666*1024*1024L, OP_DEC); + t_parse_size("-666M", 666 * 1024 * 1024L, OP_DEC); + t_parse_size("-666MB", 666 * 1000 * 1000L, OP_DEC); + t_parse_size("-666MiB", 666 * 1024 * 1024L, OP_DEC); } int