diff options
author | Fabian Bergström <fabian.bergstrom@gmail.com> | 2022-11-06 10:06:33 +0100 |
---|---|---|
committer | Fabian <fabian@fmbb.se> | 2022-12-28 22:17:36 +0100 |
commit | 0631c7f74f1c3abac463c0d2f6d47c0bc7c6876f (patch) | |
tree | 34b9e8bccb2e17c21a547229b6d48813aea177b5 /lib/tools/emacs/erlang-skels.el | |
parent | 19bce3c6b734538dc7d5c3482f48703bd13691e6 (diff) | |
download | erlang-0631c7f74f1c3abac463c0d2f6d47c0bc7c6876f.tar.gz |
Fix example code in ct_hooks_chapter.xml
The example code has a syntax error (missing a period),
and uses the deprecated erlang:now/0 function.
* prefix unused variable names with _
* use a more minimal example
* move file:open to terminate
* 'suite_total' and 'total' were mixed up
* put complete CT hook example in erlang-skels.el
* fix indentation for the example CTH code
* remove some spaces and align to 80 chars rule
Diffstat (limited to 'lib/tools/emacs/erlang-skels.el')
-rw-r--r-- | lib/tools/emacs/erlang-skels.el | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/tools/emacs/erlang-skels.el b/lib/tools/emacs/erlang-skels.el index 3202f43790..2d2429b050 100644 --- a/lib/tools/emacs/erlang-skels.el +++ b/lib/tools/emacs/erlang-skels.el @@ -70,6 +70,8 @@ erlang-skel-ct-test-suite-s erlang-skel-header) ("Large Common Test suite" "ct-test-suite-l" erlang-skel-ct-test-suite-l erlang-skel-header) + ("Common Test Hook" "ct-hook" + erlang-skel-ct-hook erlang-skel-header) ("Erlang TS test suite" "ts-test-suite" erlang-skel-ts-test-suite erlang-skel-header) ) @@ -1845,6 +1847,107 @@ Please see the function `tempo-define-template'.") "*The template of a library module. Please see the function `tempo-define-template'.") +(defvar erlang-skel-ct-hook + '((erlang-skel-include erlang-skel-normal-header) + "%% Mandatory callbacks" n + "-export([init/2])." n + n + "%% Optional callbacks" n + "-export([id/1])." n + n + "-export([pre_init_per_suite/3])." n + "-export([post_init_per_suite/4])." n + n + "-export([pre_end_per_suite/3])." n + "-export([post_end_per_suite/4])." n + n + "-export([pre_init_per_group/4])." n + "-export([post_init_per_group/5])." n + n + "-export([pre_end_per_group/4])." n + "-export([post_end_per_group/5])." n + n + "-export([pre_init_per_testcase/4])." n + "-export([post_init_per_testcase/5])." n + n + "-export([pre_end_per_testcase/4])." n + "-export([post_end_per_testcase/5])." n + n + "-export([on_tc_fail/4])." n + "-export([on_tc_skip/4])." n + n + "-export([terminate/1])." n + n + "%% The hook state is threaded through all callbacks," n + "%% but can be anything the hook needs, replace as desired." n + "-record(state, { cases=0, suites=0, groups=0, skips=0, fails=0 })." n + n + "%% Return a unique id for this CTH." n + "id(Opts) ->" n + " %% A reference is the default implementation, this can be removed" n + " %% or some value can be read from Opts instead." n + " erlang:make_ref()." n + n + "%% Always called before any other callback function, once per installed hook." n + "init(Id, Opts) ->" n + " {ok, #state{}}." n + n + "pre_init_per_suite(Suite, Config, State) ->" n + " {Config, State}." n + n + "post_init_per_suite(Suite, Config, Return, State) ->" n + " {Return, State}." n + n + "pre_end_per_suite(Suite, Config, State) ->" n + " {Config, State}." n + n + "post_end_per_suite(Suite, Config, Return, State) ->" n + " {Return, State#state{suites = State#state.suites + 1}}." n + n + "pre_init_per_group(Suite, Group, Config, State) ->" n + " {Config, State}." n + n + "post_init_per_group(Suite, Group, Config, Return, State) ->" n + " {Return, State}." n + n + "pre_end_per_group(Suite, Group, Config, State) ->" n + " {Config, State}." n + n + "post_end_per_group(Suite, Group, Config, Return, State) ->" n + " {Return, State#state{groups = State#state.groups + 1}}." n + n + "pre_init_per_testcase(Suite, TC, Config, State) ->" n + " {Config, State}." n + n + "%% Called after each init_per_testcase (immediately before the test case)." n + "post_init_per_testcase(Suite, TC, Config, Return, State) ->" n + " {Return, State}." n + n + "%% Called before each end_per_testcase (immediately after the test case)." n + "pre_end_per_testcase(Suite, TC, Config, State) ->" n + " {Config, State}." n + n + "post_end_per_testcase(Suite, TC, Config, Return, State) ->" n + " {Return, State#state{cases = State#state.cases + 1}}." n + n + "%% Called after post_init_per_suite, post_end_per_suite, post_init_per_group," n + "%% post_end_per_group and post_end_per_testcase if the suite, group or test case failed." n + "on_tc_fail(Suite, TC, Reason, State) ->" n + " State#state{fails = State#state.fails + 1}." n + n + "%% Called when a test case is skipped by either user action" n + "%% or due to an init function failing." n + "on_tc_skip(Suite, TC, Reason, State) ->" n + " State#state{skips = State#state.skips + 1}." n + n + "%% Called when the scope of the CTH is done" n + "terminate(State) ->" n + " logger:notice(\"~s is done: ~p~n\", [?MODULE, State])." n + n + ) + "*The template of a library module. + Please see the function `tempo-define-template'.") + ;; Skeleton code: ;; This code is based on the package `tempo' which is part of modern |