Mercurial > vim
comparison runtime/doc/test_urls.vim @ 12952:7fd105bfe992 v8.0.1352
patch 8.0.1352: dead URLs in the help go unnoticed
commit https://github.com/vim/vim/commit/f38c86eb6b665d9fcd3d232820a48198eccac376
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 28 14:19:07 2017 +0100
patch 8.0.1352: dead URLs in the help go unnoticed
Problem: Dead URLs in the help go unnoticed.
Solution: Add a script to check URLs in the help files. (Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 28 Nov 2017 14:30:05 +0100 |
parents | |
children | e09acb1daea7 |
comparison
equal
deleted
inserted
replaced
12951:749acedeee6e | 12952:7fd105bfe992 |
---|---|
1 " Test for URLs in help documents. | |
2 " | |
3 " Opens a new window with all found URLS followed by return code from curl | |
4 " (anything other than 0 means unreachable) | |
5 " | |
6 " Written by Christian Brabandt. | |
7 | |
8 func Test_check_URLs() | |
9 if has("win32") | |
10 echoerr "Doesn't work on MS-Windows" | |
11 return | |
12 endif | |
13 if executable('curl') | |
14 " Note: does not follow redirects! | |
15 let s:command = 'curl --silent --fail --output /dev/null --head ' | |
16 elseif executable('wget') | |
17 " Note: only allow a couple of redirects | |
18 let s:command = 'wget --quiet -S --spider --max-redirect=2 --timeout=5 --tries=2 -O /dev/null ' | |
19 else | |
20 echoerr 'Only works when "curl" or "wget" is available' | |
21 return | |
22 endif | |
23 | |
24 let pat='\(https\?\|ftp\)://[^\t* ]\+' | |
25 exe 'helpgrep' pat | |
26 helpclose | |
27 | |
28 let urls = map(getqflist(), 'v:val.text') | |
29 " do not use submatch(1)! | |
30 let urls = map(urls, {key, val -> matchstr(val, pat)}) | |
31 " remove examples like user@host (invalid urls) | |
32 let urls = filter(urls, 'v:val !~ "@"') | |
33 " Remove example URLs which are invalid | |
34 let urls = filter(urls, {key, val -> val !~ '\<\(\(my\|some\)\?host\|machine\|hostname\|file\)\>'}) | |
35 new | |
36 put =urls | |
37 " remove some more invalid items | |
38 " empty lines | |
39 v/./d | |
40 " remove # anchors | |
41 %s/#.*$//e | |
42 " remove trailing stuff (parenthesis, dot, comma, quotes), but only for HTTP | |
43 " links | |
44 g/^h/s#[.,)'"/>][:.]\?$## | |
45 g#^[hf]t\?tp:/\(/\?\.*\)$#d | |
46 silent! g/ftp://,$/d | |
47 silent! g/=$/d | |
48 let a = getline(1,'$') | |
49 let a = uniq(sort(a)) | |
50 %d | |
51 call setline(1, a) | |
52 | |
53 " Do the testing. | |
54 set nomore | |
55 %s/.*/\=TestURL(submatch(0))/ | |
56 | |
57 " highlight the failures | |
58 /.* \([0-9]*[1-9]\|[0-9]\{2,}\)$ | |
59 endfunc | |
60 | |
61 func TestURL(url) | |
62 " Relies on the return code to determine whether a page is valid | |
63 echom printf("Testing URL: %d/%d %s", line('.'), line('$'), a:url) | |
64 call system(s:command . shellescape(a:url)) | |
65 return printf("%s %d", a:url, v:shell_error) | |
66 endfunc | |
67 | |
68 call Test_check_URLs() |