Explorar o código

Merge topic 'test_driver_tap13_support'

3f6ff4b5db create_test_sourcelist: add test driver option to run all tests
a3aa5596a1 Tests: Isolate TestDriver build directories

Acked-by: Kitware Robot <[email protected]>
Merge-request: !3661
Brad King %!s(int64=4) %!d(string=hai) anos
pai
achega
34f316b484
Modificáronse 2 ficheiros con 74 adicións e 5 borrados
  1. 42 1
      Templates/TestDriver.cxx.in
  2. 32 4
      Tests/CMakeLists.txt

+ 42 - 1
Templates/TestDriver.cxx.in

@@ -2,6 +2,7 @@
 #include <stdio.h>  /* NOLINT */
 #include <stdio.h>  /* NOLINT */
 #include <stdlib.h> /* NOLINT */
 #include <stdlib.h> /* NOLINT */
 #include <string.h> /* NOLINT */
 #include <string.h> /* NOLINT */
+#include <time.h>
 
 
 #if defined(_MSC_VER)
 #if defined(_MSC_VER)
 #pragma warning(disable : 4996) /* deprecation */
 #pragma warning(disable : 4996) /* deprecation */
@@ -62,11 +63,23 @@ static char* lowercase(const char* string)
   return new_string;
   return new_string;
 }
 }
 
 
+int isTestSkipped(const char *name, int n_skipped_tests, char *skipped_tests[]) {
+  int i;
+  for (i = 0; i < n_skipped_tests; i++) {
+    if (strcmp(name, skipped_tests[i]) == 0) {
+      return 1;
+    }
+  }
+
+  return 0;
+}
+
 int main(int ac, char* av[])
 int main(int ac, char* av[])
 {
 {
   int i;
   int i;
   int testNum = 0;
   int testNum = 0;
   int partial_match;
   int partial_match;
+  int run_all;
   char *arg;
   char *arg;
   int testToRun = -1;
   int testToRun = -1;
 
 
@@ -95,15 +108,43 @@ int main(int ac, char* av[])
     av++;
     av++;
   }
   }
   partial_match = 0;
   partial_match = 0;
+  run_all = 0;
   arg = CM_NULL; /* NOLINT */
   arg = CM_NULL; /* NOLINT */
-  /* If partial match is requested.  */
+  /* If partial match or running all tests are requested.  */
   if (testToRun == -1 && ac > 1) {
   if (testToRun == -1 && ac > 1) {
     partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
     partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
+    run_all = (strcmp(av[1], "-A") == 0) ? 1 : 0;
   }
   }
   if (partial_match != 0 && ac < 3) {
   if (partial_match != 0 && ac < 3) {
     printf("-R needs an additional parameter.\n");
     printf("-R needs an additional parameter.\n");
     return -1;
     return -1;
   }
   }
+  if (run_all == 1) {
+    clock_t t;
+    int status = 0;
+    const char* status_message = NULL;
+    printf("TAP version 13\n");
+    printf("1..%d\n", NumTests);
+    for (i = 0; i < NumTests; ++i) {
+      const char *name = cmakeGeneratedFunctionMapEntries[i].name;
+      if (ac > 2) {
+        if (isTestSkipped(name, ac - 2, av + 2) == 1) {
+          printf("ok %d %s # SKIP\n", i + 1, name);
+          continue;
+        }
+      }
+      t = clock();
+      status = (*cmakeGeneratedFunctionMapEntries[i].func)(ac, av);
+      t = clock() - t;
+      double time_taken = ((double)t) / CLOCKS_PER_SEC;
+      status_message = (status == -1) ? "not ok" : "ok";
+      printf("%s %d %s # %f\n", status_message, i + 1, name, time_taken);
+    }
+    printf("All tests finished.\n");
+
+    return 0;
+  }
+
   if (testToRun == -1) {
   if (testToRun == -1) {
     arg = lowercase(av[1 + partial_match]);
     arg = lowercase(av[1 + partial_match]);
   }
   }

+ 32 - 4
Tests/CMakeLists.txt

@@ -1742,33 +1742,61 @@ if(BUILD_TESTING)
   add_test(testdriver1 ${CMAKE_CTEST_COMMAND}
   add_test(testdriver1 ${CMAKE_CTEST_COMMAND}
     --build-and-test
     --build-and-test
     "${CMake_SOURCE_DIR}/Tests/TestDriver"
     "${CMake_SOURCE_DIR}/Tests/TestDriver"
-    "${CMake_BINARY_DIR}/Tests/TestDriver"
+    "${CMake_BINARY_DIR}/Tests/TestDriver1"
     ${build_generator_args}
     ${build_generator_args}
     --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
     --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
     --build-project TestDriverTest
     --build-project TestDriverTest
     --test-command TestDriverTest test1
     --test-command TestDriverTest test1
     )
     )
+  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestDriver1")
 
 
   add_test(testdriver2 ${CMAKE_CTEST_COMMAND}
   add_test(testdriver2 ${CMAKE_CTEST_COMMAND}
     --build-and-test
     --build-and-test
     "${CMake_SOURCE_DIR}/Tests/TestDriver"
     "${CMake_SOURCE_DIR}/Tests/TestDriver"
-    "${CMake_BINARY_DIR}/Tests/TestDriver"
+    "${CMake_BINARY_DIR}/Tests/TestDriver2"
     ${build_generator_args}
     ${build_generator_args}
     --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
     --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
     --build-project TestDriverTest
     --build-project TestDriverTest
     --test-command TestDriverTest test2
     --test-command TestDriverTest test2
     )
     )
+  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestDriver2")
 
 
   add_test(testdriver3  ${CMAKE_CTEST_COMMAND}
   add_test(testdriver3  ${CMAKE_CTEST_COMMAND}
     --build-and-test
     --build-and-test
     "${CMake_SOURCE_DIR}/Tests/TestDriver"
     "${CMake_SOURCE_DIR}/Tests/TestDriver"
-    "${CMake_BINARY_DIR}/Tests/TestDriver"
+    "${CMake_BINARY_DIR}/Tests/TestDriver3"
     ${build_generator_args}
     ${build_generator_args}
     --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
     --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
     --build-project TestDriverTest
     --build-project TestDriverTest
     --test-command TestDriverTest subdir/test3
     --test-command TestDriverTest subdir/test3
     )
     )
-  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestDriver")
+  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestDriver3")
+
+  add_test(testdriver4  ${CMAKE_CTEST_COMMAND}
+    --build-and-test
+    "${CMake_SOURCE_DIR}/Tests/TestDriver"
+    "${CMake_BINARY_DIR}/Tests/TestDriver4"
+    ${build_generator_args}
+    --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
+    --build-project TestDriverTest
+    --test-command TestDriverTest -A test2
+    )
+  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestDriver4")
+
+  add_test(testdriver5  ${CMAKE_CTEST_COMMAND}
+    --build-and-test
+    "${CMake_SOURCE_DIR}/Tests/TestDriver"
+    "${CMake_BINARY_DIR}/Tests/TestDriver5"
+    ${build_generator_args}
+    --build-exe-dir "${CMake_BINARY_DIR}/Tests/Wrapping/bin"
+    --build-project TestDriverTest
+    --test-command TestDriverTest -A test2
+    )
+  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestDriver5")
+  set_tests_properties(testdriver5 PROPERTIES
+    PASS_REGULAR_EXPRESSION
+    "TAP version 13\n1\\.\\.3.+ok 1 test1 # [0-9]+\\.[0-9]+.*All tests finished."
+    )
 
 
   add_test(Dependency ${CMAKE_CTEST_COMMAND}
   add_test(Dependency ${CMAKE_CTEST_COMMAND}
     --build-and-test
     --build-and-test