emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/lua-mode 7a3a5f6 169/468: Add script to facilitate indenta


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode 7a3a5f6 169/468: Add script to facilitate indentation testing
Date: Thu, 5 Aug 2021 04:58:29 -0400 (EDT)

branch: elpa/lua-mode
commit 7a3a5f6dbe1f20b034a981f97e02e68c701f75be
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>

    Add script to facilitate indentation testing
---
 test/indentation/test_indentation.sh | 77 ++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/test/indentation/test_indentation.sh 
b/test/indentation/test_indentation.sh
new file mode 100755
index 0000000..799c98e
--- /dev/null
+++ b/test/indentation/test_indentation.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+# This script can be used to test lua-mode indentation engine. For a slightly
+# longer description, run it without parameters and consult the output.
+
+# Need to preserve input arguments, because subshells overwrite them
+declare -a PARAMS
+PARAMS=( "$@" )
+
+set ${EMACS=emacs}
+set ${LUA_MODE=$(dirname $0)/../lua-mode.el}
+
+if [ ${#PARAMS[@]} -eq 0 ]; then
+    cat <<EOF
+Usage: `basename $0` <FILE> [ <FILE> ... ]
+
+Test lua-mode indentation: each FILE is checked to be indented as FILE.etalon.
+The following environment variables are considered:
+
+  - EMACS (default value: emacs)
+    specify emacs version to be run
+
+  - LUA_MODE (default value: $(readlink -m $(dirname $0)/../lua-mode.el))
+    specify location where tested lua-mode.el resides
+EOF
+    exit 1
+fi
+
+# All output will be redirected into ERROR_LOG temporary file to make sure
+# that if everything goes ok, the script will remain silent. In case of an
+# error, ERROR_LOG contents may be retrieved and printed onto the screen.
+ERROR_LOG=`mktemp` || { echo "can't create tempfile"; exit 1; }
+exec 6<>"$ERROR_LOG"
+unlink "$ERROR_LOG"
+ERROR_LOG=/proc/$$/fd/6
+
+OUTPUT=`mktemp` ||  { echo "can't create temporary output file"; exit 1; }
+exec 7<>"$OUTPUT"
+unlink "$OUTPUT"
+OUTPUT=/proc/$$/fd/7
+
+test_file_indentation() {
+    INPUT="$1"
+    ETALON="$INPUT.etalon"
+
+    echo -n "Testing $INPUT... "
+
+    test -f "$INPUT"  || { echo "input file '$INPUT' not exists or not a 
file"; return 1; }
+    test -f "$ETALON" || { echo "etalon file '$ETALON' not exists or not a 
file"; return 1; }
+
+# run emacs with lua-mode and indent input file
+# disable backup file creation to prevent emacs from trying to write to procfs
+    $EMACS --quick --batch \
+        --load $LUA_MODE \
+        --eval "(setq make-backup-files nil)" \
+        --eval "\
+(progn
+  (find-file \"$INPUT\")
+  (lua-mode)
+  (indent-region (point-min) (point-max))
+  (write-file \"$OUTPUT\"))" \
+      > $ERROR_LOG 2>&1 \
+      || { echo "indentation failed (Emacs log):"; cat <$ERROR_LOG ; return 1; 
}
+
+    diff -u $ETALON $OUTPUT >$ERROR_LOG 2>&1 \
+        || { echo "indentation mismatch:"; cat <$ERROR_LOG; return 1; }
+
+    echo OK
+}
+
+FAILED=no
+
+for INPUT in "${PARAMS[@]}"; do
+    test_file_indentation "$INPUT" || FAILED=yes
+done
+
+test "$FAILED" = "no" || exit 1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]