aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-07-01 03:45:45 -0700
committerGitHub <noreply@github.com>2023-07-01 03:45:45 -0700
commit43ded8d3584477ab14731486cfb0e86534f2b2dc (patch)
tree09a39aa6aa13939d0b033843c7195a2e882ab8fb
parentba8f19ebb67ca27d746f4b1cd902ab3d807eace3 (diff)
downloadrneovim-43ded8d3584477ab14731486cfb0e86534f2b2dc.tar.gz
rneovim-43ded8d3584477ab14731486cfb0e86534f2b2dc.tar.bz2
rneovim-43ded8d3584477ab14731486cfb0e86534f2b2dc.zip
feat(version): unverbose ":version", ":verbose version" #24195
Problem: `nvim -v` and `:version` prints system vimrc, fallback files, and compilation info by default, which most people don't care about and just clutters up the output. Solution: Omit extra info unless 'verbose' is set.
-rw-r--r--cmake/RunTests.cmake2
-rw-r--r--src/nvim/version.c44
-rw-r--r--test/functional/core/main_spec.lua17
3 files changed, 43 insertions, 20 deletions
diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake
index e1a0c8d6c3..5e83b72235 100644
--- a/cmake/RunTests.cmake
+++ b/cmake/RunTests.cmake
@@ -66,6 +66,8 @@ set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/helpers.lua.
set(ENV{DEPS_INSTALL_DIR} ${DEPS_INSTALL_DIR}) # used by test/busted_runner.lua
execute_process(
+ # Note: because of "-ll" (low-level interpreter mode), some modules like
+ # _editor.lua are not loaded.
COMMAND ${NVIM_PRG} -ll ${WORKING_DIR}/test/busted_runner.lua -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE}
--lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
--lpath=${BUILD_DIR}/?.lua
diff --git a/src/nvim/version.c b/src/nvim/version.c
index b9fa7799a6..95e275bceb 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -2700,33 +2700,39 @@ void list_version(void)
msg(longVersion);
msg(version_buildtype);
list_lua_version();
+
+ if (p_verbose > 0) {
#ifndef NDEBUG
- msg(version_cflags);
+ msg(version_cflags);
#endif
-
- version_msg("\n\n");
+ version_msg("\n\n");
#ifdef SYS_VIMRC_FILE
- version_msg(_(" system vimrc file: \""));
- version_msg(SYS_VIMRC_FILE);
- version_msg("\"\n");
-#endif // ifdef SYS_VIMRC_FILE
-#ifdef HAVE_PATHDEF
-
- if (*default_vim_dir != NUL) {
- version_msg(_(" fall-back for $VIM: \""));
- version_msg(default_vim_dir);
+ version_msg(_(" system vimrc file: \""));
+ version_msg(SYS_VIMRC_FILE);
version_msg("\"\n");
- }
+#endif
- if (*default_vimruntime_dir != NUL) {
- version_msg(_(" f-b for $VIMRUNTIME: \""));
- version_msg(default_vimruntime_dir);
- version_msg("\"\n");
+#ifdef HAVE_PATHDEF
+ if (*default_vim_dir != NUL) {
+ version_msg(_(" fall-back for $VIM: \""));
+ version_msg(default_vim_dir);
+ version_msg("\"\n");
+ }
+
+ if (*default_vimruntime_dir != NUL) {
+ version_msg(_(" f-b for $VIMRUNTIME: \""));
+ version_msg(default_vimruntime_dir);
+ version_msg("\"\n");
+ }
+#endif
}
-#endif // ifdef HAVE_PATHDEF
- version_msg("\nRun :checkhealth for more info");
+ version_msg(p_verbose > 0
+ ? "\nRun :checkhealth for more info"
+ : (starting
+ ? "\nRun \"nvim -V1 -v\" for more info"
+ : "\nRun \":verbose version\" for more info"));
}
/// Show the intro message when not editing a file.
diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua
index efab40dd11..19c7a93730 100644
--- a/test/functional/core/main_spec.lua
+++ b/test/functional/core/main_spec.lua
@@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local eq = helpers.eq
+local matches = helpers.matches
local feed = helpers.feed
local eval = helpers.eval
local clear = helpers.clear
@@ -12,21 +13,24 @@ local write_file = helpers.write_file
local is_os = helpers.is_os
local skip = helpers.skip
-describe('Command-line option', function()
+describe('command-line option', function()
describe('-s', function()
local fname = 'Xtest-functional-core-main-s'
local fname_2 = fname .. '.2'
local nonexistent_fname = fname .. '.nonexistent'
local dollar_fname = '$' .. fname
+
before_each(function()
clear()
os.remove(fname)
os.remove(dollar_fname)
end)
+
after_each(function()
os.remove(fname)
os.remove(dollar_fname)
end)
+
it('treats - as stdin', function()
eq(nil, luv.fs_stat(fname))
funcs.system(
@@ -38,6 +42,7 @@ describe('Command-line option', function()
local attrs = luv.fs_stat(fname)
eq(#('42\n'), attrs.size)
end)
+
it('does not expand $VAR', function()
eq(nil, luv.fs_stat(fname))
eq(true, not not dollar_fname:find('%$%w+'))
@@ -50,6 +55,7 @@ describe('Command-line option', function()
local attrs = luv.fs_stat(fname)
eq(#('100500\n'), attrs.size)
end)
+
it('does not crash after reading from stdin in non-headless mode', function()
skip(is_os('win'))
local screen = Screen.new(40, 8)
@@ -100,6 +106,7 @@ describe('Command-line option', function()
]])
]=]
end)
+
it('errors out when trying to use nonexistent file with -s', function()
eq(
'Cannot open for reading: "'..nonexistent_fname..'": no such file or directory\n',
@@ -110,6 +117,7 @@ describe('Command-line option', function()
'-s', nonexistent_fname}))
eq(2, eval('v:shell_error'))
end)
+
it('errors out when trying to use -s twice', function()
write_file(fname, ':call setline(1, "1")\n:wqall!\n')
write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n')
@@ -124,4 +132,11 @@ describe('Command-line option', function()
eq(nil, luv.fs_stat(fname_2))
end)
end)
+
+ it('nvim -v, :version', function()
+ matches('Run ":verbose version"', funcs.execute(':version'))
+ matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version'))
+ matches('Run "nvim %-V1 %-v"', funcs.system({nvim_prog_abs(), '-v'}))
+ matches('Compilation: .*Run :checkhealth', funcs.system({nvim_prog_abs(), '-V1', '-v'}))
+ end)
end)