diff options
author | Dan Gudmundsson <[email protected]> | 2018-10-01 17:04:03 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2018-10-09 12:20:12 +0200 |
commit | b7a6a4ba1c1d91146af44f9d83cb53486a852c9c (patch) | |
tree | 29a3833143ae2fef004f4ab924e99ed0a7dde6ce /lib | |
parent | 8e938ab671bdcadbf6571426e045de7855a5b196 (diff) | |
download | otp-b7a6a4ba1c1d91146af44f9d83cb53486a852c9c.tar.gz otp-b7a6a4ba1c1d91146af44f9d83cb53486a852c9c.tar.bz2 otp-b7a6a4ba1c1d91146af44f9d83cb53486a852c9c.zip |
Run emacs tests from test_suite
Drive emacs test from test_suite instead of bash script.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tools/emacs/Makefile | 1 | ||||
-rwxr-xr-x | lib/tools/emacs/test-erlang-mode | 110 | ||||
-rw-r--r-- | lib/tools/test/emacs_SUITE.erl | 153 |
3 files changed, 107 insertions, 157 deletions
diff --git a/lib/tools/emacs/Makefile b/lib/tools/emacs/Makefile index ea4d6cb723..b7775d1c8c 100644 --- a/lib/tools/emacs/Makefile +++ b/lib/tools/emacs/Makefile @@ -46,6 +46,7 @@ EMACS_FILES= \ erlang-eunit \ erlang-edoc \ erlang-flymake \ + erlang-test \ erlang README_FILES= README diff --git a/lib/tools/emacs/test-erlang-mode b/lib/tools/emacs/test-erlang-mode deleted file mode 100755 index 2418d23c92..0000000000 --- a/lib/tools/emacs/test-erlang-mode +++ /dev/null @@ -1,110 +0,0 @@ -#!/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 diff --git a/lib/tools/test/emacs_SUITE.erl b/lib/tools/test/emacs_SUITE.erl index 0ad00d8fdb..a6d43d1816 100644 --- a/lib/tools/test/emacs_SUITE.erl +++ b/lib/tools/test/emacs_SUITE.erl @@ -23,16 +23,26 @@ -export([all/0, init_per_testcase/2, end_per_testcase/2]). --export([bif_highlight/1, indent/1, test_erlang_mode_script/1]). +-export([bif_highlight/1, + load_interpreted/1, compile_and_load/1, + indent/1, + tests_interpreted/1, tests_compiled/1 + ]). all() -> - [bif_highlight, indent, test_erlang_mode_script]. + [bif_highlight, load_interpreted, compile_and_load, + indent, + tests_interpreted, tests_compiled + ]. -init_per_testcase(_Case, Config) -> +init_per_testcase(Case, Config) -> ErlangEl = filename:join([code:lib_dir(tools),"emacs","erlang.el"]), case file:read_file_info(ErlangEl) of {ok, _} -> - [{el, ErlangEl}|Config]; + case Case =:= bif_highlight orelse emacs_version_ok(24.1) of + false -> {skip, "Old or no emacs found"}; + _ -> [{el, ErlangEl}|Config] + end; _ -> {skip, "Could not find erlang.el"} end. @@ -76,27 +86,89 @@ check_bif_highlight(Bin, Tag, Compare) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -indent(Config) -> - case emacs_version_ok() of +load_interpreted(_Config) -> + _ = emacs(["-l erlang.el -f erlang-mode"]), + ok. + +compile_and_load(_Config) -> + Dir = emacs_dir(), + Files0 = filelib:wildcard("*.el", Dir), + Files = case emacs_version_ok(24.3) of + %% erldoc.el depends on cl-lib which was introduced in 24.3. + false -> Files0 -- ["erldoc.el"]; + _ -> Files0 + end, + Unforgiving = + case emacs_version_ok(24) of + Ver when Ver < 25 -> + ""; + Ver when Ver < 26 -> + %% Workaround byte-compile-error-on-warn which seem broken in + %% Emacs 25. + "\"(advice-add #'display-warning :after " + "(lambda (_ f _ _) (error \"%s\" f)))\""; + _ -> + "\"(setq byte-compile-error-on-warn t)\"" + end, + %% Add files here whenever they are cleaned of warnings. + NoWarn = ["erlang.el", "erlang-test.el", "erlang-edoc.el", "erlang-start.el", "erldoc.el"], + Compile = fun(File) -> + Pedantic = case lists:member(File, NoWarn) andalso Unforgiving /= "" of + true -> ["--eval ", Unforgiving, " "]; + false -> " " + end, + emacs([Pedantic, + " -f batch-byte-compile ",filename:join(Dir, File)]), + true + end, + lists:foreach(Compile, Files), + emacs(["-l erlang.elc -f erlang-mode"]), + ok. + +tests_interpreted(_Config) -> + case emacs_version_ok(25) of false -> {skip, "Old or no emacs found"}; - true -> - Def = filename:dirname(code:which(?MODULE)) - ++ "/" - ++ ?MODULE_STRING - ++ "_data", - Dir = proplists:get_value(data_dir, Config, Def), - OrigFs = filelib:wildcard(Dir ++ "/*"), - io:format("Dir: ~s~nFs: ~p~n", [Dir, OrigFs]), - Fs = [{File, unindent(File)} || File <- OrigFs, - filename:extension(File) =:= ""], - Indent = fun emacs/1, - [Indent(File) || {_, File} <- Fs], - Res = [diff(Orig, File) || {Orig, File} <- Fs], - [file:delete(File) || {ok, File} <- Res], %% Cleanup - [] = [Fail || {fail, Fail} <- Res], + _ -> + emacs(["-l erlang.el ", + "-l erlang-test.el -f ert-run-tests-batch-and-exit"]), ok end. +tests_compiled(_Config) -> + case emacs_version_ok(25) of + false -> {skip, "Old or no emacs found"}; + _ -> + emacs(["-l erlang.elc ", + "-l erlang-test.elc -f ert-run-tests-batch-and-exit"]), + ok + end. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +indent(Config) -> + Def = filename:dirname(code:which(?MODULE)) + ++ "/" + ++ ?MODULE_STRING + ++ "_data", + Dir = proplists:get_value(data_dir, Config, Def), + OrigFs = filelib:wildcard(Dir ++ "/*"), + io:format("Dir: ~s~nFs: ~p~n", [Dir, OrigFs]), + Fs = [{File, unindent(File)} || File <- OrigFs, + filename:extension(File) =:= ""], + Indent = fun(File) -> + emacs([ + File, " ", + "--eval '(indent-region (point-min) (point-max) nil)' ", + "--eval '(save-buffer 0)'" + ]), + ok + end, + [Indent(File) || {_, File} <- Fs], + Res = [diff(Orig, File) || {Orig, File} <- Fs], + [file:delete(File) || {ok, File} <- Res], %% Cleanup + [] = [Fail || {fail, Fail} <- Res], + ok. + unindent(Input) -> Output = Input ++ ".erl", {ok, Bin} = file:read_file(Input), @@ -115,14 +187,13 @@ diff(Orig, File) -> {fail, File} end. -emacs_version_ok() -> +emacs_version_ok(AcceptVer) -> case os:cmd("emacs --version | head -1") of "GNU Emacs " ++ Ver -> case string:to_float(Ver) of - {Vsn, _} when Vsn >= 24.1 -> - true; + {Vsn, _} when Vsn >= AcceptVer -> + Vsn; _ -> - io:format("Unsupported Emacs version~n~s~n~n",[Ver]), false end; Res -> @@ -130,31 +201,19 @@ emacs_version_ok() -> false end. -emacs(File) -> +emacs(EmacsCmds) when is_list(EmacsCmds) -> Cmd = ["emacs ", "--batch --quick ", "--directory ", emacs_dir(), " ", - "--eval \"(require 'erlang-start)\" ", - File, " ", - "--eval '(indent-region (point-min) (point-max) nil)' ", - "--eval '(save-buffer 0)'" - ], - _Res = os:cmd(Cmd), - % io:format("cmd ~s:~n=> ~s~n", [Cmd, _Res]), - ok. + "--eval \"(require 'erlang-start)\" " + | EmacsCmds], + Res0 = os:cmd(Cmd ++ " ; echo $?"), + Rows = string:lexemes(Res0, ["\r\n", $\n]), + Res = lists:last(Rows), + Output = string:join(lists:droplast(Rows), "\n"), + io:format("Cmd ~s:~n => ~s ~ts~n", [Cmd, Res, Output]), + "0" = Res, + Output. emacs_dir() -> filename:join([code:lib_dir(tools), "emacs"]). - -test_erlang_mode_script(_Config) -> - Script = filename:join([emacs_dir(), "test-erlang-mode"]), - RcFile = string:trim(os:cmd("mktemp /tmp/emacs_SUITE.XXXXXX")), - Output = os:cmd(Script ++ " -f; echo $? > " ++ RcFile), - io:format("~s output:~n~n~ts~n", [Script, Output]), - {ok, RcBin} = file:read_file(RcFile), - ok = file:delete(RcFile), - RcString = binary:bin_to_list(RcBin), - {Rc, _} = string:to_integer(RcString), - io:format("Script return code: ~p~n", [Rc]), - 0 = Rc, - ok. |