# HG changeset patch # User Christian Brabandt # Date 1487875504 -3600 # Node ID 4e2cdce4576c5d4bb49c20296b2fbc8698975f38 # Parent 02654bf3c3f6a7967e1dc7d8873bc555442c9bbb patch 8.0.0361: GUI initialisation is not sufficiently tested commit https://github.com/vim/vim/commit/8be2fbb6705dfb41d06d688701803d206c968404 Author: Bram Moolenaar Date: Thu Feb 23 19:32:47 2017 +0100 patch 8.0.0361: GUI initialisation is not sufficiently tested Problem: GUI initialisation is not sufficiently tested. Solution: Add the gui_init test. (Kazuki Kuriyama) diff --git a/Filelist b/Filelist --- a/Filelist +++ b/Filelist @@ -105,7 +105,10 @@ SRC_ALL = \ src/testdir/sautest/autoload/*.vim \ src/testdir/runtest.vim \ src/testdir/shared.vim \ + src/testdir/view_util.vim \ src/testdir/setup.vim \ + src/testdir/gui_init.vim \ + src/testdir/setup_gui.vim \ src/testdir/test[0-9]*.ok \ src/testdir/test[0-9]*a.ok \ src/testdir/test_[a-z]*.ok \ diff --git a/src/Makefile b/src/Makefile --- a/src/Makefile +++ b/src/Makefile @@ -2133,6 +2133,7 @@ test_arglist \ test_gn \ test_goto \ test_gui \ + test_gui_init \ test_hardcopy \ test_help \ test_help_tagjump \ diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -2,7 +2,10 @@ # Common Makefile, defines the list of tests to run. # -NO_PLUGIN = -U NONE --noplugin --not-a-term +# Options for protecting the tests against undesirable interaction with the +# environment +NO_PLUGINS = --noplugin --not-a-term +NO_INITS = -U NONE $(NO_PLUGINS) # The first script creates small.vim. SCRIPTS_FIRST = \ @@ -152,6 +155,7 @@ NEW_TESTS = test_arglist.res \ test_gf.res \ test_gn.res \ test_gui.res \ + test_gui_init.res \ test_hardcopy.res \ test_help.res \ test_hide.res \ diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak --- a/src/testdir/Make_dos.mak +++ b/src/testdir/Make_dos.mak @@ -38,7 +38,7 @@ win32: nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(DOSTMP_INFILES): $(*B).in if not exist $(DOSTMP)\NUL md $(DOSTMP) if exist $@ del $@ - $(VIMPROG) -u dos.vim $(NO_PLUGIN) "+set ff=dos|f $@|wq" $(*B).in + $(VIMPROG) -u dos.vim $(NO_INITS) "+set ff=dos|f $@|wq" $(*B).in # For each input file dostmp/test99.in run the tests. # This moves test99.in to test99.in.bak temporarily. @@ -47,7 +47,7 @@ win32: nolog $(SCRIPTS_FIRST) $(SCRIPTS) move $(*B).in $(*B).in.bak > nul copy $(DOSTMP)\$(*B).in $(*B).in > nul copy $(*B).ok test.ok > nul - $(VIMPROG) -u dos.vim $(NO_PLUGIN) -s dotest.in $(*B).in + $(VIMPROG) -u dos.vim $(NO_INITS) -s dotest.in $(*B).in -@if exist test.out MOVE /y test.out $(DOSTMP)\$(*B).out > nul -@if exist $(*B).in.bak move /y $(*B).in.bak $(*B).in > nul -@if exist test.ok del test.ok @@ -55,7 +55,7 @@ win32: nolog $(SCRIPTS_FIRST) $(SCRIPTS) -@if exist Xfind rd /s /q Xfind -@del X* -@if exist viminfo del viminfo - $(VIMPROG) -u dos.vim $(NO_PLUGIN) "+set ff=unix|f test.out|wq" \ + $(VIMPROG) -u dos.vim $(NO_INITS) "+set ff=unix|f test.out|wq" \ $(DOSTMP)\$(*B).out @diff test.out $*.ok & if errorlevel 1 \ ( move /y test.out $*.failed > nul \ @@ -104,7 +104,7 @@ benchmark: bench_re_freeze.out: bench_re_freeze.vim -if exist benchmark.out del benchmark.out - $(VIMPROG) -u dos.vim $(NO_PLUGIN) $*.in + $(VIMPROG) -u dos.vim $(NO_INITS) $*.in @IF EXIST benchmark.out ( type benchmark.out ) # New style of tests uses Vim script with assert calls. These are easier @@ -115,5 +115,15 @@ newtests: $(NEW_TESTS) .vim.res: @echo "$(VIMPROG)" > vimcmd - $(VIMPROG) -u NONE $(NO_PLUGIN) -S runtest.vim $*.vim + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $*.vim @del vimcmd + +test_gui.res: test_gui.vim + @echo "$(VIMPROG)" > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $< + @del vimcmd + +test_gui_init.res: test_gui_init.vim + @echo "$(VIMPROG)" > vimcmd + $(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $< + @del vimcmd diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak --- a/src/testdir/Make_ming.mak +++ b/src/testdir/Make_ming.mak @@ -66,8 +66,8 @@ win32: fixff nolog $(SCRIPTS_FIRST) $(SC # TODO: find a way to avoid changing the distributed files. fixff: - -$(VIMPROG) -u dos.vim $(NO_PLUGIN) "+argdo set ff=dos|upd" +q *.in *.ok - -$(VIMPROG) -u dos.vim $(NO_PLUGIN) "+argdo set ff=unix|upd" +q \ + -$(VIMPROG) -u dos.vim $(NO_INITS) "+argdo set ff=dos|upd" +q *.in *.ok + -$(VIMPROG) -u dos.vim $(NO_INITS) "+argdo set ff=unix|upd" +q \ dotest.in test60.ok test_listchars.ok \ test_getcwd.ok test_wordcount.ok @@ -91,7 +91,7 @@ clean: .in.out: -@if exist $*.ok $(CP) $*.ok test.ok - $(VIMPROG) -u dos.vim $(NO_PLUGIN) -s dotest.in $*.in + $(VIMPROG) -u dos.vim $(NO_INITS) -s dotest.in $*.in @diff test.out $*.ok -@if exist $*.out $(DEL) $*.out @$(MV) test.out $*.out @@ -107,7 +107,7 @@ nolog: bench_re_freeze.out: bench_re_freeze.vim -$(DEL) benchmark.out - $(VIMPROG) -u dos.vim $(NO_PLUGIN) $*.in + $(VIMPROG) -u dos.vim $(NO_INITS) $*.in $(CAT) benchmark.out # New style of tests uses Vim script with assert calls. These are easier @@ -118,6 +118,16 @@ newtests: $(NEW_TESTS) .vim.res: @echo "$(VIMPROG)" > vimcmd - $(VIMPROG) -u NONE $(NO_PLUGIN) -S runtest.vim $*.vim + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $*.vim @$(DEL) vimcmd +test_gui.res: test_gui.vim + @echo "$(VIMPROG)" > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $< + @$(DEL) vimcmd + +test_gui_init.res: test_gui_init.vim + @echo "$(VIMPROG)" > vimcmd + $(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $< + @$(DEL) vimcmd + diff --git a/src/testdir/Makefile b/src/testdir/Makefile --- a/src/testdir/Makefile +++ b/src/testdir/Makefile @@ -52,7 +52,7 @@ report: RM_ON_RUN = test.out X* viminfo RM_ON_START = tiny.vim small.vim mbyte.vim mzscheme.vim lua.vim test.ok benchmark.out -RUN_VIM = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim $(NO_PLUGIN) -s dotest.in +RUN_VIM = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim $(NO_INITS) -s dotest.in clean: -rm -rf *.out *.failed *.res *.rej *.orig test.log messages $(RM_ON_RUN) $(RM_ON_START) valgrind.* @@ -118,7 +118,7 @@ nolog: # New style of tests uses Vim script with assert calls. These are easier # to write and a lot easier to read and debug. # Limitation: Only works with the +eval feature. -RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim $(NO_PLUGIN) +RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim newtests: newtestssilent @/bin/sh -c "if test -f messages && grep -q 'SKIPPED\|FAILED' messages; then cat messages && if test -f test.log; then cat test.log; fi ; fi" @@ -128,5 +128,15 @@ newtestssilent: $(NEW_TESTS) .vim.res: @echo "$(RUN_VIMTEST)" > vimcmd - $(RUN_VIMTEST) -U NONE -S runtest.vim $*.vim + $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim @rm vimcmd + +test_gui.res: test_gui.vim + @echo "$(RUN_GVIMTEST)" > vimcmd + $(RUN_VIMTEST) -u NONE $(NO_INITS) -S runtest.vim $< + @rm vimcmd + +test_gui_init.res: test_gui_init.vim + @echo "$(RUN_GVIMTEST_WITH_GVIMRC)" > vimcmd + $(RUN_VIMTEST) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $< + @rm vimcmd diff --git a/src/testdir/gui_init.vim b/src/testdir/gui_init.vim new file mode 100644 --- /dev/null +++ b/src/testdir/gui_init.vim @@ -0,0 +1,5 @@ +" gvimrc for test_gui_init.vim + +if has('gui_athena') || has('gui_motif') || has('gui_gtk2') || has('gui_gtk3') + set guiheadroom=0 +endif diff --git a/src/testdir/setup_gui.vim b/src/testdir/setup_gui.vim new file mode 100644 --- /dev/null +++ b/src/testdir/setup_gui.vim @@ -0,0 +1,29 @@ +" Common preparations for running GUI tests. + +let g:x11_based_gui = has('gui_athena') || has('gui_motif') + \ || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') + +" Reasons for 'skipped'. +let g:not_supported = "Skipped: Feature/Option not supported by this GUI: " +let g:not_implemented = "Skipped: Test not implemented yet for this GUI" +let g:not_hosted = "Skipped: Test not hosted by the system/environment" + +" For KDE set a font, empty 'guifont' may cause a hang. +func GUISetUpCommon() + if has("gui_kde") + set guifont=Courier\ 10\ Pitch/8/-1/5/50/0/0/0/0/0 + endif + + " Gnome insists on creating $HOME/.gnome2/, set $HOME to avoid changing the + " actual home directory. But avoid triggering fontconfig by setting the + " cache directory. Only needed for Unix. + if $XDG_CACHE_HOME == '' && exists('g:tester_HOME') + let $XDG_CACHE_HOME = g:tester_HOME . '/.cache' + endif + call mkdir('Xhome') + let $HOME = fnamemodify('Xhome', ':p') +endfunc + +func GUITearDownCommon() + call delete('Xhome', 'rf') +endfunc diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim --- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -4,32 +4,14 @@ if !has('gui') || ($DISPLAY == "" && !ha finish endif -let s:x11_based_gui = has('gui_athena') || has('gui_motif') - \ || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') - -" Reasons for 'skipped'. -let s:not_supported = "Skipped: Feature/Option not supported by this GUI: " -let s:not_implemented = "Skipped: Test not implemented yet for this GUI" -let s:not_hosted = "Skipped: Test not hosted by the system/environment" +source setup_gui.vim -" For KDE set a font, empty 'guifont' may cause a hang. -func SetUp() - if has("gui_kde") - set guifont=Courier\ 10\ Pitch/8/-1/5/50/0/0/0/0/0 - endif - - " Gnome insists on creating $HOME/.gnome2/, set $HOME to avoid changing the - " actual home directory. But avoid triggering fontconfig by setting the - " cache directory. Only needed for Unix. - if $XDG_CACHE_HOME == '' && exists('g:tester_HOME') - let $XDG_CACHE_HOME = g:tester_HOME . '/.cache' - endif - call mkdir('Xhome') - let $HOME = fnamemodify('Xhome', ':p') +func Setup() + call GUISetUpCommon() endfunc func TearDown() - call delete('Xhome', 'rf') + call GUITearDownCommon() endfunc " Test for resetting "secure" flag after GUI has started. @@ -43,8 +25,8 @@ endfunc func Test_getfontname_with_arg() let skipped = '' - if !s:x11_based_gui - let skipped = s:not_implemented + if !g:x11_based_gui + let skipped = g:not_implemented elseif has('gui_athena') || has('gui_motif') " Invalid font name. The result should be an empty string. call assert_equal('', getfontname('notexist')) @@ -72,8 +54,8 @@ func Test_getfontname_without_arg() let fname = getfontname() - if !s:x11_based_gui - let skipped = s:not_implemented + if !g:x11_based_gui + let skipped = g:not_implemented elseif has('gui_kde') " 'expected' is the value specified by SetUp() above. call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname) @@ -100,8 +82,8 @@ func Test_set_guifont() set guifontset= endif - if !s:x11_based_gui - let skipped = s:not_implemented + if !g:x11_based_gui + let skipped = g:not_implemented elseif has('gui_athena') || has('gui_motif') " Non-empty font list with invalid font names. " @@ -153,7 +135,7 @@ func Test_set_guifontset() let skipped = '' if !has('xfontset') - let skipped = s:not_supported . 'xfontset' + let skipped = g:not_supported . 'xfontset' else let ctype_saved = v:ctype @@ -202,7 +184,7 @@ func Test_set_guifontset() " Third, give a set of tests if it is found feasible. if !feasible - let skipped = s:not_hosted + let skipped = g:not_hosted else " N.B. 'v:ctype' has already been set to an appropriate value in the " previous loop. @@ -224,15 +206,15 @@ endfunc func Test_set_guifontwide() let skipped = '' - if !s:x11_based_gui - let skipped = s:not_implemented + if !g:x11_based_gui + let skipped = g:not_implemented elseif has('gui_gtk') let guifont_saved = &guifont let guifontwide_saved = &guifontwide let fc_match = exepath('fc-match') if empty(fc_match) - let skipped = s:not_hosted + let skipped = g:not_hosted else let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en') let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja') @@ -246,7 +228,7 @@ func Test_set_guifontwide() elseif has('gui_athena') || has('gui_motif') " guifontwide is premised upon the xfontset feature. if !has('xfontset') - let skipped = s:not_supported . 'xfontset' + let skipped = g:not_supported . 'xfontset' else let encoding_saved = &encoding let guifont_saved = &guifont @@ -303,6 +285,22 @@ func Test_set_guifontwide() endif endfunc +func Test_set_guiheadroom() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_supported . 'guiheadroom' + else + " Since this script is to be read together with '-U NONE', the default + " value must be preserved. + call assert_equal(50, &guiheadroom) + endif + + if !empty(skipped) + throw skipped + endif +endfunc + func Test_getwinpos() call assert_match('Window position: X \d\+, Y \d\+', execute('winpos')) call assert_true(getwinposx() >= 0) @@ -317,7 +315,7 @@ func Test_shell_command() endfunc func Test_windowid_variable() - if s:x11_based_gui || has('win32') + if g:x11_based_gui || has('win32') call assert_true(v:windowid > 0) else call assert_equal(0, v:windowid) diff --git a/src/testdir/test_gui_init.vim b/src/testdir/test_gui_init.vim new file mode 100644 --- /dev/null +++ b/src/testdir/test_gui_init.vim @@ -0,0 +1,35 @@ +" Tests specifically for the GUI features/options that need to be set up at +" startup to take effect at runtime. + +if !has('gui') || ($DISPLAY == "" && !has('gui_running')) + finish +endif + +source setup_gui.vim + +func Setup() + call GUISetUpCommon() +endfunc + +func TearDown() + call GUITearDownCommon() +endfunc + +" Make sure that the tests will be done with the GUI activated. +gui -f + +func Test_set_guiheadroom() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_supported . 'guiheadroom' + else + " The 'expected' value must be consistent with the value specified with + " gui_init.vim. + call assert_equal(0, &guiheadroom) + endif + + if !empty(skipped) + throw skipped + endif +endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -765,6 +765,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 361, +/**/ 360, /**/ 359,