aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2019-11-28 10:44:17 +0100
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2019-11-28 10:44:17 +0100
commitf94149602d4daefa63cad754495024b725bd38fc (patch)
tree1c59cebc7fdd89069dcc1203ae7601e0e18f539c
parentf54f6a1638a68212ad29bdfd71c14e9c10aeeab1 (diff)
downloadmtest-f94149602d4daefa63cad754495024b725bd38fc.tar.gz
mtest-f94149602d4daefa63cad754495024b725bd38fc.tar.bz2
mtest-f94149602d4daefa63cad754495024b725bd38fc.zip
retab
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--mtest.h190
-rwxr-xr-xmtest.sh116
2 files changed, 148 insertions, 158 deletions
diff --git a/mtest.h b/mtest.h
index db8c4de..f442c12 100644
--- a/mtest.h
+++ b/mtest.h
@@ -54,15 +54,15 @@
========================================================================== */
-#define mt_defs() \
- const char *curr_test; \
- int mt_test_status; \
- int mt_total_tests = 0; \
- int mt_total_failed = 0; \
- int mt_total_checks = 0; \
- int mt_checks_failed = 0; \
- static void (*mt_prepare_test)(void); \
- static void (*mt_cleanup_test)(void)
+#define mt_defs() \
+ const char *curr_test; \
+ int mt_test_status; \
+ int mt_total_tests = 0; \
+ int mt_total_failed = 0; \
+ int mt_total_checks = 0; \
+ int mt_checks_failed = 0; \
+ static void (*mt_prepare_test)(void); \
+ static void (*mt_cleanup_test)(void)
/* ==========================================================================
@@ -72,15 +72,15 @@
========================================================================== */
-#define mt_defs_ext() \
- extern const char *curr_test; \
- extern int mt_test_status; \
- extern int mt_total_tests; \
- extern int mt_total_failed; \
- extern int mt_total_checks; \
- extern int mt_checks_failed; \
- static void (*mt_prepare_test)(void); \
- static void (*mt_cleanup_test)(void)
+#define mt_defs_ext()\
+ extern const char *curr_test; \
+ extern int mt_test_status; \
+ extern int mt_total_tests; \
+ extern int mt_total_failed; \
+ extern int mt_total_checks; \
+ extern int mt_checks_failed; \
+ static void (*mt_prepare_test)(void); \
+ static void (*mt_cleanup_test)(void)
/* ==========================================================================
@@ -107,21 +107,19 @@
========================================================================== */
-#define mt_run_named(f, n) do { \
- curr_test = n; \
- mt_test_status = 0; \
- ++mt_total_tests; \
- if (mt_prepare_test) mt_prepare_test(); \
- f(); \
- if (mt_cleanup_test) mt_cleanup_test(); \
- if (mt_test_status != 0) \
- { \
- fprintf(stdout, "not ok %d - %s\n", mt_total_tests, curr_test); \
- ++mt_total_failed; \
- } \
- else \
- fprintf(stdout, "ok %d - %s\n", mt_total_tests, curr_test); \
- } while(0)
+#define mt_run_named(f, n) do { \
+ curr_test = n; \
+ mt_test_status = 0; \
+ ++mt_total_tests; \
+ if (mt_prepare_test) mt_prepare_test(); \
+ f(); \
+ if (mt_cleanup_test) mt_cleanup_test(); \
+ if (mt_test_status != 0) { \
+ fprintf(stdout, "not ok %d - %s\n", mt_total_tests, curr_test); \
+ ++mt_total_failed; \
+ } else \
+ fprintf(stdout, "ok %d - %s\n", mt_total_tests, curr_test); \
+} while(0)
/* ==========================================================================
@@ -132,21 +130,19 @@
========================================================================== */
-#define mt_run_param_named(f, p, n) do { \
- curr_test = n; \
- mt_test_status = 0; \
- ++mt_total_tests; \
- if (mt_prepare_test) mt_prepare_test(); \
- f(p); \
- if (mt_cleanup_test) mt_cleanup_test(); \
- if (mt_test_status != 0) \
- { \
- fprintf(stdout, "not ok %d - %s\n", mt_total_tests, curr_test); \
- ++mt_total_failed; \
- } \
- else \
- fprintf(stdout, "ok %d - %s\n", mt_total_tests, curr_test); \
- } while(0)
+#define mt_run_param_named(f, p, n) do { \
+ curr_test = n; \
+ mt_test_status = 0; \
+ ++mt_total_tests; \
+ if (mt_prepare_test) mt_prepare_test(); \
+ f(p); \
+ if (mt_cleanup_test) mt_cleanup_test(); \
+ if (mt_test_status != 0) { \
+ fprintf(stdout, "not ok %d - %s\n", mt_total_tests, curr_test); \
+ ++mt_total_failed; \
+ } else \
+ fprintf(stdout, "ok %d - %s\n", mt_total_tests, curr_test); \
+} while(0)
/* ==========================================================================
@@ -155,16 +151,16 @@
========================================================================== */
-#define mt_assert(e) do { \
- ++mt_total_checks; \
- if (!(e)) \
- { \
- fprintf(stderr, "# assert [%s:%d] %s, %s\n", \
- __FILE__, __LINE__, curr_test, #e); \
- mt_test_status = -1; \
- ++mt_checks_failed; \
- return; \
- } } while (0)
+#define mt_assert(e) do { \
+ ++mt_total_checks; \
+ if (!(e)) { \
+ fprintf(stderr, "# assert [%s:%d] %s, %s\n", \
+ __FILE__, __LINE__, curr_test, #e); \
+ mt_test_status = -1; \
+ ++mt_checks_failed; \
+ return; \
+ } \
+} while (0)
/* ==========================================================================
@@ -173,15 +169,15 @@
========================================================================== */
-#define mt_fail(e) do { \
- ++mt_total_checks; \
- if (!(e)) \
- { \
- fprintf(stderr, "# assert [%s:%d] %s, %s\n", \
- __FILE__, __LINE__, curr_test, #e); \
- mt_test_status = -1; \
- ++mt_checks_failed; \
- } } while (0)
+#define mt_fail(e) do { \
+ ++mt_total_checks; \
+ if (!(e)) { \
+ fprintf(stderr, "# assert [%s:%d] %s, %s\n", \
+ __FILE__, __LINE__, curr_test, #e); \
+ mt_test_status = -1; \
+ ++mt_checks_failed; \
+ } \
+} while (0)
/* ==========================================================================
@@ -189,18 +185,18 @@
========================================================================== */
-#define mt_fok(e) do { \
- int ret; \
- ++mt_total_checks; \
- if ((ret = e) != 0) \
- { \
- fprintf(stderr, "# assert [%s:%d] %s, %s != ok\n", \
- __FILE__, __LINE__, curr_test, #e); \
- fprintf(stderr, "# assert [%s:%d] %s, return: %d, errno: %d\n", \
- __FILE__, __LINE__, curr_test, ret, errno); \
- mt_test_status = -1; \
- ++mt_checks_failed; \
- } } while (0)
+#define mt_fok(e) do { \
+ int ret; \
+ ++mt_total_checks; \
+ if ((ret = e) != 0) { \
+ fprintf(stderr, "# assert [%s:%d] %s, %s != ok\n", \
+ __FILE__, __LINE__, curr_test, #e); \
+ fprintf(stderr, "# assert [%s:%d] %s, return: %d, errno: %d\n", \
+ __FILE__, __LINE__, curr_test, ret, errno); \
+ mt_test_status = -1; \
+ ++mt_checks_failed; \
+ } \
+} while (0)
/* ==========================================================================
@@ -209,15 +205,14 @@
========================================================================== */
-#define mt_ferr(e, errn) do { \
- errno = 0; \
- mt_fail(e == -1); \
- mt_fail(errno == errn); \
- if (errno != errn) \
- { \
- fprintf(stderr, "# assert [%s:%d] %s, got errno: %d\n", \
- __FILE__, __LINE__, curr_test, errno); \
- } } while (0)
+#define mt_ferr(e, errn) do { \
+ errno = 0; \
+ mt_fail(e == -1); \
+ mt_fail(errno == errn); \
+ if (errno != errn) \
+ fprintf(stderr, "# assert [%s:%d] %s, got errno: %d\n", \
+ __FILE__, __LINE__, curr_test, errno); \
+} while (0)
/* ==========================================================================
@@ -228,12 +223,13 @@
========================================================================== */
-#define mt_return() do { \
- fprintf(stdout, "1..%d\n", mt_total_tests); \
- fprintf(stderr, "# total tests.......:%4d\n", mt_total_tests); \
- fprintf(stderr, "# passed tests......:%4d\n", mt_total_tests - mt_total_failed); \
- fprintf(stderr, "# failed tests......:%4d\n", mt_total_failed); \
- fprintf(stderr, "# total checks......:%4d\n", mt_total_checks); \
- fprintf(stderr, "# passed checks.....:%4d\n", mt_total_checks - mt_checks_failed); \
- fprintf(stderr, "# failed checks.....:%4d\n", mt_checks_failed); \
- return mt_total_failed > 254 ? 254 : mt_total_failed; } while(0)
+#define mt_return() do { \
+ fprintf(stdout, "1..%d\n", mt_total_tests); \
+ fprintf(stderr, "# total tests.......:%4d\n", mt_total_tests); \
+ fprintf(stderr, "# passed tests......:%4d\n", mt_total_tests - mt_total_failed); \
+ fprintf(stderr, "# failed tests......:%4d\n", mt_total_failed); \
+ fprintf(stderr, "# total checks......:%4d\n", mt_total_checks); \
+ fprintf(stderr, "# passed checks.....:%4d\n", mt_total_checks - mt_checks_failed); \
+ fprintf(stderr, "# failed checks.....:%4d\n", mt_checks_failed); \
+ return mt_total_failed > 254 ? 254 : mt_total_failed; \
+} while(0)
diff --git a/mtest.sh b/mtest.sh
index fc4a934..7224e89 100755
--- a/mtest.sh
+++ b/mtest.sh
@@ -74,9 +74,9 @@ mt_current_test="none"
mt_run()
{
- function_name=$1
- shift
- mt_run_named $function_name $function_name $@
+ function_name=$1
+ shift
+ mt_run_named $function_name $function_name $@
}
@@ -108,32 +108,29 @@ mt_run()
mt_run_named()
{
- function_name="$1"
- mt_current_test="$2"
- mt_test_status=0
- mt_total_tests=$((mt_total_tests + 1))
-
- if type mt_prepare_test > /dev/null 2>&1
- then
- mt_prepare_test
- fi
-
- shift
- shift
- eval $function_name $@
-
- if type mt_cleanup_test > /dev/null 2>&1
- then
- mt_cleanup_test
- fi
-
- if [ $mt_test_status -ne 0 ]
- then
- echo "not ok $mt_total_tests - $mt_current_test"
- mt_total_failed=$((mt_total_failed + 1))
- else
- echo "ok $mt_total_tests - $mt_current_test"
- fi
+ function_name="$1"
+ mt_current_test="$2"
+ mt_test_status=0
+ mt_total_tests=$((mt_total_tests + 1))
+
+ if type mt_prepare_test > /dev/null 2>&1; then
+ mt_prepare_test
+ fi
+
+ shift
+ shift
+ eval $function_name $@
+
+ if type mt_cleanup_test > /dev/null 2>&1; then
+ mt_cleanup_test
+ fi
+
+ if [ $mt_test_status -ne 0 ]; then
+ echo "not ok $mt_total_tests - $mt_current_test"
+ mt_total_failed=$((mt_total_failed + 1))
+ else
+ echo "ok $mt_total_tests - $mt_current_test"
+ fi
}
@@ -147,13 +144,12 @@ mt_run_named()
mt_fail()
{
- mt_total_checks=$(( mt_total_checks + 1 ))
- if ! eval $1
- then
- echo "# assert $mt_current_test, '$1'"
- mt_test_status=1
- mt_checks_failed=$(( mt_checks_failed + 1 ))
- fi
+ mt_total_checks=$(( mt_total_checks + 1 ))
+ if ! eval $1; then
+ echo "# assert $mt_current_test, '$1'"
+ mt_test_status=1
+ mt_checks_failed=$(( mt_checks_failed + 1 ))
+ fi
}
@@ -167,13 +163,12 @@ mt_fail()
mt_dfail()
{
- mt_total_checks=$(( mt_total_checks + 1 ))
- if ! $@
- then
- echo "# assert $mt_current_test, '$1'"
- mt_test_status=1
- mt_checks_failed=$(( mt_checks_failed + 1 ))
- fi
+ mt_total_checks=$(( mt_total_checks + 1 ))
+ if ! $@; then
+ echo "# assert $mt_current_test, '$1'"
+ mt_test_status=1
+ mt_checks_failed=$(( mt_checks_failed + 1 ))
+ fi
}
@@ -189,22 +184,21 @@ mt_dfail()
mt_return()
{
- echo "1..$mt_total_tests"
-
- mt_passed_tests=$((mt_total_tests - mt_total_failed))
- mt_passed_checks=$((mt_total_checks - mt_checks_failed))
-
- printf "# total tests.......: %4d\n" ${mt_total_tests}
- printf "# passed tests......: %4d\n" ${mt_passed_tests}
- printf "# failed tests......: %4d\n" ${mt_total_failed}
- printf "# total checks......: %4d\n" ${mt_total_checks}
- printf "# passed checks.....: %4d\n" ${mt_passed_checks}
- printf "# failed checks.....: %4d\n" ${mt_checks_failed}
-
- if [ $mt_total_failed -gt 254 ]
- then
- exit 254
- else
- exit $mt_total_failed
- fi
+ echo "1..$mt_total_tests"
+
+ mt_passed_tests=$((mt_total_tests - mt_total_failed))
+ mt_passed_checks=$((mt_total_checks - mt_checks_failed))
+
+ printf "# total tests.......: %4d\n" ${mt_total_tests}
+ printf "# passed tests......: %4d\n" ${mt_passed_tests}
+ printf "# failed tests......: %4d\n" ${mt_total_failed}
+ printf "# total checks......: %4d\n" ${mt_total_checks}
+ printf "# passed checks.....: %4d\n" ${mt_passed_checks}
+ printf "# failed checks.....: %4d\n" ${mt_checks_failed}
+
+ if [ $mt_total_failed -gt 254 ]; then
+ exit 254
+ else
+ exit $mt_total_failed
+ fi
}