Merge lp:~elfy/ubuntu-manual-tests/testscript into lp:ubuntu-manual-tests

Proposed by Elfy
Status: Merged
Merged at revision: 322
Proposed branch: lp:~elfy/ubuntu-manual-tests/testscript
Merge into: lp:ubuntu-manual-tests
Diff against target: 350 lines (+346/-0)
1 file modified
tools/test_case_format (+346/-0)
To merge this branch: bzr merge lp:~elfy/ubuntu-manual-tests/testscript
Reviewer Review Type Date Requested Status
ԜаӀtеr Ⅼарсһуnѕkі Needs Fixing
Nicholas Skaggs Pending
Review via email: mp+249513@code.launchpad.net

Description of the change

first draft, script for manual testcase format checking

To post a comment you must log in.
Revision history for this message
ԜаӀtеr Ⅼарсһуnѕkі (wxl) wrote :

Not sure what's wrong (not familiar with tidy) but I took 1657_Gnome-system-monitor and ran it with and without the leading dl tag. Both times it produced no output and had a 0 exit status.

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'tools/test_case_format'
2--- tools/test_case_format 1970-01-01 00:00:00 +0000
3+++ tools/test_case_format 2015-02-12 15:50:39 +0000
4@@ -0,0 +1,346 @@
5+#! /bin/sh
6+#description: format file according to https://wiki.ubuntu.com/Testing/TestCaseFormat
7+#save as test-case-format
8+#Make file executable <code>chmod +x test-case-format
9+#move to /urs/local/bin <code>sudo mv test-case-format /usr/local/bin</code>
10+#In order to use this script, both vim and tidy need to be installed.
11+#usage: test-case-format /path/to/files
12+INDENTATION="4"
13+
14+_basename()
15+{
16+ [ -z "${1}" ] && return 1 || _basename_var_name="${1}"
17+ [ -z "${2}" ] || _basename_var_suffix="${2}"
18+ case "${_basename_var_name}" in
19+ /*|*/*) _basename_var_name="$(expr "${_basename_var_name}" : '.*/\([^/]*\)')" ;;
20+ esac
21+
22+ if [ -n "${_basename_var_suffix}" ] && [ "${#_basename_var_name}" -gt "${#2}" ]; then
23+ if [ X"$(printf "%s" "${_basename_var_name}" | cut -c"$((${#_basename_var_name} - ${#_basename_var_suffix} + 1))"-"${#_basename_var_name}")" \
24+ = X"$(printf "%s" "${_basename_var_suffix}")" ]; then
25+ _basename_var_name="$(printf "%s" "${_basename_var_name}" | cut -c1-"$((${#_basename_var_name} - ${#_basename_var_suffix}))")"
26+ fi
27+ fi
28+
29+ printf "%s\\n" "${_basename_var_name}"
30+}
31+
32+_usage()
33+{
34+ printf "%s\\n" "Usage: $(_basename "${0}") testcase ..." >&2
35+ printf "%s\\n" "https://wiki.ubuntu.com/Testing/TestCaseFormat" >&2
36+ exit 1
37+}
38+
39+_tmp_files()
40+{
41+ mkdir -p /tmp/"$(_basename "${0}")"/indent
42+ #this file can also be copied to ~/.vim/indent/html.vim so
43+ #vim indent html files the testcase way <dl>/<dt>/<dd>
44+ cat > /tmp/"$(_basename "${0}")"/indent/html.vim << EOF
45+" Description: html indenter
46+" Author: Johannes Zellner <johannes@zellner.org>
47+" Last Change: Mo, 05 Jun 2006 22:32:41 CEST
48+" Restoring 'cpo' and 'ic' added by Bram 2006 May 5
49+" Globals: g:html_indent_tags -- indenting tags
50+" g:html_indent_strict -- inhibit 'O O' elements
51+" g:html_indent_strict_table -- inhibit 'O -' elements
52+
53+" Only load this indent file when no other was loaded.
54+if exists("b:did_indent")
55+ finish
56+endif
57+let b:did_indent = 1
58+
59+
60+" [-- local settings (must come before aborting the script) --]
61+setlocal indentexpr=HtmlIndentGet(v:lnum)
62+setlocal indentkeys=o,O,*<Return>,<>>,{,}
63+
64+
65+if exists('g:html_indent_tags')
66+ unlet g:html_indent_tags
67+endif
68+
69+" [-- helper function to assemble tag list --]
70+fun! <SID>HtmlIndentPush(tag)
71+ if exists('g:html_indent_tags')
72+ let g:html_indent_tags = g:html_indent_tags.'\|'.a:tag
73+ else
74+ let g:html_indent_tags = a:tag
75+ endif
76+endfun
77+
78+
79+" [-- <ELEMENT ? - - ...> --]
80+call <SID>HtmlIndentPush('a')
81+call <SID>HtmlIndentPush('abbr')
82+call <SID>HtmlIndentPush('acronym')
83+call <SID>HtmlIndentPush('address')
84+call <SID>HtmlIndentPush('b')
85+call <SID>HtmlIndentPush('bdo')
86+call <SID>HtmlIndentPush('big')
87+call <SID>HtmlIndentPush('blockquote')
88+call <SID>HtmlIndentPush('button')
89+call <SID>HtmlIndentPush('caption')
90+call <SID>HtmlIndentPush('center')
91+call <SID>HtmlIndentPush('cite')
92+call <SID>HtmlIndentPush('code')
93+call <SID>HtmlIndentPush('colgroup')
94+call <SID>HtmlIndentPush('dd')
95+call <SID>HtmlIndentPush('del')
96+call <SID>HtmlIndentPush('dfn')
97+call <SID>HtmlIndentPush('dir')
98+call <SID>HtmlIndentPush('div')
99+call <SID>HtmlIndentPush('dl')
100+call <SID>HtmlIndentPush('dt')
101+call <SID>HtmlIndentPush('em')
102+call <SID>HtmlIndentPush('fieldset')
103+call <SID>HtmlIndentPush('font')
104+call <SID>HtmlIndentPush('form')
105+call <SID>HtmlIndentPush('frameset')
106+call <SID>HtmlIndentPush('h1')
107+call <SID>HtmlIndentPush('h2')
108+call <SID>HtmlIndentPush('h3')
109+call <SID>HtmlIndentPush('h4')
110+call <SID>HtmlIndentPush('h5')
111+call <SID>HtmlIndentPush('h6')
112+call <SID>HtmlIndentPush('i')
113+call <SID>HtmlIndentPush('iframe')
114+call <SID>HtmlIndentPush('ins')
115+call <SID>HtmlIndentPush('kbd')
116+call <SID>HtmlIndentPush('label')
117+call <SID>HtmlIndentPush('legend')
118+call <SID>HtmlIndentPush('map')
119+call <SID>HtmlIndentPush('menu')
120+call <SID>HtmlIndentPush('noframes')
121+call <SID>HtmlIndentPush('noscript')
122+call <SID>HtmlIndentPush('object')
123+call <SID>HtmlIndentPush('ol')
124+call <SID>HtmlIndentPush('optgroup')
125+" call <SID>HtmlIndentPush('pre')
126+call <SID>HtmlIndentPush('q')
127+call <SID>HtmlIndentPush('s')
128+call <SID>HtmlIndentPush('samp')
129+call <SID>HtmlIndentPush('script')
130+call <SID>HtmlIndentPush('select')
131+call <SID>HtmlIndentPush('small')
132+call <SID>HtmlIndentPush('span')
133+call <SID>HtmlIndentPush('strong')
134+call <SID>HtmlIndentPush('style')
135+call <SID>HtmlIndentPush('sub')
136+call <SID>HtmlIndentPush('sup')
137+call <SID>HtmlIndentPush('table')
138+call <SID>HtmlIndentPush('textarea')
139+call <SID>HtmlIndentPush('title')
140+call <SID>HtmlIndentPush('tt')
141+call <SID>HtmlIndentPush('u')
142+call <SID>HtmlIndentPush('ul')
143+call <SID>HtmlIndentPush('var')
144+
145+
146+" [-- <ELEMENT ? O O ...> --]
147+if !exists('g:html_indent_strict')
148+ call <SID>HtmlIndentPush('body')
149+ call <SID>HtmlIndentPush('head')
150+ call <SID>HtmlIndentPush('html')
151+ call <SID>HtmlIndentPush('tbody')
152+endif
153+
154+
155+" [-- <ELEMENT ? O - ...> --]
156+if !exists('g:html_indent_strict_table')
157+ call <SID>HtmlIndentPush('th')
158+ call <SID>HtmlIndentPush('td')
159+ call <SID>HtmlIndentPush('tr')
160+ call <SID>HtmlIndentPush('tfoot')
161+ call <SID>HtmlIndentPush('thead')
162+endif
163+
164+delfun <SID>HtmlIndentPush
165+
166+let s:cpo_save = &cpo
167+set cpo-=C
168+
169+" [-- count indent-increasing tags of line a:lnum --]
170+fun! <SID>HtmlIndentOpen(lnum, pattern)
171+ let s = substitute('x'.getline(a:lnum),
172+ \ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)', "\1", 'g')
173+ let s = substitute(s, "[^\1].*$", '', '')
174+ return strlen(s)
175+endfun
176+
177+" [-- count indent-decreasing tags of line a:lnum --]
178+fun! <SID>HtmlIndentClose(lnum, pattern)
179+ let s = substitute('x'.getline(a:lnum),
180+ \ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)', "\1", 'g')
181+ let s = substitute(s, "[^\1].*$", '', '')
182+ return strlen(s)
183+endfun
184+
185+" [-- count indent-increasing '{' of (java|css) line a:lnum --]
186+fun! <SID>HtmlIndentOpenAlt(lnum)
187+ return strlen(substitute(getline(a:lnum), '[^{]\+', '', 'g'))
188+endfun
189+
190+" [-- count indent-decreasing '}' of (java|css) line a:lnum --]
191+fun! <SID>HtmlIndentCloseAlt(lnum)
192+ return strlen(substitute(getline(a:lnum), '[^}]\+', '', 'g'))
193+endfun
194+
195+" [-- return the sum of indents respecting the syntax of a:lnum --]
196+fun! <SID>HtmlIndentSum(lnum, style)
197+ if a:style == match(getline(a:lnum), '^\s*</')
198+ if a:style == match(getline(a:lnum), '^\s*</\<\('.g:html_indent_tags.'\)\>')
199+ let open = <SID>HtmlIndentOpen(a:lnum, g:html_indent_tags)
200+ let close = <SID>HtmlIndentClose(a:lnum, g:html_indent_tags)
201+ if 0 != open || 0 != close
202+ return open - close
203+ endif
204+ endif
205+ endif
206+ if '' != &syntax &&
207+ \ synIDattr(synID(a:lnum, 1, 1), 'name') =~ '\(css\|java\).*' &&
208+ \ synIDattr(synID(a:lnum, strlen(getline(a:lnum)), 1), 'name')
209+ \ =~ '\(css\|java\).*'
210+ if a:style == match(getline(a:lnum), '^\s*}')
211+ return <SID>HtmlIndentOpenAlt(a:lnum) - <SID>HtmlIndentCloseAlt(a:lnum)
212+ endif
213+ endif
214+ return 0
215+endfun
216+
217+fun! HtmlIndentGet(lnum)
218+ " Find a non-empty line above the current line.
219+ let lnum = prevnonblank(a:lnum - 1)
220+
221+ " Hit the start of the file, use zero indent.
222+ if lnum == 0
223+ return 0
224+ endif
225+
226+ " [-- special handling for <dd> --]
227+ if getline(a:lnum-1) =~ '\c</dt>'
228+ if getline(a:lnum) =~ '\c<dd>'
229+ return indent(lnum) + (&sw)
230+ endif
231+ endif
232+
233+ " [-- special handling for <dd>/<dt>: --]
234+ if getline(a:lnum-1) =~ '\c</dd>'
235+ if getline(a:lnum) =~ '\c</dd>'
236+ return indent(lnum)
237+ endif
238+ if getline(a:lnum) =~ '\c<dt>'
239+ return indent(lnum) - (&sw)
240+ endif
241+ return -1
242+ endif
243+
244+ let restore_ic = &ic
245+ setlocal ic " ignore case
246+
247+ " [-- special handling for <pre>: no indenting --]
248+ if getline(a:lnum) =~ '\c</pre>'
249+ \ || 0 < searchpair('\c<pre>', '', '\c</pre>', 'nWb')
250+ \ || 0 < searchpair('\c<pre>', '', '\c</pre>', 'nW')
251+ " we're in a line with </pre> or inside <pre> ... </pre>
252+ if restore_ic == 0
253+ setlocal noic
254+ endif
255+ return -1
256+ endif
257+
258+ " [-- special handling for <javascript>: use cindent --]
259+ let js = '<script.*type\s*=\s*.*java'
260+
261+ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
262+ " by Tye Zdrojewski <zdro@yahoo.com>, 05 Jun 2006
263+ " ZDR: This needs to be an AND (we are 'after the start of the pair' AND
264+ " we are 'before the end of the pair'). Otherwise, indentation
265+ " before the start of the script block will be affected; the end of
266+ " the pair will still match if we are before the beginning of the
267+ " pair.
268+ "
269+ if 0 < searchpair(js, '', '</script>', 'nWb')
270+ \ && 0 < searchpair(js, '', '</script>', 'nW')
271+ " we're inside javascript
272+ if getline(lnum) !~ js && getline(a:lnum) != '</script>'
273+ if restore_ic == 0
274+ setlocal noic
275+ endif
276+ return cindent(a:lnum)
277+ endif
278+ endif
279+
280+ if getline(lnum) =~ '\c</pre>'
281+ " line before the current line a:lnum contains
282+ " a closing </pre>. --> search for line before
283+ " starting <pre> to restore the indent.
284+ let preline = prevnonblank(search('\c<pre>', 'bW') - 1)
285+ if preline > 0
286+ if restore_ic == 0
287+ setlocal noic
288+ endif
289+ return indent(preline)
290+ endif
291+ endif
292+
293+ let ind = <SID>HtmlIndentSum(lnum, -1)
294+ let ind = ind + <SID>HtmlIndentSum(a:lnum, 0)
295+
296+ if restore_ic == 0
297+ setlocal noic
298+ endif
299+
300+ return indent(lnum) + (&sw * ind)
301+endfun
302+
303+let &cpo = s:cpo_save
304+unlet s:cpo_save
305+
306+" [-- EOF <runtime>/indent/html.vim --]
307+EOF
308+
309+ cat > /tmp/"$(_basename "${0}")"/vimrc << EOF
310+set runtimepath=/tmp/$(_basename "${0}"),\$VIMRUNTIME
311+syntax on
312+set ffs=unix,dos
313+set encoding=utf-8 "utf is able to represent any character
314+set softtabstop=${INDENTATION}
315+set shiftwidth=${INDENTATION}
316+set expandtab "tabs mutate into spaces, if you wanna insert "real"
317+filetype plugin indent on "enable filetype-specific plugins
318+EOF
319+}
320+
321+_format()
322+{
323+ for _format_var_testcase; do
324+ printf "%s\\n" "${_format_var_testcase}"
325+ tidy -f /tmp/"$(_basename "${0}")"/testcase -xml -i "${_format_var_testcase}" > /dev/null
326+ [ "${?}" -eq "2" ] && { cat /tmp/"$(_basename "${0}")"/testcase; exit 1; }
327+ vim -es -u /tmp/"$(_basename "${0}")"/vimrc -c "set ft=html" -c "normal gg=G" -c wq "${_format_var_testcase}"
328+ done
329+}
330+
331+if [ ! -t 0 ]; then
332+ #there is input comming from pipe or file, add to the end of $@
333+ set -- "${@}" $(cat)
334+fi
335+
336+[ "${#}" -eq "0" ] && _usage
337+
338+for arg in "${@}"; do #parse options
339+ case "${arg}" in
340+ --) shift; break ;;
341+ -h|--help) _usage ;;
342+ -*) printf "%s\\n" "$(expr "${0}" : '.*/\([^/]*\)'): unrecognized option \`${arg}'" >&2; _usage ;;
343+ esac
344+done
345+
346+[ -f "$(command -v "vim")" ] || { printf "%b\\n" "$(_basename "${0}"): You need to install 'vim' & 'tidy' to run this program\n$ sudo apt-get install vim tidy" >&2; exit 1; }
347+[ -f "$(command -v "tidy")" ] || { printf "%b\\n" "$(_basename "${0}"): You need to install 'tidy' to run this program\n$ sudo apt-get install tidy" >&2; exit 1; }
348+
349+_tmp_files
350+_format "${@}"

Subscribers

People subscribed via source and target branches