summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-05 06:07:45 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-05 06:07:45 +0200
commit6f01f3eb2c5bc6b34d2a33bb4d4eb42704d22db6 (patch)
tree8a04a07c82c7fa2d7974f8c984ab5105cd6cc977
parentc7934218d7bfcba408b725c41fab1f3d5d890162 (diff)
downloadkit-6f01f3eb2c5bc6b34d2a33bb4d4eb42704d22db6.zip
test
-rw-r--r--build_and_test.sh53
-rw-r--r--source/kit_test/test.c4
2 files changed, 47 insertions, 10 deletions
diff --git a/build_and_test.sh b/build_and_test.sh
index 5416fa3..f434244 100644
--- a/build_and_test.sh
+++ b/build_and_test.sh
@@ -6,13 +6,14 @@ COMPILE=gcc
COMPILEPP=g++
OBJ_POSTFIX=.o
EXE_POSTFIX=
+FLAGS=
case $(uname | tr '[:upper:]' '[:lower:]') in
*darwin*)
if command -v clang >/dev/null 2>&1; then
echo "C compiler found - Clang"
COMPILE=clang
- COMPILEPP=clang
+ COMPILEPP=clang++
elif command -v gcc >/dev/null 2>&1; then
echo "C compiler found - GCC"
else
@@ -21,11 +22,22 @@ case $(uname | tr '[:upper:]' '[:lower:]') in
fi
;;
*msys*|*cygwin*|*mingw*|*nt*|*win*)
- echo "C compiler found - MSVC"
- COMPILE=cl.exe
- COMPILEPP=cl.exe
- OBJ_POSTFIX=.obj
- EXE_POSTFIX=.exe
+ if command -v cl.exe >/dev/null 2>&1; then
+ echo "C compiler found - MSVC"
+ COMPILE=cl.exe
+ COMPILEPP=cl.exe
+ OBJ_POSTFIX=.obj
+ EXE_POSTFIX=.exe
+ elif command -v gcc >/dev/null 2>&1; then
+ echo "C compiler found - GCC"
+ elif command -v clang >/dev/null 2>&1; then
+ echo "C compiler found - Clang"
+ COMPILE=clang
+ COMPILEPP=clang++
+ else
+ echo "C compiler not found"
+ exit 1
+ fi
;;
*)
if command -v gcc >/dev/null 2>&1; then
@@ -33,7 +45,7 @@ case $(uname | tr '[:upper:]' '[:lower:]') in
elif command -v clang >/dev/null 2>&1; then
echo "C compiler found - Clang"
COMPILE=clang
- COMPILEPP=clang
+ COMPILEPP=clang++
else
echo "C compiler not found"
exit 1
@@ -43,17 +55,36 @@ esac
echo ""
-$COMPILE -c -o "build/kit${OBJ_POSTFIX}" "source/kit/_static.c"
+if [ "$COMPILE" = "gcc" ] || [ "$COMPILE" = "clang" ]; then
+ if [ "$1" = "release" ]; then
+ FLAGS="-O3"
+ else
+ FLAGS="-O0 -fsanitize=undefined,address,leak"
+ fi
+else
+ if [ "$1" = "release" ]; then
+ FLAGS="\O2"
+ else
+ FLAGS="\Od"
+ fi
+fi
+
+$COMPILE -c -o "build/kit${OBJ_POSTFIX}" \
+ ${FLAGS} \
+ "source/kit/_static.c"
if [ ! $? -eq 0 ]; then
exit 1
fi
-$COMPILE -c -o "build/kit_test${OBJ_POSTFIX}" "source/kit_test/_static.c"
+$COMPILE -c -o "build/kit_test${OBJ_POSTFIX}" \
+ ${FLAGS} \
+ "source/kit_test/_static.c"
if [ ! $? -eq 0 ]; then
exit 1
fi
$COMPILE -o "build/kit_test_suite${EXE_POSTFIX}" \
+ ${FLAGS} \
"build/kit${OBJ_POSTFIX}" \
"build/kit_test${OBJ_POSTFIX}" \
"source/tests/_static.c"
@@ -62,6 +93,7 @@ if [ ! $? -eq 0 ]; then
fi
$COMPILE -o "build/test_too_many_assertions${EXE_POSTFIX}" \
+ ${FLAGS} \
"build/kit${OBJ_POSTFIX}" \
"build/kit_test${OBJ_POSTFIX}" \
"source/tests/test_too_many_assertions.c"
@@ -70,6 +102,7 @@ if [ ! $? -eq 0 ]; then
fi
$COMPILE -o "build/test_too_many_tests${EXE_POSTFIX}" \
+ ${FLAGS} \
"build/kit${OBJ_POSTFIX}" \
"build/kit_test${OBJ_POSTFIX}" \
"source/tests/test_too_many_tests.c"
@@ -78,6 +111,7 @@ if [ ! $? -eq 0 ]; then
fi
$COMPILEPP -o "build/test_cpp${EXE_POSTFIX}" \
+ ${FLAGS} \
"build/kit${OBJ_POSTFIX}" \
"build/kit_test${OBJ_POSTFIX}" \
"source/tests/test_cpp.cpp"
@@ -86,6 +120,7 @@ if [ ! $? -eq 0 ]; then
fi
$COMPILEPP -o "build/test_signals${EXE_POSTFIX}" \
+ ${FLAGS} \
"build/kit${OBJ_POSTFIX}" \
"build/kit_test${OBJ_POSTFIX}" \
"source/tests/test_signals.cpp"
diff --git a/source/kit_test/test.c b/source/kit_test/test.c
index 41ee715..86ababa 100644
--- a/source/kit_test/test.c
+++ b/source/kit_test/test.c
@@ -181,7 +181,9 @@ int kit_run_tests(int argc, char **argv) {
int duration = (int) (ns_to_ms(end.tv_nsec - begin.tv_nsec) +
sec_to_ms(end.tv_sec - begin.tv_sec));
- for (j = 0; j < kit_tests_list.v[i].assertions; j++)
+ for (j = 0; j < kit_tests_list.v[i].assertions &&
+ j < KIT_TEST_ASSERTIONS_LIMIT;
+ j++)
if (kit_tests_list.v[i].status[j] == 0) {
fail_assertion_count++;
test_status = 0;