From eb3a527a254731929cc45e90dcbc8d6477a99054 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 17 Mar 2015 09:08:09 -0700 Subject: 946 - selectively run just some tests --- cpp/001test | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'cpp/001test') diff --git a/cpp/001test b/cpp/001test index 32014689..f0cb2c15 100644 --- a/cpp/001test +++ b/cpp/001test @@ -40,8 +40,25 @@ long Num_failures = 0; } :(before "End Main") -if (argc > 1 && is_equal(argv[1], "test")) { +if (argc == 2 && is_equal(argv[1], "test")) { run_tests(); + cerr << '\n'; + if (Num_failures > 0) + cerr << Num_failures << " failure" + << (Num_failures > 1 ? "s" : "") + << '\n'; + return 0; +} +// pass in a set of line numbers in test_file to run just those tests +if (argc > 2 && is_equal(argv[1], "test")) { + for (int i = 2; i < argc; ++i) { + run_test(to_int(argv[i])-1); + } + cerr << '\n'; + if (Num_failures > 0) + cerr << Num_failures << " failure" + << (Num_failures > 1 ? "s" : "") + << '\n'; return 0; } @@ -50,25 +67,30 @@ void run_tests() { time_t t; time(&t); cerr << "C tests: " << ctime(&t); for (unsigned long i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) { - setup(); - // End Test Setup - (*Tests[i])(); - if (Passed) cerr << "."; - // Test Teardown - // End Test Teardown + run_test(i); } +} - cerr << '\n'; - if (Num_failures > 0) - cerr << Num_failures << " failure" - << (Num_failures > 1 ? "s" : "") - << '\n'; +void run_test(int i) { + setup(); + // End Test Setup + (*Tests[i])(); + if (Passed) cerr << "."; + // Test Teardown + // End Test Teardown } bool is_equal(char* s, const char* lit) { return strncmp(s, lit, strlen(lit)) == 0; } +int to_int(string n) { + char* end = NULL; + int result = strtol(n.c_str(), &end, /*any base*/0); + assert(*end == '\0'); + return result; +} + :(before "End Includes") #include using std::istream; -- cgit 1.4.1-2-gfad0