Browse Source

ENH: Generate code to setup MSVC debug library hook. The test driver program will not display error dialogs if DART_TEST_FROM_DART is set in the environment.

Brad King 23 years ago
parent
commit
e9e3855c65
1 changed files with 29 additions and 9 deletions
  1. 29 9
      Source/cmCreateTestSourceList.cxx

+ 29 - 9
Source/cmCreateTestSourceList.cxx

@@ -97,6 +97,21 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
     "#include <stdio.h>\n"
     "#include <stdio.h>\n"
     "#include <string.h>\n"
     "#include <string.h>\n"
     "#include <stdlib.h>\n";
     "#include <stdlib.h>\n";
+  fout <<
+    "#if defined(_MSC_VER) && defined(_DEBUG)\n"
+    "/* MSVC debug hook to prevent dialogs when running from DART.  */\n"
+    "# include <crtdbg.h>\n"
+    "static int TestDriverDebugReport(int type, char* message, int* retVal)\n"
+    "{\n"
+    "  (void)type; (void)retVal;\n"
+    "  if(getenv(\"DART_TEST_FROM_DART\"))\n"
+    "    {\n"
+    "    fprintf(stderr, message);\n"
+    "    exit(1);\n"
+    "    }\n"
+    "  return 0;\n"
+    "}\n"
+    "#endif\n";
   if(extraInclude.size())
   if(extraInclude.size())
     {
     {
     fout << "#include \"" << extraInclude << "\"\n";
     fout << "#include \"" << extraInclude << "\"\n";
@@ -104,7 +119,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
   
   
   fout <<
   fout <<
     "\n"
     "\n"
-    "// Forward declare test functions\n"
+    "/* Forward declare test functions. */\n"
     "\n";
     "\n";
 
 
   std::vector<std::string>::iterator testsBegin = i;
   std::vector<std::string>::iterator testsBegin = i;
@@ -143,7 +158,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
 
 
   fout << 
   fout << 
     "\n"
     "\n"
-    "// Create map\n"
+    "/* Create map.  */\n"
     "\n"
     "\n"
     "typedef int (*MainFuncPointer)(int , char*[]);\n"
     "typedef int (*MainFuncPointer)(int , char*[]);\n"
     "typedef struct\n"
     "typedef struct\n"
@@ -179,8 +194,8 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
   fout << 
   fout << 
     "};\n"
     "};\n"
     "\n"
     "\n"
-    "// Allocate and create a lowercased copy of string\n"
-    "// (note that it has to be free'd manually)\n"
+    "/* Allocate and create a lowercased copy of string\n"
+    "   (note that it has to be free'd manually) */\n"
     "\n"
     "\n"
     "char* lowercase(const char *string)\n"
     "char* lowercase(const char *string)\n"
     "{\n"
     "{\n"
@@ -205,19 +220,24 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
     "  int i, NumTests, testNum, partial_match;\n"
     "  int i, NumTests, testNum, partial_match;\n"
     "  char *arg, *test_name;\n"
     "  char *arg, *test_name;\n"
     "  \n"
     "  \n"
+    "#if defined(_MSC_VER) && defined(_DEBUG)\n"
+    "  /* Put in hook for debug library.  */\n"
+    "  _CrtSetReportHook(TestDriverDebugReport);\n"
+    "#endif\n"
+    "  \n"
     "  NumTests = " << numTests << ";\n"
     "  NumTests = " << numTests << ";\n"
     "  \n"
     "  \n"
-    "  // If no test name was given\n";
+    "  /* If no test name was given */\n";
   if(function.size())
   if(function.size())
     {
     {
-    fout << "  // process command line with user function\n"
+    fout << "  /* process command line with user function.  */\n"
          << "  " << function << "(&ac, &av);\n";
          << "  " << function << "(&ac, &av);\n";
     }
     }
   
   
   fout <<
   fout <<
     "  if (ac < 2)\n"
     "  if (ac < 2)\n"
     "    {\n"
     "    {\n"
-    "    // Ask for a test\n"
+    "    /* Ask for a test.  */\n"
     "    printf(\"Available tests:\\n\");\n"
     "    printf(\"Available tests:\\n\");\n"
     "    for (i =0; i < NumTests; ++i)\n"
     "    for (i =0; i < NumTests; ++i)\n"
     "      {\n"
     "      {\n"
@@ -234,7 +254,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
     "    return (*cmakeGeneratedFunctionMapEntries[testNum].func)(ac-1, av+1);\n"
     "    return (*cmakeGeneratedFunctionMapEntries[testNum].func)(ac-1, av+1);\n"
     "    }\n"
     "    }\n"
     "  \n"
     "  \n"
-    "  // If partial match is requested\n"
+    "  /* If partial match is requested.  */\n"
     "  partial_match = (strcmp(av[1], \"-R\") == 0) ? 1 : 0;\n"
     "  partial_match = (strcmp(av[1], \"-R\") == 0) ? 1 : 0;\n"
     "  if (partial_match && ac < 3)\n"
     "  if (partial_match && ac < 3)\n"
     "    {\n"
     "    {\n"
@@ -262,7 +282,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
     "    }\n"
     "    }\n"
     "  free(arg);\n"
     "  free(arg);\n"
     "  \n"
     "  \n"
-    "  // Nothing was run, display the test names\n"
+    "  /* Nothing was run, display the test names.  */\n"
     "  printf(\"Available tests:\\n\");\n"
     "  printf(\"Available tests:\\n\");\n"
     "  for (i =0; i < NumTests; ++i)\n"
     "  for (i =0; i < NumTests; ++i)\n"
     "    {\n"
     "    {\n"