From 7f58b2bb6a1a667689d450d9e9738d68a91f0518 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 29 Sep 2023 06:06:28 +0800 Subject: vim-patch:9.0.0607: verbose echo message test fails on Mac OS Problem: Verbose echo message test fails on Mac OS. Solution: Skip the test on Mac OS. https://github.com/vim/vim/commit/f802767df7b4532651fcf11d49e812ead32db45b Co-authored-by: Bram Moolenaar --- test/old/testdir/check.vim | 16 ++++++++++++++++ test/old/testdir/test_messages.vim | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/old/testdir/check.vim b/test/old/testdir/check.vim index af1a80250c..647e25b214 100644 --- a/test/old/testdir/check.vim +++ b/test/old/testdir/check.vim @@ -108,6 +108,22 @@ func CheckNotBSD() endif endfunc +" Command to check for not running on a MacOS +command CheckNotMac call CheckNotMac() +func CheckNotMac() + if has('mac') + throw 'Skipped: does not work on MacOS' + endif +endfunc + +" Command to check for not running on a MacOS M1 system. +command CheckNotMacM1 call CheckNotMacM1() +func CheckNotMacM1() + if has('mac') && system('uname -a') =~ '\' + throw 'Skipped: does not work on MacOS M1' + endif +endfunc + " Command to check that making screendumps is supported. " Caller must source screendump.vim command CheckScreendump call CheckScreendump() diff --git a/test/old/testdir/test_messages.vim b/test/old/testdir/test_messages.vim index adafb6bd23..9a999d71a8 100644 --- a/test/old/testdir/test_messages.vim +++ b/test/old/testdir/test_messages.vim @@ -379,7 +379,8 @@ endfunc " Test verbose message before echo command func Test_echo_verbose_system() CheckRunVimInTerminal - CheckUnix + CheckUnix " needs the "seq" command + CheckNotMac " doesn't use /tmp let buf = RunVimInTerminal('', {'rows': 10}) call term_sendkeys(buf, ":4 verbose echo system('seq 20')\") -- cgit From 92e40f8d185e3da8fc97b7a48041afc3fd568d29 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 28 Sep 2023 05:09:21 +0800 Subject: vim-patch:9.0.1946: filename expansion using ** in bash may fail Problem: filename expansion using ** in bash may fail Solution: Try to enable the globstar setting Starting with bash 4.0 it supports extended globbing using the globstar shell option. This makes matching recursively below a certain directory using the ** pattern work as expected nowadays. However, we need to explicitly enable this using the 'shopt -s globstar' bash command. So let's check the bash environment variable $BASH_VERSINFO (which is supported since bash 3.0 and conditionally enable the globstar option, if the major version is at least 4. For older bashs, this at least shouldn't cause errors (unless one is using really ancient bash 2.X or something). closes: vim/vim#13002 closes: vim/vim#13144 https://github.com/vim/vim/commit/9eb1ce531527a7177d16373b0f8689bbcd3d5f73 Co-authored-by: Christian Brabandt --- runtime/doc/editing.txt | 4 +++- src/nvim/os/shell.c | 27 ++++++++++++++++++++++----- test/old/testdir/test_functions.vim | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index 2f44256138..abfe466b07 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -356,7 +356,9 @@ as a wildcard when "[" is in the 'isfname' option. A simple way to avoid this is to use "path\[[]abc]", this matches the file "path\[abc]". *starstar-wildcard* -Expanding "**" is possible on Unix, Win32, macOS and a few other systems. +Expanding "**" is possible on Unix, Win32, macOS and a few other systems (but +it may depend on your 'shell' setting. It's known to work correctly for zsh; for +bash this requires at least bash version >= 4.X). This allows searching a directory tree. This goes up to 100 directories deep. Note there are some commands where this works slightly differently, see |file-searching|. diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 1cd560c5ef..582135349f 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -134,6 +134,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in #define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh #define STYLE_PRINT 3 // use "print -N", for zsh #define STYLE_BT 4 // `cmd` expansion, execute the pattern directly +#define STYLE_GLOBSTAR 5 // use extended shell glob for bash (this uses extended + // globbing functionality with globstar, needs bash > 4) int shell_style = STYLE_ECHO; int check_spaces; static bool did_find_nul = false; @@ -141,6 +143,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // vimglob() function to define for Posix shell static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; + // vimglob() function with globstar setting enabled, only for bash >= 4.X + static char *sh_globstar_opt = + "[[ ${BASH_VERSINFO[0]} -ge 4 ]] && shopt -s globstar; "; bool is_fish_shell = #if defined(UNIX) @@ -190,6 +195,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // If we use *zsh, "print -N" will work better than "glob". // STYLE_VIMGLOB: NL separated // If we use *sh*, we define "vimglob()". + // STYLE_GLOBSTAR: NL separated + // If we use *bash*, we define "vimglob() and enable globstar option". // STYLE_ECHO: space separated. // A shell we don't know, stay safe and use "echo". if (num_pat == 1 && *pat[0] == '`' @@ -203,9 +210,12 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in shell_style = STYLE_PRINT; } } - if (shell_style == STYLE_ECHO - && strstr(path_tail(p_sh), "sh") != NULL) { - shell_style = STYLE_VIMGLOB; + if (shell_style == STYLE_ECHO) { + if (strstr(path_tail(p_sh), "bash") != NULL) { + shell_style = STYLE_GLOBSTAR; + } else if (strstr(path_tail(p_sh), "sh") != NULL) { + shell_style = STYLE_VIMGLOB; + } } // Compute the length of the command. We need 2 extra bytes: for the @@ -214,6 +224,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in len = strlen(tempname) + 29; if (shell_style == STYLE_VIMGLOB) { len += strlen(sh_vimglob_func); + } else if (shell_style == STYLE_GLOBSTAR) { + len += strlen(sh_vimglob_func) + strlen(sh_globstar_opt); } for (i = 0; i < num_pat; i++) { @@ -281,6 +293,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in STRCAT(command, "print -N >"); } else if (shell_style == STYLE_VIMGLOB) { STRCAT(command, sh_vimglob_func); + } else if (shell_style == STYLE_GLOBSTAR) { + STRCAT(command, sh_globstar_opt); + STRCAT(command, sh_vimglob_func); } else { STRCAT(command, "echo >"); } @@ -430,7 +445,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in p = skipwhite(p); // skip to next entry } // file names are separated with NL - } else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { + } else if (shell_style == STYLE_BT + || shell_style == STYLE_VIMGLOB + || shell_style == STYLE_GLOBSTAR) { buffer[len] = NUL; // make sure the buffer ends in NUL p = buffer; for (i = 0; *p != NUL; i++) { // count number of entries @@ -496,7 +513,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in (*file)[i] = p; // Space or NL separates if (shell_style == STYLE_ECHO || shell_style == STYLE_BT - || shell_style == STYLE_VIMGLOB) { + || shell_style == STYLE_VIMGLOB || shell_style == STYLE_GLOBSTAR) { while (!(shell_style == STYLE_ECHO && *p == ' ') && *p != '\n' && *p != NUL) { p++; diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim index 3e1e5a4816..f3636f93dd 100644 --- a/test/old/testdir/test_functions.vim +++ b/test/old/testdir/test_functions.vim @@ -3281,4 +3281,23 @@ func Test_fullcommand() call assert_equal('', fullcommand(10)) endfunc +" Test for glob() with shell special patterns +func Test_glob_extended_bash() + CheckExecutable bash + let _shell = &shell + set shell=bash + + call mkdir('Xtestglob/foo/bar/src', 'p') + call writefile([], 'Xtestglob/foo/bar/src/foo.sh') + call writefile([], 'Xtestglob/foo/bar/src/foo.h') + call writefile([], 'Xtestglob/foo/bar/src/foo.cpp') + + " Sort output of glob() otherwise we end up with different + " ordering depending on whether file system is case-sensitive. + let expected = ['Xtestglob/foo/bar/src/foo.cpp', 'Xtestglob/foo/bar/src/foo.h'] + call assert_equal(expected, sort(glob('Xtestglob/**/foo.{h,cpp}', 0, 1))) + call delete('Xtestglob', 'rf') + let &shell=_shell +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 3465e0daa0daa1fdb9a8706724493646a731e359 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 29 Sep 2023 05:47:23 +0800 Subject: vim-patch:9.0.1947: Bash Expansion test fails on Windows/MacOS Problem: Bash Expansion test fails on Windows/MacOS Solution: Disable Test_glob_extended_bash for now This test doesn't work on Windows even if bash can be executed, since the globstar functionality has only been enabled in Unix builds of Vim (Commit 9eb1ce531527a7177d16373b0f8689bbcd3d5f73, patch 9.0.1946). closes: vim/vim#13205 https://github.com/vim/vim/commit/03ca4002c1dcd34c4b17fe4a491b02d77ec2c887 Co-authored-by: Ken Takata --- test/old/testdir/test_functions.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim index f3636f93dd..7b20f47f7a 100644 --- a/test/old/testdir/test_functions.vim +++ b/test/old/testdir/test_functions.vim @@ -3284,6 +3284,9 @@ endfunc " Test for glob() with shell special patterns func Test_glob_extended_bash() CheckExecutable bash + CheckNotMSWindows + CheckNotMac " The default version of bash is old on macOS. + let _shell = &shell set shell=bash -- cgit