aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-03-15 13:36:52 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-03-28 13:32:02 +0100
commit262e7d00d0bfea6315f854818a561d9e45a34673 (patch)
treee755f7b882d420397a1e298d4acb21e41a1ee0a0
parent4c5639246c1cce6e695eba66cfd9d0ff92af6a91 (diff)
downloadcmocka-262e7d00d0bfea6315f854818a561d9e45a34673.tar.gz
cmocka-262e7d00d0bfea6315f854818a561d9e45a34673.tar.xz
cmocka-262e7d00d0bfea6315f854818a561d9e45a34673.zip
cmocka: Add cmocka_set_skip_filter() to skip tests
The introduced cmocka_set_skip_filter() allows setting a filter for tests to be skipped. It supports the same wildcards allowed for cmocka_set_test_filter() (i.e. '*' or '?'). Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/cmocka.h12
-rw-r--r--src/cmocka.c21
-rw-r--r--src/cmocka.def1
3 files changed, 31 insertions, 3 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index 3fb4767..9b47ceb 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -2367,6 +2367,18 @@ void cmocka_set_message_output(enum cm_message_output output);
*/
void cmocka_set_test_filter(const char *pattern);
+/**
+ * @brief Set a pattern to skip tests matching the pattern.
+ *
+ * This allows to filter tests and skip the ones matching the pattern. The
+ * pattern can include two wildards. The first is '*', a wildcard that matches
+ * zero or more characters, or ‘?’, a wildcard that matches exactly one
+ * character.
+ *
+ * @param[in] pattern The pattern to match, e.g. "test_wurst*"
+ */
+void cmocka_set_skip_filter(const char *pattern);
+
/** @} */
#endif /* CMOCKA_H_ */
diff --git a/src/cmocka.c b/src/cmocka.c
index 6bfc831..6233155 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -313,6 +313,8 @@ static enum cm_message_output global_msg_output = CM_OUTPUT_STDOUT;
static const char *global_test_filter_pattern;
+static const char *global_skip_filter_pattern;
+
#ifndef _WIN32
/* Signals caught by exception_handler(). */
static const int exception_signals[] = {
@@ -2693,6 +2695,11 @@ void cmocka_set_test_filter(const char *pattern)
global_test_filter_pattern = pattern;
}
+void cmocka_set_skip_filter(const char *pattern)
+{
+ global_skip_filter_pattern = pattern;
+}
+
/****************************************************************************
* TIME CALCULATIONS
****************************************************************************/
@@ -2979,10 +2986,18 @@ int _cmocka_run_group_tests(const char *group_name,
|| tests[i].setup_func != NULL
|| tests[i].teardown_func != NULL)) {
if (global_test_filter_pattern != NULL) {
- int ok;
+ int match;
+
+ match = c_strmatch(tests[i].name, global_test_filter_pattern);
+ if (!match) {
+ continue;
+ }
+ }
+ if (global_skip_filter_pattern != NULL) {
+ int match;
- ok = c_strmatch(tests[i].name, global_test_filter_pattern);
- if (!ok) {
+ match = c_strmatch(tests[i].name, global_skip_filter_pattern);
+ if (match) {
continue;
}
}
diff --git a/src/cmocka.def b/src/cmocka.def
index 10522f0..3633dc1 100644
--- a/src/cmocka.def
+++ b/src/cmocka.def
@@ -43,6 +43,7 @@ EXPORTS
cm_print_error
cmocka_set_message_output
cmocka_set_test_filter
+ cmocka_set_skip_filter
global_expect_assert_env
global_expecting_assert
global_last_failed_assert