aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tools/emacs/test-erlang-mode
blob: 2418d23c92792914cce4dbbd90386d63db602904 (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash

# Usage: test-erlang-mode [options]
#
# Basic test script for erlang.el
#
# Options:
#   -f  - Forgiving mode.  Return success if no
#         suitable emacs is found.
#

invalid_emacs_rc=33

tmp=$(getopt --options hf --long help: -- "$@") || exit

eval set -- $tmp

while true
do
  case "$1" in
    -f)
      invalid_emacs_rc=0
      shift;;

    --)
      shift
      break;;

    -h|--help)
      echo
      sed -nr '/^# Usage:/,/^$/ s/^# ?//p' "$0"
      exit;;
  esac
done


set -e

cd $(dirname "$0")

if ! type emacs &> /dev/null
then
    echo "Skipping emacs test due to no emacs in PATH"
    exit "$invalid_emacs_rc"
fi

version="$(emacs --version | head -n1)"
version_number="${version#GNU Emacs }"
version_major="${version_number%%\.*}"

echo "Emacs version $version"

case "$version_major" in
    [0-9][0-9])
        if [ "$version_major" -lt 24 ]
        then
            echo "Skipping emacs test due to too old emacs ($version_major)"
            exit "$invalid_emacs_rc"
        fi;;
    *)
        echo "Skipping emacs test due to unsupported emacs version ($version)"
        exit "$invalid_emacs_rc";;
esac

set -x

# Test interpreted erlang-mode.
emacs -Q -batch -L . -l erlang.el -f erlang-mode

# Compile everything except erldoc.el.
for el in *.el
do
    [ "$el" = "erldoc.el" ] && continue
    emacs -Q -batch -L . -f batch-byte-compile "$el"
done

# Test compiled erlang-mode.
emacs -Q -batch -L . -l erlang.elc -f erlang-mode

if [ "$version_major" -ge 25 ]
then
    # Run unit tests in interpreted mode.
    emacs -Q -batch -L . -l erlang.el -l erlang-test.el \
          -f ert-run-tests-batch-and-exit

    # Run unit tests in compiled mode.
    emacs -Q -batch -L . -l erlang.elc -l erlang-test.elc \
          -f ert-run-tests-batch-and-exit

    # Compile erldoc which depends on cl-lib which was introduced in
    # Emacs 25.
    emacs -Q -batch -L . -f batch-byte-compile erldoc.el
    
    # Compile selected files again and this time do not accept any
    # warnings.  Add files here whenever they are cleaned of warnings.
    if [ "$version_major" -ge 26 ]
    then
        unforgiving="(setq byte-compile-error-on-warn t)"
    else
        # Workaround byte-compile-error-on-warn which seem broken in
        # Emacs 25.
        unforgiving="(advice-add #'display-warning :after \
         (lambda (_ f _ _) (error \"%s\" f)))"
    fi
    for el in erlang.el erlang-test.el erlang-edoc.el \
                        erlang-start.el erldoc.el
    do
        emacs -Q -batch -L . --eval "$unforgiving" -f batch-byte-compile "$el"
    done
fi