Browse Source

Merge topic 'FindPython-update-tests'

3fad553ea5 FindPython: enhance Python3Embedded test

Acked-by: Kitware Robot <[email protected]>
Merge-request: !10021
Brad King 1 year ago
parent
commit
cb39fca27e
2 changed files with 27 additions and 17 deletions
  1. 16 11
      Tests/FindPython/CMakeLists.txt
  2. 11 6
      Tests/FindPython/display_time.c

+ 16 - 11
Tests/FindPython/CMakeLists.txt

@@ -342,16 +342,18 @@ if(CMake_TEST_FindPython3)
     --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
     )
 
-  add_test(NAME FindPython.Python3Embedded COMMAND
-    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
-    --build-and-test
-    "${CMake_SOURCE_DIR}/Tests/FindPython/Python3Embedded"
-    "${CMake_BINARY_DIR}/Tests/FindPython/Python3Embedded"
-    ${build_generator_args}
-    --build-project TestPython3Embedded
-    --build-options ${build_options}
-    --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
-    )
+  if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION  VERSION_GREATER_EQUAL "4.8")
+    add_test(NAME FindPython.Python3Embedded COMMAND
+      ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+      --build-and-test
+      "${CMake_SOURCE_DIR}/Tests/FindPython/Python3Embedded"
+      "${CMake_BINARY_DIR}/Tests/FindPython/Python3Embedded"
+      ${build_generator_args}
+      --build-project TestPython3Embedded
+      --build-options ${build_options}
+      --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+      )
+  endif()
 
   add_test(NAME FindPython.RequiredArtifacts COMMAND
     ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
@@ -430,10 +432,13 @@ if(CMake_TEST_FindPython3)
                     FindPython.Python.V3.ExactVersion.LOCATION FindPython.Python.V3.ExactVersion.VERSION
                     FindPython.Python3.VersionRange.LOCATION FindPython.Python3.VersionRange.VERSION
                     FindPython.Python.V3.VersionRange.LOCATION FindPython.Python.V3.VersionRange.VERSION
-                    FindPython.VirtualEnv FindPython.Python3Embedded FindPython.RequiredArtifacts
+                    FindPython.VirtualEnv FindPython.RequiredArtifacts
                     FindPython.ArtifactsInteractive.ON FindPython.ArtifactsInteractive.OFF
                     FindPython.CustomFailureMessage FindPython.DifferentComponents
                APPEND PROPERTY LABELS Python3)
+  if(TEST FindPython.Python3Embedded)
+    set_property(TEST FindPython.Python3Embedded APPEND PROPERTY LABELS Python3)
+  endif()
 
   if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
     add_test(NAME FindPython.UnversionedNames COMMAND

+ 11 - 6
Tests/FindPython/display_time.c

@@ -9,27 +9,32 @@
 void display_time(void)
 {
 #if defined(PYTHON3)
-  wchar_t* program = Py_DecodeLocale("display_time", NULL);
-  if (program == NULL) {
-    fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
-    exit(1);
+  PyConfig config;
+  PyStatus status;
+
+  PyConfig_InitPythonConfig(&config);
+  status =
+    PyConfig_SetBytesString(&config, &config.program_name, "display_time");
+  if (PyStatus_Exception(status)) {
+    Py_ExitStatusException(status);
   }
+
   char* cmd = "from time import time,ctime\n"
               "print('Today is', ctime(time()))\n";
 #else
   char* program = "display_time";
   char* cmd = "from time import time,ctime\n"
               "print 'Today is', ctime(time())\n";
-#endif
 
   Py_SetProgramName(program); /* optional but recommended */
+#endif
   Py_Initialize();
   PyRun_SimpleString(cmd);
 #if defined(PYTHON3)
   if (Py_FinalizeEx() < 0) {
     exit(120);
   }
-  PyMem_RawFree(program);
+  PyConfig_Clear(&config);
 #else
   Py_Finalize();
 #endif