annotate src/testdir/screendump.vim @ 35167:6dddafdbe6f9 default tip

Added tag v9.1.0409 for changeset 0b259135fb3a4ce87fc1ff0673ae9b61cb7ed555
author Christian Brabandt <cb@256bit.org>
date Sun, 12 May 2024 00:15:05 +0200
parents 4a88061200c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Functions shared by tests making screen dumps.
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Only load this script once.
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents: 17113
diff changeset
4 if exists('*VerifyScreenDump')
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 finish
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 endif
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents: 17113
diff changeset
8 source shared.vim
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents: 17113
diff changeset
9 source term_util.vim
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
10
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
11 " Skip the rest if there is no terminal feature at all.
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
12 if !has('terminal')
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
13 finish
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
14 endif
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
15
30519
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
16 " Read a dump file "fname" and if "filter" exists apply it to the text.
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
17 def ReadAndFilter(fname: string, filter: string): list<string>
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
18 var contents = readfile(fname)
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
19
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
20 if filereadable(filter)
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
21 # do this in the bottom window so that the terminal window is unaffected
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
22 wincmd j
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
23 enew
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
24 setline(1, contents)
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
25 exe "source " .. filter
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
26 contents = getline(1, '$')
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
27 enew!
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
28 wincmd k
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
29 redraw
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
30 endif
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
31
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
32 return contents
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
33 enddef
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
34
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
35
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " Verify that Vim running in terminal buffer "buf" matches the screen dump.
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
37 " "options" is passed to term_dumpwrite().
28710
54e33757d1ec patch 8.2.4879: screendump test may fail when using valgrind
Bram Moolenaar <Bram@vim.org>
parents: 27626
diff changeset
38 " Additionally, the "wait" entry can specify the maximum time to wait for the
54e33757d1ec patch 8.2.4879: screendump test may fail when using valgrind
Bram Moolenaar <Bram@vim.org>
parents: 27626
diff changeset
39 " screen dump to match in msec (default 1000 msec).
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 " The file name used is "dumps/{filename}.dump".
30519
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
41 "
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
42 " To ignore part of the dump, provide a "dumps/{filename}.vim" file with
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
43 " Vim commands to be applied to both the reference and the current dump, so
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
44 " that parts that are irrelevant are not used for the comparison. The result
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
45 " is NOT written, thus "term_dumpdiff()" shows the difference anyway.
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
46 "
14693
156a7c5328a7 patch 8.1.0359: no clue what test failed when using a screendump twice
Christian Brabandt <cb@256bit.org>
parents: 14031
diff changeset
47 " Optionally an extra argument can be passed which is prepended to the error
156a7c5328a7 patch 8.1.0359: no clue what test failed when using a screendump twice
Christian Brabandt <cb@256bit.org>
parents: 14031
diff changeset
48 " message. Use this when using the same dump file with different options.
156a7c5328a7 patch 8.1.0359: no clue what test failed when using a screendump twice
Christian Brabandt <cb@256bit.org>
parents: 14031
diff changeset
49 " Returns non-zero when verification fails.
156a7c5328a7 patch 8.1.0359: no clue what test failed when using a screendump twice
Christian Brabandt <cb@256bit.org>
parents: 14031
diff changeset
50 func VerifyScreenDump(buf, filename, options, ...)
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 let reference = 'dumps/' . a:filename . '.dump'
30519
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
52 let filter = 'dumps/' . a:filename . '.vim'
16150
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
53 let testfile = 'failed/' . a:filename . '.dump'
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
54
28710
54e33757d1ec patch 8.2.4879: screendump test may fail when using valgrind
Bram Moolenaar <Bram@vim.org>
parents: 27626
diff changeset
55 let max_loops = get(a:options, 'wait', 1000) / 10
54e33757d1ec patch 8.2.4879: screendump test may fail when using valgrind
Bram Moolenaar <Bram@vim.org>
parents: 27626
diff changeset
56
19687
c3f506e24eab patch 8.2.0400: not all tests using a terminal are in the list of flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
57 " Starting a terminal to make a screendump is always considered flaky.
19691
60b5abfc4897 patch 8.2.0402: setting local instead of global flag
Bram Moolenaar <Bram@vim.org>
parents: 19687
diff changeset
58 let g:test_is_flaky = 1
19687
c3f506e24eab patch 8.2.0400: not all tests using a terminal are in the list of flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
59
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
60 " wait for the pending updates to be handled.
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
61 call TermWait(a:buf)
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
62
17918
9606c0adc148 patch 8.1.1955: tests contain typos
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
63 " Redraw to execute the code that updates the screen. Otherwise we get the
16326
1679b9f54946 patch 8.1.1168: not all screen update code of terminal is executed in tests
Bram Moolenaar <Bram@vim.org>
parents: 16314
diff changeset
64 " text and attributes only from the internal buffer.
1679b9f54946 patch 8.1.1168: not all screen update code of terminal is executed in tests
Bram Moolenaar <Bram@vim.org>
parents: 16314
diff changeset
65 redraw
1679b9f54946 patch 8.1.1168: not all screen update code of terminal is executed in tests
Bram Moolenaar <Bram@vim.org>
parents: 16314
diff changeset
66
30519
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
67 if filereadable(reference)
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
68 let refdump = ReadAndFilter(reference, filter)
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
69 else
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
70 " Must be a new screendump, always fail
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
71 let refdump = []
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
72 endif
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
73
16150
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
74 let did_mkdir = 0
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
75 if !isdirectory('failed')
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
76 let did_mkdir = 1
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
77 call mkdir('failed')
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
78 endif
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 let i = 0
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 while 1
15103
9339601e7a31 patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents: 14693
diff changeset
82 " leave some time for updating the original window
9339601e7a31 patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents: 14693
diff changeset
83 sleep 10m
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 call delete(testfile)
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
85 call term_dumpwrite(a:buf, testfile, a:options)
30519
4a88061200c2 patch 9.0.0595: extra newline in messages after a verbose shell message
Bram Moolenaar <Bram@vim.org>
parents: 29387
diff changeset
86 let testdump = ReadAndFilter(testfile, filter)
15916
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
87 if refdump == testdump
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 call delete(testfile)
16150
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
89 if did_mkdir
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
90 call delete('failed', 'd')
b23048205589 patch 8.1.1080: when a screendump test fails, moving the file is a hassle
Bram Moolenaar <Bram@vim.org>
parents: 15916
diff changeset
91 endif
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 break
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 endif
28710
54e33757d1ec patch 8.2.4879: screendump test may fail when using valgrind
Bram Moolenaar <Bram@vim.org>
parents: 27626
diff changeset
94 if i == max_loops
16249
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
95 " Leave the failed dump around for inspection.
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
96 if filereadable(reference)
17113
18ec0b92f431 patch 8.1.1556: command for failing screenshot does not include directory
Bram Moolenaar <Bram@vim.org>
parents: 16477
diff changeset
97 let msg = 'See dump file difference: call term_dumpdiff("testdir/' .. testfile .. '", "testdir/' .. reference .. '")'
16249
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
98 if a:0 == 1
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
99 let msg = a:1 . ': ' . msg
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
100 endif
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
101 if len(testdump) != len(refdump)
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
102 let msg = msg . '; line count is ' . len(testdump) . ' instead of ' . len(refdump)
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
103 endif
67e43b01497f patch 8.1.1129: when making a new screendump test have to create the file
Bram Moolenaar <Bram@vim.org>
parents: 16150
diff changeset
104 else
17113
18ec0b92f431 patch 8.1.1556: command for failing screenshot does not include directory
Bram Moolenaar <Bram@vim.org>
parents: 16477
diff changeset
105 let msg = 'See new dump file: call term_dumpload("testdir/' .. testfile .. '")'
29387
9dce192d1ac2 patch 9.0.0036: 'fillchars' cannot have window-local values
Bram Moolenaar <Bram@vim.org>
parents: 28710
diff changeset
106 " no point in retrying
9dce192d1ac2 patch 9.0.0036: 'fillchars' cannot have window-local values
Bram Moolenaar <Bram@vim.org>
parents: 28710
diff changeset
107 let g:run_nr = 10
15916
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
108 endif
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
109 for i in range(len(refdump))
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
110 if i >= len(testdump)
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
111 break
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
112 endif
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
113 if testdump[i] != refdump[i]
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
114 let msg = msg . '; difference in line ' . (i + 1) . ': "' . testdump[i] . '"'
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
115 endif
95648dc0124f patch 8.1.0964: cannot see in CI why a screenshot test failed
Bram Moolenaar <Bram@vim.org>
parents: 15653
diff changeset
116 endfor
14693
156a7c5328a7 patch 8.1.0359: no clue what test failed when using a screendump twice
Christian Brabandt <cb@256bit.org>
parents: 14031
diff changeset
117 call assert_report(msg)
156a7c5328a7 patch 8.1.0359: no clue what test failed when using a screendump twice
Christian Brabandt <cb@256bit.org>
parents: 14031
diff changeset
118 return 1
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 endif
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 let i += 1
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 endwhile
14693
156a7c5328a7 patch 8.1.0359: no clue what test failed when using a screendump twice
Christian Brabandt <cb@256bit.org>
parents: 14031
diff changeset
122 return 0
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 endfunc