[augeas-devel] [PATCH 01/10] Allow running individual tests with test-run
lutter at redhat.com
lutter at redhat.com
Tue May 22 00:44:28 UTC 2012
From: David Lutterkort <lutter at redhat.com>
Invoking 'test-run t1 t2 t3' will only run tests t1, t2 and t3
* tests/test-xpath.c: move checking if a test is mentioned in argv to
cutest
* tests/cutest.c, tests/cutest.h: add should_run
* Makefile.am: test-xpath now uses cutest.[ch]
* tests/test-run.c (run_tests): check if tests is mentioned on cmd line
---
tests/Makefile.am | 2 +-
tests/cutest.c | 9 +++++++++
tests/cutest.h | 4 ++++
tests/test-run.c | 8 +++++---
tests/test-xpath.c | 8 +++-----
5 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 324ce6b..e146c3f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -206,7 +206,7 @@ INCLUDES = -I$(top_srcdir)/src
fatest_SOURCES = fatest.c cutest.c cutest.h $(top_srcdir)/src/memory.c $(top_srcdir)/src/memory.h
fatest_LDADD = $(top_builddir)/src/libfa.la $(LIBXML_LIBS) $(GNULIB)
-test_xpath_SOURCES = test-xpath.c $(top_srcdir)/src/memory.c
+test_xpath_SOURCES = test-xpath.c cutest.c cutest.h $(top_srcdir)/src/memory.c
test_xpath_LDADD = $(top_builddir)/src/libaugeas.la $(LIBXML_LIBS) $(GNULIB)
test_load_SOURCES = test-load.c cutest.c cutest.h $(top_srcdir)/src/memory.c $(top_srcdir)/src/memory.h
diff --git a/tests/cutest.c b/tests/cutest.c
index 3c8962c..493f037 100644
--- a/tests/cutest.c
+++ b/tests/cutest.c
@@ -339,6 +339,15 @@ void run(CuTest *tc, const char *format, ...) {
free(command);
}
+int should_run(const char *name, int argc, char **argv) {
+ if (argc == 0)
+ return 1;
+ for (int i=0; i < argc; i++)
+ if (STREQ(argv[i], name))
+ return 1;
+ return 0;
+}
+
/*
* Local variables:
* indent-tabs-mode: nil
diff --git a/tests/cutest.h b/tests/cutest.h
index 99e2d34..1f3b02e 100644
--- a/tests/cutest.h
+++ b/tests/cutest.h
@@ -130,6 +130,10 @@ void CuSuiteDetails(CuSuite* testSuite, char **details);
/* Run a command */
void run(CuTest *tc, const char *format, ...);
+
+/* Return 1 if NAME is one of the ARGV, or if ARGC == 0; return 0 otherwise */
+int should_run(const char *name, int argc, char **argv);
+
#endif /* CU_TEST_H */
/*
diff --git a/tests/test-run.c b/tests/test-run.c
index bcae5f4..8f71225 100644
--- a/tests/test-run.c
+++ b/tests/test-run.c
@@ -222,17 +222,19 @@ static int run_one_test(struct test *test) {
goto done;
}
-static int run_tests(struct test *tests) {
+static int run_tests(struct test *tests, int argc, char **argv) {
int result = EXIT_SUCCESS;
list_for_each(t, tests) {
+ if (! should_run(t->name, argc, argv))
+ continue;
if (run_one_test(t) < 0)
result = EXIT_FAILURE;
}
return result;
}
-int main(void) {
+int main(int argc, char **argv) {
struct test *tests;
abs_top_srcdir = getenv("abs_top_srcdir");
@@ -240,7 +242,7 @@ int main(void) {
die("env var abs_top_srcdir must be set");
tests = read_tests();
- return run_tests(tests);
+ return run_tests(tests, argc - 1, argv + 1);
}
/*
diff --git a/tests/test-xpath.c b/tests/test-xpath.c
index 42a4b91..313c033 100644
--- a/tests/test-xpath.c
+++ b/tests/test-xpath.c
@@ -30,6 +30,8 @@
#include <internal.h>
#include <memory.h>
+#include "cutest.h"
+
static const char *abs_top_srcdir;
static char *root;
@@ -336,11 +338,7 @@ static int run_tests(struct test *tests, int argc, char **argv) {
die("aug_defvar $php");
list_for_each(t, tests) {
- int skip = (argc > 0);
- for (int i=0; i < argc; i++)
- if (STREQ(argv[i], t->name))
- skip = 0;
- if (skip)
+ if (! should_run(t->name, argc, argv))
continue;
if (run_one_test(aug, t) < 0)
result = EXIT_FAILURE;
--
1.7.7.6
More information about the augeas-devel
mailing list