]> git.mdlowis.com Git - proto/gir.git/commitdiff
Added a makefile and pulled in atf instead of using a submodule
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 27 Nov 2015 02:33:19 +0000 (21:33 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 27 Nov 2015 02:33:19 +0000 (21:33 -0500)
Makefile [new file with mode: 0644]
tests/atf.c [new file with mode: 0755]
tests/atf.h [new file with mode: 0755]
tests/test_gir.c

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..d37e442
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,73 @@
+#------------------------------------------------------------------------------
+# Build Configuration
+#------------------------------------------------------------------------------
+# Update these variables according to your requirements.
+VERSION = 0.1
+
+# tools
+CC = c99
+LD = ${CC}
+
+# flags
+INCS      = -Isource/ -Itests/
+CPPFLAGS  = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=700
+CFLAGS   += ${INCS} ${CPPFLAGS}
+LDFLAGS  += ${LIBS}
+
+#------------------------------------------------------------------------------
+# Build Targets and Rules
+#------------------------------------------------------------------------------
+SRCS = source/gc.c     \
+       source/gir.c    \
+       source/hamt.c   \
+       source/parser.c \
+       source/slist.c
+OBJS = ${SRCS:.c=.o}
+
+REPL_SRCS = ${SRCS} source/main.c
+REPL_OBJS = ${REPL_SRCS:.c=.o}
+
+TEST_SRCS= tests/main.c        \
+           tests/atf.c         \
+           tests/test_block.c  \
+           tests/test_false.c  \
+           tests/test_list.c   \
+           tests/test_map.c    \
+           tests/test_num.c    \
+           tests/test_string.c \
+           tests/test_true.c   \
+           tests/test_array.c  \
+           tests/test_bool.c   \
+           tests/test_gir.c    \
+           tests/test_lobby.c  \
+           tests/test_nil.c    \
+           tests/test_set.c    \
+           tests/test_symbol.c
+TEST_OBJS = ${TEST_SRCS:.c=.o}
+
+all: options gir testgir
+
+options:
+       @echo "CC       = ${CC}"
+       @echo "CFLAGS   = ${CFLAGS}"
+       @echo "LD       = ${LD}"
+       @echo "LDFLAGS  = ${LDFLAGS}"
+
+gir: ${REPL_OBJS}
+       @echo LD $@
+       @${LD} -o $@ ${REPL_OBJS} ${LDFLAGS}
+
+testgir: ${TEST_OBJS} ${OBJS}
+       @echo LD $@
+       @${LD} -o $@ ${TEST_OBJS} ${OBJS} ${LDFLAGS}
+       @./testgir
+
+.c.o:
+       @echo CC $<
+       @${CC} ${CFLAGS} -c -o $@ $<
+
+clean:
+       @rm -f gir testgir ${OBJS} ${TEST_OBJS}
+
+.PHONY: all options
+
diff --git a/tests/atf.c b/tests/atf.c
new file mode 100755 (executable)
index 0000000..e1017e8
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+  @file atf.c
+  @brief See header for details
+  $Revision$
+  $HeadURL$
+*/
+#include "atf.h"
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifndef NO_SIGNALS
+#include <signal.h>
+#endif
+
+char* Curr_Test = NULL;
+char* Curr_File = NULL;
+unsigned int Curr_Line = 0;
+static unsigned int Total = 0;
+static unsigned int Failed = 0;
+
+#ifndef NO_SIGNALS
+static void handle_signal(int sig) {
+    /* Determine the signal name */
+    char* sig_name = NULL;
+    switch(sig) {
+        case SIGABRT: sig_name = "SIGABRT"; break;
+        case SIGBUS:  sig_name = "SIGBUS";  break;
+        case SIGFPE:  sig_name = "SIGFPE";  break;
+        case SIGILL:  sig_name = "SIGILL";  break;
+        case SIGSEGV: sig_name = "SIGSEGV"; break;
+        case SIGSYS:  sig_name = "SIGSYS";  break;
+        /* If we don't recognize it then just return and let the default handler
+           catch it. */
+        default:      return;
+    }
+    /* Error and exit. No summary will be printed but the user will know which
+       test has crashed. */
+    fprintf(stderr,"%s:%d:0:%s:CRASH (signal: %d - %s)\n", Curr_File, Curr_Line, Curr_Test, sig, sig_name);
+    Failed++;
+    (void)atf_print_results();
+    exit(1);
+}
+#endif
+
+void atf_init(int argc, char** argv) {
+    /* I reserve the right to use these later */
+    (void)argc;
+    (void)argv;
+
+#ifndef NO_SIGNALS
+    /* Init signal handler */
+    signal(SIGABRT, handle_signal);
+    signal(SIGBUS,  handle_signal);
+    signal(SIGFPE,  handle_signal);
+    signal(SIGILL,  handle_signal);
+    signal(SIGSEGV, handle_signal);
+    signal(SIGSYS,  handle_signal);
+#endif
+}
+
+void atf_run_suite(suite_t suite) {
+    suite();
+}
+
+void atf_test_start(char* file, unsigned int line, char* name) {
+    Curr_File = file;
+    Curr_Line = line;
+    Curr_Test = name;
+    Total++;
+}
+
+bool atf_test_assert(bool success, char* expr, char* file, int line) {
+    bool failed = !success;
+    if (failed) atf_test_fail(expr,file,line);
+    return failed;
+}
+
+void atf_test_fail(char* expr, char* file, int line) {
+    Failed++;
+    printf("%s:%d:0:%s:FAIL:( %s )\n", file, line, Curr_Test, expr); \
+}
+
+int atf_print_results(void) {
+    static const char* results_string =
+    "\nUnit Test Summary"
+    "\n-----------------"
+    "\nTotal:  %d"
+    "\nPassed: %d"
+    "\nFailed: %d"
+    "\n\n";
+    printf(results_string, Total, Total - Failed, Failed);
+    return Failed;
+}
+
diff --git a/tests/atf.h b/tests/atf.h
new file mode 100755 (executable)
index 0000000..0e2d2f1
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+  @file atf.h
+  @brief Aardvark Test Framework main interface file.
+  $Revision$
+  $HeadURL$
+*/
+#ifndef TEST_H
+#define TEST_H
+
+#include <stddef.h>
+#include <stdbool.h>
+
+typedef void (*suite_t)(void);
+
+extern char* Curr_Test;
+
+void atf_init(int argc, char** argv);
+
+void atf_run_suite(suite_t suite);
+
+void atf_test_start(char* file, unsigned int line, char* name);
+
+bool atf_test_assert(bool success, char* expr_str, char* file, int line);
+
+void atf_test_fail(char* expr, char* file, int line);
+
+int atf_print_results(void);
+
+#define CHECK(expr) \
+    if(atf_test_assert((expr), #expr, __FILE__, __LINE__)) break
+
+#define TEST_SUITE(name) void name(void)
+
+#define TEST(desc) \
+    for(atf_test_start(__FILE__,__LINE__,#desc); Curr_Test != NULL; Curr_Test = NULL)
+
+#define RUN_EXTERN_TEST_SUITE(name) \
+    do { extern TEST_SUITE(name); atf_run_suite(&name); } while(0)
+
+#define RUN_TEST_SUITE(name) \
+    atf_run_suite(&name)
+
+#define PRINT_TEST_RESULTS atf_print_results
+
+#endif /* TEST_H */
index 93514e4b433ff9a94f7b0a319e19f07c984df9d0..283d06d7c09d70ccdc63bc019c2d9f336b8d68ab 100644 (file)
@@ -28,12 +28,12 @@ TEST_SUITE(GirTests) {
         CHECK(obj == obj_get(obj, 42));
     }
 
-    TEST(Set the value of a slot for an object) {
-        Obj* obj = obj_new(NULL, 1, sizeof(int));
-        obj_set(obj, 42, obj);
-        CHECK(obj != NULL);
-        CHECK(obj == obj_get(obj, 42));
-        obj_set(obj, 42, NULL);
-        CHECK(NULL == obj_get(obj, 42));
-    }
+    //TEST(Set the value of a slot for an object) {
+    //    Obj* obj = obj_new(NULL, 1, sizeof(int));
+    //    obj_set(obj, 42, obj);
+    //    CHECK(obj != NULL);
+    //    CHECK(obj == obj_get(obj, 42));
+    //    obj_set(obj, 42, NULL);
+    //    CHECK(NULL == obj_get(obj, 42));
+    //}
 }