'mutest_set_verbose_level', argtype=[c_int])
@property
- def passed_count(self):
- return get_val(self.so, 'mutest_passed_count')
+ def passed_checks(self):
+ return get_val(self.so, 'mutest_passed_checks')
@property
- def failed_count(self):
- return get_val(self.so, 'mutest_failed_count')
+ def failed_checks(self):
+ return get_val(self.so, 'mutest_failed_checks')
def run(self):
global verbose_level
self.set_verbose_level(verbose_level)
self.reset_counters()
self.testcase()
- return (self.passed_count, self.failed_count)
+ return (self.passed_checks, self.failed_checks)
class TestSuiteInfo (object):
* http://blitiri.com.ar/p/bola/
*
* This header file should be included in the source files that will make up
- * a test suite. If you implement your mu_run_suites() function yourself, you
- * probably will need to include this header too (see mkmutest).
+ * a test suite. It's used for both C and Python implementation, but when
+ * using the Python implementation you should define the MUTEST_PY macro.
+ * If you implement your mu_run_suites() function yourself, you probably will
+ * need to include this header too (see mkmutest).
*
* Please, read the README file for more details.
*/
extern "C" {
#endif
+/* verbosity level (each level shows all the previous levels too) */
+enum {
+ MU_QUIET = 0, /* be completely quiet */
+ MU_ERROR, /* shows errors only */
+ MU_SUMMARY, /* shows a summary */
+ MU_SUITE, /* shows test suites progress */
+ MU_CASE, /* shows test cases progress */
+ MU_CHECK /* shows the current running check */
+};
+
+/* print a message according to the verbosity level */
+#define mu_print(level, ...) \
+ do { \
+ if (mutest_verbose_level >= level) { \
+ if (mutest_verbose_level == MU_ERROR) \
+ fprintf(stderr, __VA_ARGS__); \
+ else \
+ fprintf(stdout, __VA_ARGS__); \
+ } \
+ } while (0)
+
/* check that an expression evaluates to true, continue if the check fails */
#define mu_check(exp) \
do { \
} \
} while (0)
-/*
- * you don't need to pay any attention to what's next, unless you want to do
- * some customization, of course, in which case, you're encouraged to take
- * a look an play =)
- */
-
-/* verbosity level (each level shows all the previous levels too) */
-enum {
- MU_QUIET = 0, /* be completely quiet */
- MU_ERROR, /* shows errors only */
- MU_SUMMARY, /* shows a summary */
- MU_SUITE, /* shows test suites progress */
- MU_CASE, /* shows test cases progress */
- MU_CHECK /* shows the current running check */
-};
-
-/* print a message according to the verbosity level */
-#define mu_print(level, ...) \
- do { \
- if (mutest_verbose_level >= level) { \
- if (mutest_verbose_level == MU_ERROR) \
- fprintf(stderr, __VA_ARGS__); \
- else \
- fprintf(stdout, __VA_ARGS__); \
- } \
- } while (0)
+#ifndef MUTEST_PY /* we are using the C implementation */
/*
* this function implements the test suites execution, you should generate
/* verbosity */
extern int mutest_verbose_level;
+#else /* MUTEST_PY is defined, using the Python implementation */
+
+/* this increments when the "API" changes, it's just for sanity check */
+int mutest_api_version = 1;
+
+int mutest_case_failed; /* unused, for C implementation compatibility */
+
+int mutest_passed_checks;
+int mutest_failed_checks;
+void mutest_reset_counters() {
+ mutest_passed_checks = 0;
+ mutest_failed_checks = 0;
+}
+
+int mutest_verbose_level = MU_ERROR;
+void mutest_set_verbose_level(int val) {
+ mutest_verbose_level = val;
+}
+
+#endif /* MUTEST_PY */
+
#ifdef __cplusplus
}
#endif
+++ /dev/null
-/*
- * This file is part of mutest, a simple micro unit testing framework for C.
- *
- * mutest was written by Leandro Lucarella <llucax@gmail.com> and is released
- * under the BOLA license, please see the LICENSE file or visit:
- * http://blitiri.com.ar/p/bola/
- *
- * This is a Python implementation of the mutest main idea. This header file
- * should be included in the source files that will make up a test suite, as
- * a dynamic shared object (.so file).
- *
- * Please, read the README file for more details.
- */
-
-#include <stdio.h> /* printf(), fprintf() */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* this increments when the "API" changes */
-int mutest_api_version = 1;
-
-int mutest_passed_count;
-int mutest_failed_count;
-void mutest_reset_counters() {
- mutest_passed_count = 0;
- mutest_failed_count = 0;
-}
-
-/*
- * Verbose level:
- * 0: quiet
- * 1: errors
- * 2: summary
- * 3: suites
- * 4: cases
- * 5: checks
- */
-int mutest_verbose_level = 1;
-void mutest_set_verbose_level(int val) {
- mutest_verbose_level = val;
-}
-
-#define mu_check(exp) \
- do { \
- if (exp) { \
- ++mutest_passed_count; \
- if (mutest_verbose_level >= 5) \
- printf("%s:%d: mu_check(%s) passed\n", \
- __FILE__, __LINE__, #exp); \
- } else { \
- ++mutest_failed_count; \
- if (mutest_verbose_level) \
- fprintf(stderr, "%s:%d: mu_check(%s) " \
- "failed, resuming test case\n", \
- __FILE__, __LINE__, #exp); \
- } \
- } while (0)
-
-#define mu_ensure(exp) \
- do { \
- if (exp) { \
- ++mutest_passed_count; \
- if (mutest_verbose_level >=5) \
- printf("%s:%d: mu_ensure(%s) passed\n", \
- __FILE__, __LINE__, #exp); \
- } else { \
- ++mutest_failed_count; \
- if (mutest_verbose_level) \
- fprintf(stderr, "%s:%d: mu_ensure(%s) " \
- "failed, aborting test case\n", \
- __FILE__, __LINE__, #exp); \
- return; \
- } \
- } while (0)
-
-#ifdef __cplusplus
-}
-#endif
-
TARGET = tester
RUNNER_SRC = test_suite_runner.c
MKMUTEST = ../mkmutest
-MUTEST = ../py/mutest
+MUTEST = ../mutest
MUTEST_H = ../mutest.h
MUTEST_C = ../mutest.c
#include "factorial.h"
-#ifdef MUTEST_PY
-#include "../py/mutest.h"
-#else
#include "../mutest.h"
-#endif
void mu_test_factorial_zero() {
unsigned x = factorial(0);
* Please, read the README file for more details.
*/
-#ifdef MUTEST_PY
-#include "../py/mutest.h"
-#else
#include "../mutest.h"
-#endif
static int ret = 0;
#include "sum.h"
#include <stdlib.h> /* malloc(), free() */
-#ifdef MUTEST_PY
-#include "../py/mutest.h"
-#else
#include "../mutest.h"
-#endif
/* unused, just for ilustrate the test suite initialization/termination */
static char* global;