annotate runtime/doc/test_urls.vim @ 25096:d0625ed91013 v8.2.3085

patch 8.2.3085: JSONC files are not recognized Commit: https://github.com/vim/vim/commit/acbb4b5720fc27b8b07357b763ed4e5a944ae1da Author: Izhak Jakov <izhakjakov> Date: Sat Jul 3 13:09:37 2021 +0200 patch 8.2.3085: JSONC files are not recognized Problem: JSONC files are not recognized. Solution: Recognize .jsonc files. (Izhak Jakov, closes https://github.com/vim/vim/issues/8500)
author Bram Moolenaar <Bram@vim.org>
date Sat, 03 Jul 2021 13:15:03 +0200
parents 7fd105bfe992
children e09acb1daea7
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()
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 if has("win32")
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 echoerr "Doesn't work on MS-Windows"
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 return
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 endif
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 if executable('curl')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 " Note: does not follow redirects!
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let s:command = 'curl --silent --fail --output /dev/null --head '
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 elseif executable('wget')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 " Note: only allow a couple of redirects
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let s:command = 'wget --quiet -S --spider --max-redirect=2 --timeout=5 --tries=2 -O /dev/null '
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 else
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 echoerr 'Only works when "curl" or "wget" is available'
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 return
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endif
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 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
25 exe 'helpgrep' pat
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 helpclose
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 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
29 " 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
30 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
31 " 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
32 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
33 " 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
34 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
35 new
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 put =urls
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 " 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
38 " empty lines
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 v/./d
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 " remove # anchors
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 %s/#.*$//e
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " 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
43 " links
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 g/^h/s#[.,)'"/>][:.]\?$##
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 g#^[hf]t\?tp:/\(/\?\.*\)$#d
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 silent! g/ftp://,$/d
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 silent! g/=$/d
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 let a = getline(1,'$')
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 let a = uniq(sort(a))
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 %d
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 call setline(1, a)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 " Do the testing.
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 set nomore
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 %s/.*/\=TestURL(submatch(0))/
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 " highlight the failures
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 /.* \([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
59 endfunc
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 func TestURL(url)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 " 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
63 echom printf("Testing URL: %d/%d %s", line('.'), line('$'), a:url)
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call system(s:command . shellescape(a:url))
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 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
66 endfunc
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
7fd105bfe992 patch 8.0.1352: dead URLs in the help go unnoticed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 call Test_check_URLs()