summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2014-08-08 09:11:52 +0200
committerStef Walter <stef@thewalter.net>2014-08-08 09:11:52 +0200
commit2e503dccd889a3f83951830fda18c9357377693d (patch)
tree581a457c1462a2f6b5afa574262b4a33d6c314c2 /common
parent6a8843b3c5f6d44eb280a54653388a3de316f638 (diff)
common: Allow specifying which tests to run on command line
This modifies our common unit test code so we can specify full test paths on the command line, and restrict the run tests to the ones specified. Order is not respected at this time.
Diffstat (limited to 'common')
-rw-r--r--common/test.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/common/test.c b/common/test.c
index a006f74..c619b7d 100644
--- a/common/test.c
+++ b/common/test.c
@@ -206,6 +206,22 @@ p11_fixture (void (* setup) (void *),
test_push (&item);
}
+static int
+should_run_test (int argc,
+ char **argv,
+ test_item *item)
+{
+ int i;
+ if (argc == 0)
+ return 1;
+ for (i = 0; i < argc; i++) {
+ if (strcmp (argv[i], item->x.test.name) == 0)
+ return 1;
+ }
+
+ return 0;
+}
+
int
p11_test_run (int argc,
char **argv)
@@ -216,16 +232,28 @@ p11_test_run (int argc,
int count;
int ret = 0;
int setup;
+ int opt;
/* p11-kit specific stuff */
putenv ("P11_KIT_STRICT=1");
p11_debug_init ();
+ while ((opt = getopt (argc, argv, "")) != -1) {
+ switch (opt) {
+ default:
+ fprintf (stderr, "specify only test names on the command line\n");
+ return 2;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
assert (gl.number == 0);
gl.last = NULL;
for (item = gl.suite, count = 0; item != NULL; item = item->next) {
- if (item->type == TEST)
+ if (item->type == TEST && should_run_test (argc, argv, item))
count++;
}
@@ -243,6 +271,10 @@ p11_test_run (int argc,
}
assert (item->type == TEST);
+
+ if (!should_run_test (argc, argv, item))
+ continue;
+
gl.last = item;
gl.number++;
setup = 0;