annotate runtime/doc/test_urls.vim @ 36543:6871d5f2fc77 draft

runtime(doc): clarify the use of filters and external commands Commit: https://github.com/vim/vim/commit/f18987caa5095e9ff154f924d952047c67c9fb64 Author: Christian Brabandt <cb@256bit.org> Date: Tue Nov 12 21:38:22 2024 +0100 runtime(doc): clarify the use of filters and external commands related: https://github.com/vim/vim/issues/16044 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 12 Nov 2024 21:45:02 +0100
parents 7191ebc28df2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for URLs in help documents.
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 "
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Opens a new window with all found URLS followed by return code from curl
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " (anything other than 0 means unreachable)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 "
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 " Written by Christian Brabandt.
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 func Test_check_URLs()
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
9 "20.10.23, added by Restorer
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 if has("win32")
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
11 let s:outdev = 'nul'
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
12 else
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
13 let s:outdev = '/dev/null'
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 endif
35158
7191ebc28df2 runtime(doc): update and remove some invalid links
Christian Brabandt <cb@256bit.org>
parents: 33712
diff changeset
15 " Restorer: For Windows users. If "curl" or "wget" is installed on the system
7191ebc28df2 runtime(doc): update and remove some invalid links
Christian Brabandt <cb@256bit.org>
parents: 33712
diff changeset
16 " but not in %PATH%, add the full path to them to %PATH% environment variable.
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 if executable('curl')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 " Note: does not follow redirects!
35158
7191ebc28df2 runtime(doc): update and remove some invalid links
Christian Brabandt <cb@256bit.org>
parents: 33712
diff changeset
19 let s:command1 = 'curl --silent --max-time 5 --fail --output ' ..s:outdev.. ' --head '
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
20 let s:command2 = ""
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 elseif executable('wget')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 " Note: only allow a couple of redirects
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
23 let s:command1 = 'wget --quiet -S --spider --max-redirect=2 --timeout=5 --tries=2 -O ' ..s:outdev.. ' '
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
24 let s:command2 = ""
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
25 elseif has("win32") "20.10.23, added by Restorer
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
26 if executable('powershell')
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
27 if 2 == system('powershell -nologo -noprofile "$psversiontable.psversion.major"')
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
28 echoerr 'To work in OS Windows requires the program "PowerShell" version 3.0 or higher'
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
29 return
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
30 endif
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
31 let s:command1 =
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
32 \ "powershell -nologo -noprofile \"{[Net.ServicePointManager]::SecurityProtocol = 'Tls12, Tls11, Tls, Ssl3'};try{(Invoke-WebRequest -MaximumRedirection 2 -TimeoutSec 5 -Uri "
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
33 let s:command2 = ').StatusCode}catch{exit [int]$Error[0].Exception.Status}"'
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
34 endif
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 else
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
36 echoerr 'Only works when "curl" or "wget", or "powershell" is available'
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 return
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 endif
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
40 " Do the testing.
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
41 set report =999
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
42 set nomore shm +=s
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
43
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 let pat='\(https\?\|ftp\)://[^\t* ]\+'
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 exe 'helpgrep' pat
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 helpclose
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 let urls = map(getqflist(), 'v:val.text')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 " do not use submatch(1)!
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 let urls = map(urls, {key, val -> matchstr(val, pat)})
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 " remove examples like user@host (invalid urls)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 let urls = filter(urls, 'v:val !~ "@"')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 " Remove example URLs which are invalid
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 let urls = filter(urls, {key, val -> val !~ '\<\(\(my\|some\)\?host\|machine\|hostname\|file\)\>'})
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 new
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 put =urls
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 " remove some more invalid items
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 " empty lines
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
59 "20.10.23, Restorer: '_' is a little faster, see `:h global`
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
60 v/./d _
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 " remove # anchors
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 %s/#.*$//e
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 " remove trailing stuff (parenthesis, dot, comma, quotes), but only for HTTP
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 " links
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
65 g/^h/s#[.),'"`/>][:.,]\?$##
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
66 g#^[hf]t\?tp:/\(/\?\.*\)$#d _
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
67 silent! g/ftp://,$/d _
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
68 silent! g/=$/d _
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 let a = getline(1,'$')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 let a = uniq(sort(a))
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
71 %d _
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 call setline(1, a)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 %s/.*/\=TestURL(submatch(0))/
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 " highlight the failures
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 /.* \([0-9]*[1-9]\|[0-9]\{2,}\)$
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 endfunc
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 func TestURL(url)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 " Relies on the return code to determine whether a page is valid
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 echom printf("Testing URL: %d/%d %s", line('.'), line('$'), a:url)
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
83 call system(s:command1 .. shellescape(a:url) .. s:command2)
12952
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 return printf("%s %d", a:url, v:shell_error)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 endfunc
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 call Test_check_URLs()
33712
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
88
e09acb1daea7 runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents: 12952
diff changeset
89 " vim: sw=2 sts=2 et