diff --git a/Makefile b/Makefile index 95a2a59..f1b409e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Compiler Flags CC := gcc -CFLAGS := -g -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -fno-omit-frame-pointer +CFLAGS := -g -Wall -Wextra -Werror -pedantic -fno-omit-frame-pointer # Directory variables LIBDIR := lib @@ -54,23 +54,32 @@ $(TEST)/bin: mkdir $@ # Run the tests in the bin folder and track results -test: $(LIB) $(TEST)/bin $(TESTBINS) - @SUCCESS_COUNT=0; FAILURE_COUNT=0; \ - for test in $(TESTBINS); do \ - ./$$test; \ - EXIT_CODE=$$?; \ - TEST_NAME=$(notdir $$test); \ - if [ $$EXIT_CODE -eq 0 ]; then \ - echo "\033[0;32m$$TEST_NAME: EXIT CODE: $$EXIT_CODE (SUCCESS)\033[0m"; \ - SUCCESS_COUNT=$$((SUCCESS_COUNT + 1)); \ +test: $(LIB) $(TESTBINS) + @SUCCESS=0; FAILURE=0; \ + RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'; \ + for t in $(TESTBINS); do \ + NAME=$$(basename $$t); \ + START=$$(date +%s%N); \ + if $$t; then \ + RET=0; \ else \ - echo "\033[0;31m$$TEST_NAME: EXIT CODE: $$EXIT_CODE (FAILURE)\033[0m"; \ - FAILURE_COUNT=$$((FAILURE_COUNT + 1)); \ + RET=$$?; \ + fi; \ + END=$$(date +%s%N); \ + ELAPSED_NS=$$((END - START)); \ + ELAPSED_MS=$$((ELAPSED_NS / 1000000)); \ + if [ $$RET -eq 0 ]; then \ + printf "%-20s %bPASS%b (%b%4d ms%b)\n" "$$NAME" "$$GREEN" "$$NC" "$$YELLOW" "$$ELAPSED_MS" "$$NC"; \ + SUCCESS=$$((SUCCESS + 1)); \ + else \ + printf "%-20s %bFAIL%b (%b%4d ms%b)\n" "$$NAME" "$$RED" "$$NC" "$$YELLOW" "$$ELAPSED_MS" "$$NC"; \ + FAILURE=$$((FAILURE + 1)); \ fi; \ done; \ - echo "\n\nTests completed"; \ - echo "SUCCESS: $$SUCCESS_COUNT"; \ - echo "FAILURE: $$FAILURE_COUNT"; - + printf "\nTests completed\n"; \ + printf "SUCCESS: %b%d%b\n" "$$GREEN" "$$SUCCESS" "$$NC"; \ + printf "FAILURE: %b%d%b\n" "$$RED" "$$FAILURE" "$$NC"; \ + test $$FAILURE -eq 0 + clean: $(RM) -r $(LIBDIR) $(OBJ) $(TEST)/bin/ diff --git a/src/except.c b/src/except.c index 08bdb3e..03005b8 100644 --- a/src/except.c +++ b/src/except.c @@ -17,7 +17,7 @@ void except_raise(const struct Exception *e, const char *file,int line) #ifdef WIN32 Except_Frame *p; - if (except_index == -1) + if (except_index == TLS_OUT_OF_INDEXES) except_init(); p = TlsGetValue(except_index); #else @@ -46,6 +46,8 @@ void except_raise(const struct Exception *e, const char *file,int line) #endif longjmp(p->env, EXCEPT_STATE_RAISED); } + + #ifdef WIN32 _CRTIMP void __cdecl _assert(void *, void *, unsigned); #undef assert @@ -61,7 +63,7 @@ void except_init(void) { assert(cond == TRUE); } -void Except_push(Except_Frame *fp) { +void except_push(Except_Frame *fp) { BOOL cond; fp->prev = TlsGetValue(except_index); @@ -69,7 +71,7 @@ void Except_push(Except_Frame *fp) { assert(cond == TRUE); } -void Except_pop(void) { +void except_pop(void) { BOOL cond; Except_Frame *tos = TlsGetValue(except_index);