From 8b4e1b66db3aaff505654cd0a71335b4b5c07fc6 Mon Sep 17 00:00:00 2001 From: Kevin Martin Jose Date: Fri, 5 Dec 2014 02:18:35 +0530 Subject: [PATCH] runtests now take commandline arguments --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 2 +- tests/test-runner.c | 74 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbec1ce..9e4a1e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ message ("Generating project ${PROJECT_NAME}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/deps/cmake_modules/") set(VARNAM_LIBRARY_NAME "varnam") +set(ARGTABLE_LIBRARY_NAME "argtable2") set(VARNAM_LIBRARY_NAME_STATIC "varnamstatic") set(DEPS_LIBRARY_NAME "deps") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a5dfac5..dda048b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,5 +34,5 @@ set(test_executable_name runtests) add_executable(${test_executable_name} test-runner.c ${TEST_FILES}) -target_link_libraries(${test_executable_name} ${VARNAM_LIBRARY_NAME} ${CHECK_LIBRARIES} m) +target_link_libraries(${test_executable_name} ${VARNAM_LIBRARY_NAME} ${ARGTABLE_LIBRARY_NAME} ${CHECK_LIBRARIES} m) diff --git a/tests/test-runner.c b/tests/test-runner.c index 9974b1a..35cb509 100644 --- a/tests/test-runner.c +++ b/tests/test-runner.c @@ -12,13 +12,50 @@ #include #include "testcases.h" #include +#include + +/*struct arg_file *suite; + struct arg_file *testcases; + struct arg_end *end;*/ int main(int argc, char **argv) { Suite *suite, *util, *commandline; SRunner *runner; - int failed, exit_code; + int failed, exit_code, nerrors; + struct arg_file *suite_arg; + struct arg_lit *help; + struct arg_lit *fork; + struct arg_file *test_arg; + struct arg_end *end; + + void *argtable[] = { + suite_arg = arg_filen(NULL, NULL, "", 0, 10, "The test suite to run"), + test_arg = arg_file0("t", NULL, "", "A test in the suite to run"), + help = arg_lit0("h", "help", "Display help text"), + fork = arg_lit0("f", NULL, "Run in forked mode"), + end = arg_end(20) + }; + + /*test_arg->hdr.flag |= ARG_HASOPTVALUE;*/ + nerrors = arg_parse(argc, argv, argtable); + + if(help->count > 0) + { + printf("usage : \n"); + arg_print_syntax(stdout, argtable, "\n"); + printf("Glossary : \n"); + arg_print_glossary(stdout, argtable, " %-25s %s\n"); + exit(0); + } + + if(nerrors > 0) + { + arg_print_errors(stdout, end, "runtest"); + exit(1); + } + /* Cleaning the output directory */ exit_code = system ("ruby test_output_cleanup.rb"); if (exit_code != 0) { @@ -44,8 +81,39 @@ int main(int argc, char **argv) srunner_add_suite (runner, commandline); srunner_set_log (runner, "testrun.log"); srunner_set_xml (runner, "testrun.xml"); - srunner_set_fork_status (runner, CK_NOFORK); - srunner_run_all (runner, CK_NORMAL); + + if(fork->count == 0) + { + printf("Running in no fork mode\n"); + srunner_set_fork_status (runner, CK_NOFORK); + } + else + printf("Running in forked mode\n"); + + + if(suite_arg->count == 0) + srunner_run_all (runner, CK_NORMAL); + else + { + int i; + + if(test_arg->count > 0 && suite_arg->count > 1) + { + printf("Only one suite and one test can be specified if a test argument is provided\nSee --help for more\n"); + exit(1); + } + else if(test_arg->count > 0) + srunner_run (runner, suite_arg->filename[0], test_arg->filename[0], CK_NOFORK); + else + { + /*If only suite names are specified*/ + for(i=0; icount; i++) + { + srunner_run (runner, suite_arg->filename[i], NULL, CK_NOFORK); + } + } + } + failed = srunner_ntests_failed (runner); srunner_free (runner);