test/env: multibyte env var to child process

Note: the test fails on non-Windows CI (Travis linux, Quickbuild bsd):
even on master before the env.c changes in this patch-series.
Maybe the unix part of printenv-test.c needs to be revisited.

Signed-off-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
erw7 2019-02-28 08:34:10 +01:00 committed by Justin M. Keyes
parent 900e96781f
commit 67535b5940
4 changed files with 88 additions and 1 deletions

View File

@ -7,6 +7,7 @@ local eval = helpers.eval
local meths = helpers.meths
local redir_exec = helpers.redir_exec
local source = helpers.source
local nvim_dir = helpers.nvim_dir
before_each(clear)
@ -45,7 +46,7 @@ describe(':let', function()
]=])
end)
it("multibyte environment variables", function()
it("multibyte env var #8398 #9267", function()
command("let $NVIM_TEST = 'AìaB'")
eq('AìaB', eval('$NVIM_TEST'))
command("let $NVIM_TEST = 'AaあB'")
@ -56,4 +57,26 @@ describe(':let', function()
command("let $NVIM_TEST = '"..mbyte.."'")
eq(mbyte, eval('$NVIM_TEST'))
end)
it("multibyte env var to child process #8398 #9267", function()
if (not helpers.iswin()) and require('test.helpers').isCI() then
-- Fails on non-Windows CI. Buffering/timing issue?
pending('fails on unix CI', function() end)
end
local cmd_get_child_env = "let g:env_from_child = system(['"..nvim_dir.."/printenv-test', 'NVIM_TEST'])"
command("let $NVIM_TEST = 'AìaB'")
command(cmd_get_child_env)
eq(eval('$NVIM_TEST'), eval('g:env_from_child'))
command("let $NVIM_TEST = 'AaあB'")
command(cmd_get_child_env)
eq(eval('$NVIM_TEST'), eval('g:env_from_child'))
local mbyte = [[\p* . . . . . . ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ ֹֻ
.ֹֻ .ֹֻ .ֹֻ ֹֻ ֹֻ ֹֻ .ֹֻ .ֹֻ .ֹֻ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ
.ֹֻ .ֹֻ .ֹֻ a a a ca ca ca ]]
command("let $NVIM_TEST = '"..mbyte.."'")
command(cmd_get_child_env)
eq(eval('$NVIM_TEST'), eval('g:env_from_child'))
end)
end)

View File

@ -3,3 +3,7 @@ target_link_libraries(tty-test ${LIBUV_LIBRARIES})
add_executable(shell-test shell-test.c)
add_executable(printargs-test printargs-test.c)
add_executable(printenv-test printenv-test.c)
if(WIN32)
set_target_properties(printenv-test PROPERTIES LINK_FLAGS -municode)
endif()

View File

@ -0,0 +1,59 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdio.h>
#ifdef WIN32
# include <windows.h>
#else
# include <stdlib.h>
#endif
#ifdef WIN32
int wmain(int argc, wchar_t **argv)
#else
int main(int argc, char **argv)
#endif
{
if (argc != 2) {
return 1;
}
#ifdef WIN32
wchar_t *value = _wgetenv(argv[1]);
if (value == NULL) {
return 1;
}
int utf8_len = WideCharToMultiByte(CP_UTF8,
0,
value,
-1,
NULL,
0,
NULL,
NULL);
if (utf8_len == 0) {
return (int)GetLastError();
}
char *utf8_value = (char *)calloc((size_t)utf8_len, sizeof(char));
utf8_len = WideCharToMultiByte(CP_UTF8,
0,
value,
-1,
utf8_value,
utf8_len,
NULL,
NULL);
fprintf(stderr, "%s", utf8_value);
free(utf8_value);
#else
char *value = getenv(argv[1]);
if (value == NULL) {
fprintf(stderr, "env var not found: %s", argv[1]);
return 1;
}
// Print to stderr to avoid buffering.
fprintf(stderr, "%s", value);
#endif
return 0;
}

View File

@ -751,6 +751,7 @@ local module = {
hasenv = hasenv,
hexdump = hexdump,
intchar2lua = intchar2lua,
isCI = isCI,
map = map,
matches = matches,
mergedicts_copy = mergedicts_copy,