File: check-syntax-changes

package info (click to toggle)
vifm 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,252 kB
  • sloc: ansic: 179,567; sh: 5,445; makefile: 723; perl: 347; python: 76; xml: 26
file content (71 lines) | stat: -rwxr-xr-x 2,074 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash

# This script performs comparison of Vim syntax highlighting with and without
# uncommited changes.  It's done by generating HTML files which are then
# compared via `git diff` in word diff mode.  Output isn't the easiest one to
# understand, but enough to show unexpected changes and expected effects (line
# numbers are at the left).
#
# Invocation:
#  * without arguments to check provided test file;
#  * with file name to check changes on specified file.

set -e

dir=$(dirname "$(readlink -f "$0")")
syntax_regression_file="$dir/../tests/test-data/syntax-highlight/syntax.vifm"

if [ $# -eq 1 ]; then
    syntax_regression_file="$1"
elif [ $# -ne 0 ]; then
    echo "Usage: $(basename "$0") [test file that uses vifm syntax]"
    exit 1
fi

if [ ! -r "$syntax_regression_file" ]; then
    echo "$(basename "$0"): '$syntax_regression_file' file doesn't exist"
    exit 2
fi

# three arguments:
#  1) path to syntax script;
#  2) path to source file;
#  3) path to destination file.
function to_html
{
    local syntax_script="$1"
    local src="$2"
    local out="$src.html"
    local dst="$3"

    vim -E -s \
        +'let g:html_no_progress = 1' \
        +'let g:html_line_ids=1' \
        +'syntax on' \
        +"source $syntax_script" \
        +'runtime syntax/2html.vim' \
        +'wqa' \
        "$src" > /dev/null 2>&1 || true
    mv "$out" "$dst"
}

# makes sure temporary files are deleted on normal or error exit
function remove_tmp_files()
{
    rm -f "$dir/before.vim" "$dir/after.vifm.html" "$dir/before.vifm.html"
}
trap remove_tmp_files EXIT

git show HEAD:data/vim/syntax/vifm.vim > "$dir/before.vim"

to_html "$dir/before.vim" "$syntax_regression_file" "$dir/before.vifm.html"

to_html "$dir/../data/vim/syntax/vifm.vim" "$syntax_regression_file" \
        "$dir/after.vifm.html"

if ! git diff --quiet --no-index "$dir/before.vifm.html" "$dir/after.vifm.html"
then
    git diff --no-index --word-diff \
             --word-diff-regex='<[^>]+>|[^<>[:space:]]+' \
             "$dir/before.vifm.html" "$dir/after.vifm.html" || true
fi