]> git.armaanb.net Git - libacheam.git/commitdiff
Add tests, restructure repo, and add static target
authorArmaan Bhojwani <me@armaanb.net>
Tue, 11 May 2021 00:26:39 +0000 (20:26 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Tue, 11 May 2021 00:27:22 +0000 (20:27 -0400)
.gitignore
Makefile
src/acheam.h [deleted file]
src/libacheam/acheam.h [new file with mode: 0644]
src/libacheam/tolowerw.c [new file with mode: 0644]
src/libacheam/toupperw.c [new file with mode: 0644]
src/tests.c [new file with mode: 0644]
src/tolowerw.c [deleted file]
src/toupperw.c [deleted file]

index 6d5e378caa5142ce6cc99a5450f0ed73fd4b0bd1..ee15c0d44c68e429f4a46603b1577d473f9da966 100644 (file)
@@ -1,4 +1,8 @@
 *.o
+*.a
 *.so
+
 man/*
 !man/*.scd
+
+test
index fc46d4bc755f6418c5956c8f136cadd303abc00b..a301e4aed716f72e877fb7a4dcd01a8d9d66ace7 100644 (file)
--- 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 (file)
index df3460e..0000000
+++ /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 (file)
index 0000000..df3460e
--- /dev/null
@@ -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 (file)
index 0000000..386ce2d
--- /dev/null
@@ -0,0 +1,15 @@
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+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 (file)
index 0000000..99ac102
--- /dev/null
@@ -0,0 +1,15 @@
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+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 (file)
index 0000000..c7dd2a2
--- /dev/null
@@ -0,0 +1,18 @@
+#include <acheam.h>
+#include <assert.h>
+
+#include <string.h>
+#include <stdio.h>
+
+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 (file)
index 386ce2d..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-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 (file)
index 99ac102..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-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;
-}
-