churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Clone

Blame 00261-use-proper-command-line-parsing-in-_testembed.patch

3b36b49
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
3b36b49
index 6c3625d..2a53f3d 100644
3b36b49
--- a/Lib/test/test_capi.py
3b36b49
+++ b/Lib/test/test_capi.py
3b36b49
@@ -385,7 +385,7 @@ class EmbeddingTests(unittest.TestCase):
3b36b49
 
3b36b49
     def test_subinterps(self):
3b36b49
         # This is just a "don't crash" test
3b36b49
-        out, err = self.run_embedded_interpreter()
3b36b49
+        out, err = self.run_embedded_interpreter("repeated_init_and_subinterpreters")
3b36b49
         if support.verbose:
3b36b49
             print()
3b36b49
             print(out)
3b36b49
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
3b36b49
index 3968399..a68d4fa 100644
3b36b49
--- a/Programs/_testembed.c
3b36b49
+++ b/Programs/_testembed.c
3b36b49
@@ -33,7 +33,7 @@ static void print_subinterp(void)
3b36b49
     );
3b36b49
 }
3b36b49
 
3b36b49
-static void test_repeated_init_and_subinterpreters(void)
3b36b49
+static int test_repeated_init_and_subinterpreters(void)
3b36b49
 {
3b36b49
     PyThreadState *mainstate, *substate;
3b36b49
 #ifdef WITH_THREAD
3b36b49
@@ -70,6 +70,7 @@ static void test_repeated_init_and_subinterpreters(void)
3b36b49
         PyEval_RestoreThread(mainstate);
3b36b49
         Py_Finalize();
3b36b49
     }
3b36b49
+    return 0;
3b36b49
 }
3b36b49
 
3b36b49
 /*****************************************************
3b36b49
@@ -103,7 +104,7 @@ static void check_stdio_details(const char *encoding, const char * errors)
3b36b49
     Py_Finalize();
3b36b49
 }
3b36b49
 
3b36b49
-static void test_forced_io_encoding(void)
3b36b49
+static int test_forced_io_encoding(void)
3b36b49
 {
3b36b49
     /* Check various combinations */
3b36b49
     printf("--- Use defaults ---\n");
3b36b49
@@ -122,19 +123,51 @@ static void test_forced_io_encoding(void)
3b36b49
         printf("Unexpected success calling Py_SetStandardStreamEncoding");
3b36b49
     }
3b36b49
     Py_Finalize();
3b36b49
+    return 0;
3b36b49
 }
3b36b49
 
3b36b49
-/* Different embedding tests */
3b36b49
-int main(int argc, char *argv[])
3b36b49
+/* *********************************************************
3b36b49
+ * List of test cases and the function that implements it.
3b36b49
+ * 
3b36b49
+ * Names are compared case-sensitively with the first
3b36b49
+ * argument. If no match is found, or no first argument was
3b36b49
+ * provided, the names of all test cases are printed and
3b36b49
+ * the exit code will be -1.
3b36b49
+ *
3b36b49
+ * The int returned from test functions is used as the exit
3b36b49
+ * code, and test_capi treats all non-zero exit codes as a
3b36b49
+ * failed test. 
3b36b49
+ *********************************************************/
3b36b49
+struct TestCase
3b36b49
 {
3b36b49
+    const char *name;
3b36b49
+    int (*func)(void);
3b36b49
+};
3b36b49
+
3b36b49
+static struct TestCase TestCases[] = {
3b36b49
+    { "forced_io_encoding", test_forced_io_encoding },
3b36b49
+    { "repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters },
3b36b49
+    { NULL, NULL }
3b36b49
+};
3b36b49
 
3b36b49
-    /* TODO: Check the argument string to allow for more test cases */
3b36b49
+int main(int argc, char *argv[])
3b36b49
+{
3b36b49
     if (argc > 1) {
3b36b49
-        /* For now: assume "forced_io_encoding */
3b36b49
-        test_forced_io_encoding();
3b36b49
-    } else {
3b36b49
-        /* Run the original embedding test case by default */
3b36b49
-        test_repeated_init_and_subinterpreters();
3b36b49
+        for (struct TestCase *tc = TestCases; tc && tc->name; tc++) {
3b36b49
+            if (strcmp(argv[1], tc->name) == 0)
3b36b49
+                return (*tc->func)();
3b36b49
+        }
3b36b49
     }
3b36b49
-    return 0;
3b36b49
+
3b36b49
+    /* No match found, or no test name provided, so display usage */
3b36b49
+    printf("Python " PY_VERSION " _testembed executable for embedded interpreter tests\n"
3b36b49
+           "Normally executed via 'EmbeddingTests' in Lib/test/test_capi.py\n\n"
3b36b49
+           "Usage: %s TESTNAME\n\nAll available tests:\n", argv[0]);
3b36b49
+    for (struct TestCase *tc = TestCases; tc && tc->name; tc++) {
3b36b49
+        printf("  %s\n", tc->name);
3b36b49
+    }
3b36b49
+
3b36b49
+    /* Non-zero exit code will cause test_capi.py tests to fail.
3b36b49
+       This is intentional. */
3b36b49
+    return -1;
3b36b49
 }