diff options
| author | pwu2775-dev <267844174+pwu2775-dev@users.noreply.github.com> | 2026-11-23 00:10:18 +0800 |
|---|---|---|
| committer | pwu2775-dev <267844174+pwu2775-dev@users.noreply.github.com> | 2026-11-23 00:10:18 +0800 |
| commit | 21ea2bb1d01f9d0ac648a0694740eea9c1aad7d0 (patch) | |
| tree | f202ce9d4d20ff460a0b5751cb4cd56c84084c3b /runtime/test/process_cmdline_test.cpp | |
| parent | 2e6b237729049f121b5441ac45526c2c3a8663d1 (diff) | |
runtime: RT-136 review follow-up: check the test's setup, say what the returned table is valid for
process_cmdline_test now checks the return values of _putenv_s/_wputenv_s and says
when _wenviron already exists at startup, so the first-call check cannot pass
silently without exercising the lazy wide-table creation. process.cpp notes that
the returned table is the CRT's own and valid until the next _putenv, as with the
msvcrt.dll original.
Diffstat (limited to 'runtime/test/process_cmdline_test.cpp')
| -rw-r--r-- | runtime/test/process_cmdline_test.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/runtime/test/process_cmdline_test.cpp b/runtime/test/process_cmdline_test.cpp index 53294b6e5..01f1b38a5 100644 --- a/runtime/test/process_cmdline_test.cpp +++ b/runtime/test/process_cmdline_test.cpp | |||
| @@ -145,9 +145,12 @@ void check_getmainargs_environment() { | |||
| 145 | return; | 145 | return; |
| 146 | } | 146 | } |
| 147 | // First use of the wide environment in this process: set_command_line runs before anything made _wenviron. | 147 | // First use of the wide environment in this process: set_command_line runs before anything made _wenviron. |
| 148 | // main() hosts start with only the narrow table; if a toolchain change made _wenviron exist, the first-call | ||
| 149 | // checks below no longer prove the creation path, so say so rather than pass silently. | ||
| 150 | if (_wenviron) std::printf("note: _wenviron already exists at startup; its lazy creation is not exercised\n"); | ||
| 148 | rt::process::set_command_line(L"game.exe", {L"-x"}); | 151 | rt::process::set_command_line(L"game.exe", {L"-x"}); |
| 149 | _putenv_s("LEONIDA_RT136_A", "before"); // narrow only; the wide table is built from the OS block on first use | 152 | if (_putenv_s("LEONIDA_RT136_A", "before") != 0 || // narrow only; the wide table is built on first use |
| 150 | if (!env_has<wchar_t>(wide_fn, L"LEONIDA_RT136_A=before")) { | 153 | !env_has<wchar_t>(wide_fn, L"LEONIDA_RT136_A=before")) { |
| 151 | std::fprintf(stderr, "FAIL __wgetmainargs: no environment (or one without LEONIDA_RT136_A) at the first call\n"); | 154 | std::fprintf(stderr, "FAIL __wgetmainargs: no environment (or one without LEONIDA_RT136_A) at the first call\n"); |
| 152 | ++failures; | 155 | ++failures; |
| 153 | } | 156 | } |
| @@ -156,8 +159,10 @@ void check_getmainargs_environment() { | |||
| 156 | ++failures; | 159 | ++failures; |
| 157 | } | 160 | } |
| 158 | // A variable set after set_command_line reallocates the CRT's table; a pointer kept from before would dangle. | 161 | // A variable set after set_command_line reallocates the CRT's table; a pointer kept from before would dangle. |
| 159 | _putenv_s("LEONIDA_RT136_B", "after"); | 162 | if (_putenv_s("LEONIDA_RT136_B", "after") != 0 || _wputenv_s(L"LEONIDA_RT136_C", L"after") != 0) { |
| 160 | _wputenv_s(L"LEONIDA_RT136_C", L"after"); | 163 | std::fprintf(stderr, "FAIL _putenv_s/_wputenv_s did not set the test variables\n"); |
| 164 | ++failures; | ||
| 165 | } | ||
| 161 | if (!env_has<wchar_t>(wide_fn, L"LEONIDA_RT136_B=after") || !env_has<wchar_t>(wide_fn, L"LEONIDA_RT136_C=after")) { | 166 | if (!env_has<wchar_t>(wide_fn, L"LEONIDA_RT136_B=after") || !env_has<wchar_t>(wide_fn, L"LEONIDA_RT136_C=after")) { |
| 162 | std::fprintf(stderr, "FAIL __wgetmainargs: an environment variable set after set_command_line is missing\n"); | 167 | std::fprintf(stderr, "FAIL __wgetmainargs: an environment variable set after set_command_line is missing\n"); |
| 163 | ++failures; | 168 | ++failures; |