diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 0a650edc2005acf..8927189587112e6 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1669,6 +1669,9 @@ def test_initconfig_api(self): self.check_all_configs("test_initconfig_api", config, preconfig, api=API_PYTHON) + def test_initconfig_exit(self): + self.run_embedded_interpreter("test_initconfig_exit") + def test_get_argc_argv(self): self.run_embedded_interpreter("test_get_argc_argv") # ignore output diff --git a/Programs/_testembed.c b/Programs/_testembed.c index a6907feeef76ec6..1337629af6c2b1d 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1855,6 +1855,33 @@ static int test_initconfig_api(void) } +static int test_initconfig_exit(void) +{ + PyInitConfig *config = PyInitConfig_Python_New(); + if (config == NULL) { + printf("Init allocation error\n"); + return 1; + } + + wchar_t *argv[] = {PROGRAM_NAME, L"--help"}; + assert(PyInitConfig_SetWStrList(config, "argv", + Py_ARRAY_LENGTH(argv), argv) == 0); + + assert(Py_InitializeFromInitConfig(config) < 0); + + int exitcode; + assert(PyInitConfig_GetExitCode(config, &exitcode) == 1); + assert(exitcode == 0); + + const char *err_msg; + assert(PyInitConfig_GetError(config, &err_msg) == 1); + assert(strcmp(err_msg, "exit code 0") == 0); + + PyInitConfig_Free(config); + return 0; +} + + static void configure_init_main(PyConfig *config) { wchar_t* argv[] = { @@ -2258,6 +2285,7 @@ static struct TestCase TestCases[] = { {"test_init_warnoptions", test_init_warnoptions}, {"test_init_set_config", test_init_set_config}, {"test_initconfig_api", test_initconfig_api}, + {"test_initconfig_exit", test_initconfig_exit}, {"test_run_main", test_run_main}, {"test_run_main_loop", test_run_main_loop}, {"test_get_argc_argv", test_get_argc_argv},