Mercurial > vim
annotate runtime/syntax/testdir/runtest.vim @ 32591:92b93fe443e9 v9.0.1627
patch 9.0.1627: no generic mechanism to test syntax plugins
Commit: https://github.com/vim/vim/commit/46acad7284cba7842b5e505fa3d07e99806d246f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 11 19:04:18 2023 +0100
patch 9.0.1627: no generic mechanism to test syntax plugins
Problem: No generic mechanism to test syntax plugins.
Solution: Add a syntax plugin test mechanism, using screendumps. Add a
simple test for "c".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 11 Jun 2023 20:15:06 +0200 |
parents | |
children | f8a2fc7d823f |
rev | line source |
---|---|
32591
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Runs all the syntax tests for which there is no "done/name" file. |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 " |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 " Current directory must be runtime/syntax. |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 " Only do this with the +eval feature |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 if 1 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 let cwd = getcwd() |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 if cwd !~ '[/\\]runtime[/\\]syntax\>' |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 echoerr 'Current directory must be "runtime/syntax"' |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 qall |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 if !isdirectory('testdir') |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 echoerr '"testdir" directory not found' |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 qall |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 " Use the script for source code screendump testing. It sources other scripts, |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 " therefore we must "cd" there. |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 cd ../../src/testdir |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 source screendump.vim |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 exe 'cd ' .. fnameescape(cwd) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 " For these tests we need to be able to run terminal Vim with 256 colors. On |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 " MS-Windows the console only has 16 colors and the GUI can't run in a |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 " terminal. |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 if !CanRunVimInTerminal() |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 echomsg 'Cannot make screendumps, aborting' |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 qall |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 cd testdir |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 if !isdirectory('done') |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 call mkdir('done') |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 set nocp |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 set nowrapscan |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 set report=9999 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 set modeline |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 set debug=throw |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 set nomore |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 au! SwapExists * call HandleSwapExists() |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 func HandleSwapExists() |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 " Ignore finding a swap file for the test input, the user might be editing |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 " it and that's OK. |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 if expand('<afile>') =~ 'input[/\\].*\..*' |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 let v:swapchoice = 'e' |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 endfunc |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 let failed_count = 0 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 for fname in glob('input/*.*', 1, 1) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 if fname =~ '\~$' |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 " backup file, skip |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 continue |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 let linecount = readfile(fname)->len() |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 let root = substitute(fname, 'input[/\\]\(.*\)\..*', '\1', '') |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 " Execute the test if the "done" file does not exist of when the input file |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 " is newer. |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 let in_time = getftime(fname) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 let out_time = getftime('done/' .. root) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 if out_time < 0 || in_time > out_time |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 for dumpname in glob('failed/' .. root .. '_\d*\.dump', 1, 1) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 call delete(dumpname) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 endfor |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 call delete('done/' .. root) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 let lines =<< trim END |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 syntax on |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 END |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 call writefile(lines, 'Xtestscript') |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 let buf = RunVimInTerminal('-S Xtestscript ' .. fname, {}) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 " Screendump at the start of the file: root_00.dump |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 let fail = VerifyScreenDump(buf, root .. '_00', {}) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 " Make a Screendump every 18 lines of the file: root_NN.dump |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 let topline = 1 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 let nr = 1 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 while linecount - topline > 20 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 let topline += 18 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 call term_sendkeys(buf, printf("%dGzt", topline)) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 let fail += VerifyScreenDump(buf, root .. printf('_%02d', nr), {}) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 let nr += 1 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 endwhile |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 " Screendump at the end of the file: root_99.dump |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 call term_sendkeys(buf, 'Gzb') |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 let fail += VerifyScreenDump(buf, root .. '_99', {}) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 call StopVimInTerminal(buf) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 call delete('Xtestscript') |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 if fail == 0 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 call writefile(['OK'], 'done/' . root) |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 echo "Test " . root . " OK\n" |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 else |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 let failed_count += 1 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 endfor |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 " Matching "if 1" at the start. |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 if failed_count > 0 |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 " have make report an error |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 cquit |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 endif |
92b93fe443e9
patch 9.0.1627: no generic mechanism to test syntax plugins
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 qall! |