Skip to content

Commit 6bff6a2

Browse files
zzzyxwvutchrisbra
authored andcommitted
patch 9.1.0681: tests: Analyzing failed screendumps is hard
Problem: tests: Analyzing failed screendumps is hard Solution: Facilitate the viewing of rendered screendumps under src/ add some documentation on how to use the viewdumps.vim script (Aliaksei Budavei) With the submitted "viewdumps.vim" script, a few manual steps in typical workflows (see below) can be automated. The updated "README.txt" contains additional information. ============================================================ Reviewing LOCAL failed screendump tests can be arranged as follows: 1) Run tests and generate screendumps: ------------------------------------------------------------ cd /path/to/fork/src/testdir make ------------------------------------------------------------ 2) Examine the screendumps from the "failed" directory: ------------------------------------------------------------ ../vim -u NONE -S viewdumps.vim ------------------------------------------------------------ ============================================================ Reviewing UPLOADED failed screendump tests can be arranged as follows (it can be further locally scripted): 1) Fetch an artifact with failed screendumps from "github.com/vim/vim/actions/runs/A_ID/artifacts/B_ID". 2) Extract the archived files: ------------------------------------------------------------ unzip /tmp/failed-tests.zip -d /tmp ------------------------------------------------------------ 3) Set up the "dumps" directory. Create a symlink to "/path/to/fork/dirs/dumps" in the extracted directories so that term_dumpdiff() can be used. (The lookup algorithm resolves "dumps" for every loaded filename. So, with "/tmp/src/testdir/failed/*.dump" files passed as script arguments, the algorithm will make the files in "/tmp/src/testdir/dumps" queried.) ------------------------------------------------------------ cd /path/to/fork ln -s $(pwd)/src/testdir/dumps /tmp/src/testdir/dumps ------------------------------------------------------------ 4) Examine the extracted screendumps: ------------------------------------------------------------ ./src/vim -u NONE -S src/testdir/viewdumps.vim \ /tmp/src/testdir/failed/*.dump ------------------------------------------------------------ 5) Clean up: ------------------------------------------------------------ unlink /tmp/src/testdir/dumps rm -rf /tmp/src ------------------------------------------------------------ ============================================================ Reviewing SUBMITTED FOR PULL REQUEST screendump tests can be arranged as follows (it can be further locally scripted): 1) List the fetched changeset and write the changed "dumps" filenames to "/tmp/filelist": ------------------------------------------------------------ cd /path/to/fork git switch prs/1234 git diff-index --relative=src/testdir/dumps/ \ --name-only prs/1234~1 > /tmp/filelist ------------------------------------------------------------ 2) Reconcile relative filepaths, and copy next-to-be-updated "dumps" files in the "failed" directory (note the missing new screendumps, if any): ------------------------------------------------------------ git switch master cd src/testdir/dumps test -d ../failed || mkdir ../failed cp -t ../failed $(cat /tmp/filelist) ------------------------------------------------------------ 3) Remember about the introduced INVERTED relation between "dumps" and "failed", i.e. the files to be committed are in "dumps" already and their previous versions are in "failed"; therefore, copy the missing new screendumps from "dumps" to "failed" (otherwise these won't be shown): ------------------------------------------------------------ git switch prs/1234 cp -t ../failed foo_10.dump foo_11.dump foo_12.dump ------------------------------------------------------------ 4) Examine the screendumps from the "failed" directory (new screendumps will be shown with no difference between their versions): ------------------------------------------------------------ cd .. ../vim -u NONE -S viewdumps.vim ------------------------------------------------------------ closes: #15515 Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 175a87c commit 6bff6a2

7 files changed

Lines changed: 231 additions & 66 deletions

File tree

Filelist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ SRC_ALL = \
185185
src/testdir/sautest/autoload/*.vim \
186186
src/testdir/testluaplugin/lua/testluaplugin/*.lua \
187187
src/testdir/check.vim \
188+
src/testdir/commondumps.vim \
188189
src/testdir/gui_init.vim \
189190
src/testdir/gui_preinit.vim \
190191
src/testdir/mouse.vim \
@@ -198,6 +199,7 @@ SRC_ALL = \
198199
src/testdir/summarize.vim \
199200
src/testdir/term_util.vim \
200201
src/testdir/view_util.vim \
202+
src/testdir/viewdumps.vim \
201203
src/testdir/test[0-9]*.ok \
202204
src/testdir/test77a.ok \
203205
src/testdir/test77a.com \

runtime/syntax/testdir/README.txt

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ verify that the tests fail. Then you know your changes are covered by the
124124
test.
125125

126126

127-
Viewing generated screendumps
128-
-----------------------------
127+
Viewing generated screendumps (local)
128+
-------------------------------------
129129

130130
You may also wish to look at the whole batch of failed screendumps after
131131
running "make test". Source the "viewdumps.vim" script for this task:
@@ -151,5 +151,60 @@ At any time, you can add, list, and abandon other screendumps:
151151
The listing of argument commands can be found under :help buffer-list.
152152

153153

154+
Viewing generated screendumps (from a CI-uploaded artifact)
155+
-----------------------------------------------------------
156+
157+
After you have downloaded an artifact archive containing failed screendumps
158+
and extracted its files in a temporary directory, you need to set up a "dumps"
159+
directory by creating a symlink:
160+
161+
cd /path/to/fork
162+
ln -s $(pwd)/runtime/syntax/testdir/dumps \
163+
/tmp/runtime/syntax/testdir/dumps
164+
165+
You can now examine the extracted screendumps:
166+
167+
./src/vim --clean -S runtime/syntax/testdir/viewdumps.vim \
168+
/tmp/runtime/syntax/testdir/failed/*.dump
169+
170+
171+
Viewing generated screendumps (submitted for a pull request)
172+
------------------------------------------------------------
173+
174+
First, you need to check out the topic branch with the proposed changes and
175+
write down a difference list between the HEAD commit (index) and its parent
176+
commit with respect to the changed "dumps" filenames:
177+
178+
cd /path/to/fork
179+
git switch prs/1234
180+
git diff-index --relative=runtime/syntax/testdir/dumps/ \
181+
--name-only prs/1234~1 > /tmp/filelist
182+
183+
Then, you need to check out the master branch, change the current working
184+
directory to reconcile relative filepaths written in the filenames list, copy
185+
in the "failed" directory the old "dumps" files, whose names are on the same
186+
list, and follow it by checking out the topic branch:
187+
188+
git switch master
189+
cd runtime/syntax/testdir/dumps
190+
cp -t ../failed $(cat /tmp/filelist)
191+
git switch prs/1234
192+
193+
Make note of any missing new screendumps. Please remember about the
194+
introduced INVERTED relation between "dumps" and "failed", i.e. the files to
195+
be committed are in "dumps" already and their old versions are in "failed".
196+
Therefore, you need to copy the missing new screendumps from "dumps" to
197+
"failed":
198+
199+
cp -t ../failed foo_10.dump foo_11.dump foo_12.dump
200+
201+
After you have changed the current working directory to its parent directory,
202+
you can now examine the screendumps from the "failed" directory (note that new
203+
screendumps will be shown with no difference between their versions):
204+
205+
cd ..
206+
../../../src/vim --clean -S viewdumps.vim
207+
208+
154209
TODO: run test for one specific filetype
155210
TODO: test syncing by jumping around
Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,9 @@
11
vim9script
22

3-
# Support sourcing this script from this directory or any other directory in
4-
# the direct path that leads to the project's root directory.
5-
const failed_path: string = finddir('failed', getcwd() .. '/**', -1)
6-
->filter(((cwdpath: string) => (_: number, dirpath: string) =>
7-
cwdpath =~ '\<syntax\>' || dirpath =~ '\<syntax\>')(getcwd()))
8-
->get(-1, '') .. '/'
9-
var error: string = null_string
10-
11-
if failed_path == '/'
12-
error = 'No such directory: "failed"'
13-
else
14-
const failed_fnames: string = failed_path .. readdir(failed_path,
15-
(fname: string) => fname =~ '^.\+\.dump$')
16-
->join(' ' .. failed_path)
17-
18-
if failed_fnames =~ 'failed/$'
19-
error = 'No such file: "*.dump"'
20-
else
21-
exec ':0argedit ' .. failed_fnames
22-
buffers
23-
endif
24-
endif
25-
26-
def Render()
27-
const failed_fname: string = bufname()
28-
try
29-
setlocal suffixesadd=.dump
30-
const dumps_fname: string = findfile(
31-
fnamemodify(failed_fname, ':p:t'),
32-
fnamemodify(failed_fname, ':p:h:h') .. '/dumps')
33-
if filereadable(dumps_fname)
34-
term_dumpdiff(failed_fname, dumps_fname)
35-
else
36-
term_dumpload(failed_fname)
37-
endif
38-
finally
39-
exec 'bwipeout ' .. failed_fname
40-
endtry
41-
enddef
3+
exec 'source ' .. (((cwdpath: string) => cwdpath
4+
->strpart(0, cwdpath->strridx('/vim')))(getcwd()))
5+
.. '/vim/src/testdir/commondumps.vim'
6+
g:Init('\<syntax\>', -1)
427

438
# THE FOLLOWING SETTINGS PERTAIN TO "input/" FILES THAT ARE LIKELY TO BE
449
# LOADED SIDE BY SIDE WHENEVER BATCHES OF NEW SCREENDUMPS ARE GENERATED.
@@ -56,22 +21,4 @@ set display=lastline ruler scrolloff=5 t_ZH= t_ZR=
5621
# Anticipate non-Latin-1 characters in "input/" files.
5722
set encoding=utf-8 termencoding=utf-8
5823

59-
autocmd_add([{
60-
replace: true,
61-
group: 'viewdumps',
62-
event: 'BufRead',
63-
pattern: '*.dump',
64-
cmd: 'Render()',
65-
}])
66-
67-
# Unconditionally help, in case a list of filenames is passed to the command,
68-
# the first terminal window with its BufRead event.
69-
silent doautocmd viewdumps BufRead
70-
71-
if error != null_string
72-
# Instead of sleeping, fill half a window with blanks and prompt hit-enter.
73-
echom error .. repeat("\x20", (winwidth(0) * (winheight(0) / 2) - strlen(error)))
74-
error = null_string
75-
endif
76-
7724
# vim:fdm=syntax:sw=2:ts=8:noet:nolist:nosta:

src/testdir/README.txt

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ tests are successful, then this file will be an empty file.
9797

9898
- To execute only specific test functions, add a second argument:
9999

100-
$ ../vim -u NONE -S runtest.vim test_channel.vim open_delay
101-
100+
$ ../vim -u NONE -S runtest.vim test_channel.vim open_delay
102101

103102
- To run all the tests:
104103

@@ -120,9 +119,82 @@ tests are successful, then this file will be an empty file.
120119

121120
$ make clean
122121

123-
# ANALYZE FAILED SCREENDUMPS FROM CI:
124122

125-
See the file ../../runtime/syntax/testdir/README.txt section
126-
"Viewing generated screendumps" on how to analyze failed screen dumps
127-
(from CI or locally) using the provided Vim script
128-
../../runtime/syntax/testdir/viewdumps.vim in a more automatic way.
123+
VIEWING GENERATED SCREENDUMPS (local):
124+
125+
You may also wish to look at the whole batch of failed screendumps after
126+
running "make". Source the "viewdumps.vim" script for this task:
127+
128+
$ ../vim -u NONE -S viewdumps.vim \
129+
[dumps/Test_xxd_*.dump ...]
130+
131+
By default, all screendumps found in the "failed" directory will be added to
132+
the argument list and then the first one will be loaded. Loaded screendumps
133+
that bear filenames of screendumps found in the "dumps" directory will be
134+
rendering the contents of any such pair of files and the difference between
135+
them (:help term_dumpdiff()); otherwise, they will be rendering own contents
136+
(:help term_dumpload()). Remember to execute :edit when occasionally you see
137+
raw file contents instead of rendered.
138+
139+
At any time, you can add, list, and abandon other screendumps:
140+
141+
:$argedit dumps/Test_spell_*.dump
142+
:args
143+
:qall
144+
145+
The listing of argument commands can be found under :help buffer-list.
146+
147+
148+
VIEWING GENERATED SCREENDUMPS (from a CI-uploaded artifact):
149+
150+
After you have downloaded an artifact archive containing failed screendumps
151+
and extracted its files in a temporary directory, you need to set up a "dumps"
152+
directory by creating a symlink:
153+
154+
$ cd /path/to/fork
155+
$ ln -s $(pwd)/src/testdir/dumps /tmp/src/testdir/dumps
156+
157+
You can now examine the extracted screendumps:
158+
159+
$ ./src/vim -u NONE -S src/testdir/viewdumps.vim \
160+
/tmp/src/testdir/failed/*.dump
161+
162+
163+
VIEWING GENERATED SCREENDUMPS (submitted for a pull request):
164+
165+
First, you need to check out the topic branch with the proposed changes and
166+
write down a difference list between the HEAD commit (index) and its parent
167+
commit with respect to the changed "dumps" filenames:
168+
169+
$ cd /path/to/fork
170+
$ git switch prs/1234
171+
$ git diff-index --relative=src/testdir/dumps/ \
172+
--name-only prs/1234~1 > /tmp/filelist
173+
174+
Then, you need to check out the master branch, change the current working
175+
directory to reconcile relative filepaths written in the filenames list,
176+
possibly create an empty "failed" directory, copy in this directory the old
177+
"dumps" files, whose names are on the same list, and follow it by checking out
178+
the topic branch:
179+
180+
$ git switch master
181+
$ cd src/testdir/dumps
182+
$ test -d ../failed || mkdir ../failed
183+
$ cp -t ../failed $(cat /tmp/filelist)
184+
$ git switch prs/1234
185+
186+
Make note of any missing new screendumps. Please remember about the
187+
introduced INVERTED relation between "dumps" and "failed", i.e. the files to
188+
be committed are in "dumps" already and their old versions are in "failed".
189+
Therefore, you need to copy the missing new screendumps from "dumps" to
190+
"failed":
191+
192+
$ cp -t ../failed foo_10.dump foo_11.dump foo_12.dump
193+
194+
After you have changed the current working directory to its parent directory,
195+
you can now examine the screendumps from the "failed" directory (note that new
196+
screendumps will be shown with no difference between their versions):
197+
198+
$ cd ..
199+
$ ../vim -u NONE -S viewdumps.vim
200+

src/testdir/commondumps.vim

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
vim9script
2+
3+
# (Script-local.)
4+
#
5+
# Render a loaded screendump file or the difference of a loaded screendump
6+
# file and its namesake file from the "dumps" directory.
7+
def Render()
8+
const failed_fname: string = bufname()
9+
try
10+
setlocal suffixesadd=.dump
11+
const dumps_fname: string = findfile(
12+
fnamemodify(failed_fname, ':p:t'),
13+
fnamemodify(failed_fname, ':p:h:h') .. '/dumps')
14+
if filereadable(dumps_fname)
15+
term_dumpdiff(failed_fname, dumps_fname)
16+
else
17+
term_dumpload(failed_fname)
18+
endif
19+
finally
20+
exec 'bwipeout ' .. failed_fname
21+
endtry
22+
enddef
23+
24+
# Search for the "failed" directory in the passed _subtreedirname_ directories
25+
# (usually "\<src\>" or "\<syntax\>") and, if found, select its passed _count_
26+
# occurence, add all its "*.dump" files to the argument list and list them;
27+
# also define a BufRead autocommand that would invoke "Render()" for every
28+
# "*.dump" file.
29+
def g:Init(subtreedirname: string, count: number)
30+
# Support sourcing this script from any directory in the direct path that
31+
# leads to the project's root directory.
32+
const failed_path: string = finddir('failed', getcwd() .. '/**', -1)
33+
->filter(((cwdpath: string, parentdirname: string) =>
34+
(_: number, dirpath: string) =>
35+
cwdpath =~ parentdirname || dirpath =~ parentdirname)(
36+
getcwd(),
37+
subtreedirname))
38+
->get(count, '') .. '/'
39+
var error: string = null_string
40+
41+
if failed_path == '/'
42+
error = 'No such directory: "failed"'
43+
else
44+
const failed_fnames: string = failed_path .. readdir(failed_path,
45+
(fname: string) => fname =~ '^.\+\.dump$')
46+
->join(' ' .. failed_path)
47+
48+
if failed_fnames =~ 'failed/$'
49+
error = 'No such file: "*.dump"'
50+
else
51+
exec ':0argedit ' .. failed_fnames
52+
buffers
53+
endif
54+
endif
55+
56+
autocmd_add([{
57+
replace: true,
58+
group: 'viewdumps',
59+
event: 'BufRead',
60+
pattern: '*.dump',
61+
cmd: 'Render()',
62+
}])
63+
64+
# Unconditionally help, in case a list of filenames is passed to the
65+
# command, the first terminal window with its BufRead event.
66+
silent doautocmd viewdumps BufRead
67+
68+
if error != null_string
69+
# Instead of sleeping, fill half a window with blanks and prompt
70+
# hit-enter.
71+
echom error .. repeat("\x20",
72+
(winwidth(0) * (winheight(0) / 2) - strlen(error)))
73+
endif
74+
enddef
75+
76+
# vim:fdm=syntax:sw=2:ts=8:noet:nolist:nosta:

src/testdir/viewdumps.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
vim9script
2+
3+
exec 'source ' .. (((cwdpath: string) => cwdpath
4+
->strpart(0, cwdpath->strridx('/vim')))(getcwd()))
5+
.. '/vim/src/testdir/commondumps.vim'
6+
g:Init('\<src\>', 0)
7+
8+
# Match ":language" of runtest.vim.
9+
language messages C
10+
11+
# vim:fdm=syntax:sw=2:ts=8:noet:nolist:nosta:

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
681,
707709
/**/
708710
680,
709711
/**/

0 commit comments

Comments
 (0)