From: Armaan Bhojwani Date: Tue, 11 May 2021 00:26:39 +0000 (-0400) Subject: Add tests, restructure repo, and add static target X-Git-Url: https://git.armaanb.net/?p=libacheam.git;a=commitdiff_plain;h=45af2131d0dce416c9960f6dbfa309d8421026cd Add tests, restructure repo, and add static target --- diff --git a/.gitignore b/.gitignore index 6d5e378..ee15c0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ *.o +*.a *.so + man/* !man/*.scd + +test diff --git a/Makefile b/Makefile index fc46d4b..a301e4a 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ DESTDIR ?= /usr/local CFLAGS := -Wall -Wextra -pedantic -std=c99 -fPIC ${CFLAGS} -all: lib man +all: shared static man -lib: - ${CC} -shared ${LDFLAGS} ${OBJS} -o libacheam.so src/*.c ${CFLAGS} +shared: + ${CC} -shared ${LDFLAGS} -o libacheam.so src/libacheam/*.c ${CFLAGS} + +static: + ${CC} ${LDFLAGS} src/libacheam/*.c ${CFLAGS} -c + ar rcs libacheam.a *.o man: for i in man/*.scd; do \ @@ -18,10 +22,10 @@ install: all ${DESTDIR}/lib/pkgconfig \ ${DESTDIR}/man/man3 - cp libacheam.so ${DESTDIR}/lib - cp acheam.pc ${DESTDIR}/lib/pkgconfig - cp src/acheam.h ${DESTDIR}/include - cp man/*.3 ${DESTDIR}/man/man3/ + cp libacheam.so ${DESTDIR}/lib + cp acheam.pc ${DESTDIR}/lib/pkgconfig + cp man/*.3 ${DESTDIR}/man/man3/ + cp src/libacheam/acheam.h ${DESTDIR}/include uninstall: rm ${DESTDIR}/include/acheam.h \ @@ -32,5 +36,12 @@ uninstall: rm ${DESTDIR}/man/man3/$$(basename "$$i" ".scd"); \ done +test: static + ${CC} -o test src/tests.c -I./src/libacheam libacheam.a ${CFLAGS} + ./test + +clean: + rm -f test libacheam.so libacheam.a *.o man/*.3 + .POSIX: -.PHONY: all man +.PHONY: all man test diff --git a/src/acheam.h b/src/acheam.h deleted file mode 100644 index df3460e..0000000 --- a/src/acheam.h +++ /dev/null @@ -1,2 +0,0 @@ -char * tolowerw(char *input); -char * toupperw(char *input); diff --git a/src/libacheam/acheam.h b/src/libacheam/acheam.h new file mode 100644 index 0000000..df3460e --- /dev/null +++ b/src/libacheam/acheam.h @@ -0,0 +1,2 @@ +char * tolowerw(char *input); +char * toupperw(char *input); diff --git a/src/libacheam/tolowerw.c b/src/libacheam/tolowerw.c new file mode 100644 index 0000000..386ce2d --- /dev/null +++ b/src/libacheam/tolowerw.c @@ -0,0 +1,15 @@ +#include +#include +#include + +char * +tolowerw(char *inp) +{ + char *tmp = calloc(strlen(inp), sizeof(char)); + strcpy(tmp, inp); + for (int i = 0; tmp[i]; i++){ + tmp[i] = tolower(tmp[i]); + } + return tmp; +} + diff --git a/src/libacheam/toupperw.c b/src/libacheam/toupperw.c new file mode 100644 index 0000000..99ac102 --- /dev/null +++ b/src/libacheam/toupperw.c @@ -0,0 +1,15 @@ +#include +#include +#include + +char * +toupperw(char *inp) +{ + char *tmp = calloc(strlen(inp), sizeof(char)); + strcpy(tmp, inp); + for (int i = 0; tmp[i]; i++){ + tmp[i] = toupper(tmp[i]); + } + return tmp; +} + diff --git a/src/tests.c b/src/tests.c new file mode 100644 index 0000000..c7dd2a2 --- /dev/null +++ b/src/tests.c @@ -0,0 +1,18 @@ +#include +#include + +#include +#include + +int +main(void) +{ + // tolowerw() + assert(strcmp(tolowerw("eXaMpLe StRiNg"), "example string") == 0); + + // toupperw() + assert(strcmp(toupperw("eXaMpLe StRiNg"), "EXAMPLE STRING") == 0); + + printf("All tests passed succesfully!\n"); + return 0; +} diff --git a/src/tolowerw.c b/src/tolowerw.c deleted file mode 100644 index 386ce2d..0000000 --- a/src/tolowerw.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -char * -tolowerw(char *inp) -{ - char *tmp = calloc(strlen(inp), sizeof(char)); - strcpy(tmp, inp); - for (int i = 0; tmp[i]; i++){ - tmp[i] = tolower(tmp[i]); - } - return tmp; -} - diff --git a/src/toupperw.c b/src/toupperw.c deleted file mode 100644 index 99ac102..0000000 --- a/src/toupperw.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -char * -toupperw(char *inp) -{ - char *tmp = calloc(strlen(inp), sizeof(char)); - strcpy(tmp, inp); - for (int i = 0; tmp[i]; i++){ - tmp[i] = toupper(tmp[i]); - } - return tmp; -} -