diff options
Diffstat (limited to 'Programs')
-rw-r--r-- | Programs/_testembed.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 11524df..d89f6be 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1334,6 +1334,7 @@ static int test_init_read_set(void) return 0; fail: + PyConfig_Clear(&config); Py_ExitStatusException(status); } @@ -1592,6 +1593,46 @@ static int test_run_main(void) } +static int test_get_argc_argv(void) +{ + PyConfig config; + PyConfig_InitPythonConfig(&config); + + wchar_t *argv[] = {L"python3", L"-c", + (L"import sys; " + L"print(f'Py_RunMain(): sys.argv={sys.argv}')"), + L"arg2"}; + config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); + config_set_string(&config, &config.program_name, L"./python3"); + + // Calling PyConfig_Read() twice must not change Py_GetArgcArgv() result. + // The second call is done by Py_InitializeFromConfig(). + PyStatus status = PyConfig_Read(&config); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); + } + + init_from_config_clear(&config); + + int get_argc; + wchar_t **get_argv; + Py_GetArgcArgv(&get_argc, &get_argv); + printf("argc: %i\n", get_argc); + assert(get_argc == Py_ARRAY_LENGTH(argv)); + for (int i=0; i < get_argc; i++) { + printf("argv[%i]: %ls\n", i, get_argv[i]); + assert(wcscmp(get_argv[i], argv[i]) == 0); + } + + Py_Finalize(); + + printf("\n"); + printf("test ok\n"); + return 0; +} + + /* ********************************************************* * List of test cases and the function that implements it. * @@ -1649,6 +1690,7 @@ static struct TestCase TestCases[] = { {"test_init_setpythonhome", test_init_setpythonhome}, {"test_init_warnoptions", test_init_warnoptions}, {"test_run_main", test_run_main}, + {"test_get_argc_argv", test_get_argc_argv}, {"test_open_code_hook", test_open_code_hook}, {"test_audit", test_audit}, |