Skip to content

Commit

Permalink
lthooks: new show related tests to fix issue #1243
Browse files Browse the repository at this point in the history
- `lthooks-show-2020-10-01.lvt` is frozen at the 2020-10-01 release,
  no arguments in hooks
- `update-lthooks-tests.sh` includes the above test
- `lthooks-show.sty` is a library of test helpers. They will be used by
  forthcoming tests, as well as completed.
  • Loading branch information
jlaurens committed Jan 23, 2024
1 parent 28c4cbc commit d212bc2
Show file tree
Hide file tree
Showing 5 changed files with 1,049 additions and 2 deletions.
8 changes: 6 additions & 2 deletions base/lthooks.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -3942,10 +3942,12 @@
%
% \changes{v1.0s}{2021/09/28}
% {Correct usage of older \cs{@@_if_file_hook:wTF} (gh/675)}
% \changes{v1.0w}{2024/01/22}
% {Correct usage of older \cs{@@_if_file_hook:wTF} (gh/1243)}
% \begin{macrocode}
%<latexrelease>\cs_new_protected:Npn \@@_try_declaring_generic_hook:nNNnn #1
%<latexrelease> {
%<latexrelease> \@@_if_file_hook:wTF #1 / \s_@@_mark
%<latexrelease> \@@_if_file_hook:wTF #1 / / \s_@@_mark
%<latexrelease> {
%<latexrelease> \exp_args:Ne
%<latexrelease> \@@_try_declaring_generic_hook_split:nNNnn
Expand Down Expand Up @@ -6785,10 +6787,12 @@
%
% \changes{v1.0s}{2021/09/28}
% {Correct usage of older \cs{@@_if_file_hook:wTF} (gh/675)}
% \changes{v1.0w}{2024/01/22}
% {Correct usage of older \cs{@@_if_file_hook:wTF} (gh/1243)}
% \begin{macrocode}
%<latexrelease>\cs_new_protected:Npn \@@_try_file_hook:n #1
%<latexrelease> {
%<latexrelease> \@@_if_file_hook:wTF #1 / \s_@@_mark
%<latexrelease> \@@_if_file_hook:wTF #1 / / \s_@@_mark
%<latexrelease> {
%<latexrelease> \exp_args:Ne \@@_if_usable_use:n
%<latexrelease> { \exp_args:Ne \@@_file_hook_normalize:n {#1} }
Expand Down
111 changes: 111 additions & 0 deletions base/testfiles-lthooks/helpers/lthooks-show.sty
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
% This is a library of commands used by various `lthooks*.lvt`

\IncludeInRelease{2020-10-01}{\TESTBlockHook}{Message}

\def\DebugShowHookEnv#1{
\ShowHook{env/#1/before}
\ShowHook{env/#1/begin}
\ShowHook{env/#1/end}
\ShowHook{env/#1/after}
}

\def\DebugShowHookCmd#1{
\ShowHook{cmd/#1/before}
\ShowHook{cmd/#1/after}
}

\def\TESTBlockHookEnv#1#2{
% run at the top level
% #1: the title of the block
% #2: the name of the environment
\BEGINTEST{Environment: #2}
\DebugShowHookEnv{#2}
\AddToHook{env/#2/before}{\TYPE{<#2 BEFORE>}}
\AddToHook{env/#2/begin}{\TYPE{<#2 BEGIN>}}
\AddToHook{env/#2/end}{\TYPE{<#2 END>}}
\AddToHook{env/#2/after}{\TYPE{<#2 AFTER>}}
\DebugShowHookEnv{#2}
\ENDTEST
}

\def\TESTBlockHookCmd#1#2{
% run at the top level
% #1: the title of the block
% #2: the csname of the command
\BEGINTEST{Command: #1}
\DebugShowHookCmd{#2}
\AddToHook{cmd/#2/before}{\TYPE{<#2 BEFORE>}}
\AddToHook{cmd/#2/after}{\TYPE{<#2 AFTER>}}
\DebugShowHookCmd{#2}
\ENDTEST
}
\def\TESTBlockHookCustomGeneric#1#2{
% run at the top level
% #1: the title of the block
% #2: the name of the hook
\BEGINTEST{Custom generic hook: #1}
\def\TEST{
\UseHook{#2}
\ShowHook{#2}
}
\BEGINTEST{Raw: #2}
\AddToHook{#2}[LABEL]{\TYPE{<#2 CODE>}}
\TEST
\ENDTEST
\BEGINTEST{Activated: #2}
\ActivateGenericHook{#2}
\TEST
\ENDTEST
\BEGINTEST{Disabled: #2}
\DisableGenericHook{#2}
\TEST
\ENDTEST
\ENDTEST
}
\def\TESTBlockHook#1#2{
% run at the top level
% #1: the title of the block
% #2: the name of the hook
\BEGINTEST{#1}
\def\TEST{
\UseHook{#2}
\ShowHook{#2}
}
\BEGINTEST{Undeclared #2}
\TEST
\ENDTEST
\BEGINTEST{#2 + TOP LEVEL}
\AddToHook{#2}{\TYPE{<#2 TOP-LEVEL>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + A LABEL}
\AddToHook{#2}[A LABEL]{\TYPE{<#2 A CODE>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + B LABEL}
\AddToHook{#2}[B LABEL]{\TYPE{<#2 B CODE>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + C LABEL}
\AddToHook{#2}[C LABEL]{\TYPE{<#2 C CODE>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + NEXT}
\AddToHookNext{#2}{\TYPE{<NEXT-ONLY>}}
\ShowHook{#2}
\TEST
\ENDTEST
\BEGINTEST{#2 + C LABEL < A LABEL}
\DeclareHookRule{#2}{C LABEL}{before}{A LABEL}
\TEST
\ENDTEST
\BEGINTEST{#2 + DEFAULT: B LABEL > C LABEL}
\DeclareDefaultHookRule{B LABEL}{after}{C LABEL}
\TEST
\ENDTEST
\ENDTEST
}
\EndIncludeInRelease%{2020-10-01}{\TESTBlockHookOneArg}{Message}

\IncludeInRelease{0000-00-00}{\whatever}{Message}
\EndIncludeInRelease
86 changes: 86 additions & 0 deletions base/testfiles-lthooks/lthooks-show-2020-10-01.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
% This is somehow `lthooks-show.lvt` frozen to the 2020-10-01 release
% before hooks with arguments were introduced.

\input{regression-test}
\RequirePackage[2020-10-01]{latexrelease}
\TYPE{********* RequirePackage[2020-10-01]{latexrelease}}

\RequirePackage{./lthooks-show}

\ExplSyntaxOn
\debug_on:n { check-declarations , deprecation }
\ExplSyntaxOff

\documentclass{article}

% There are many different hook profiles.

\START

\TESTBlockHookEnv
{Undefined environment envA}
{envA}
\NewDocumentEnvironment
{envA}{}
{\TYPE{<BEGIN{envA}>}}
{\TYPE{<END{envA}>}}
\begin{envA}\TYPE{<envA BODY>}\end{envA}

\NewDocumentEnvironment
{envB}{}
{\TYPE{<BEGIN{envB}>}}
{\TYPE{<END{envB}>}}
\TESTBlockHookEnv
{Defined environment envB}
{envB}
\begin{envB}\TYPE{<envB BODY>}\end{envB}

\TESTBlockHookCmd
{Undefined command with no arguments}
{cmdA}
\NewDocumentCommand\cmdA{}{\TYPE{<cmdA BODY>}}
\cmdA

\NewDocumentCommand\cmdB{}{\TYPE{<cmdB BODY>}}
\TESTBlockHookCmd
{Defined command with no arguments}
{cmdB}
\cmdB

\TESTBlockHookCustomGeneric
{CUSTOM GENERIC HOOK}
{CUSTOM GENERIC HOOK}

\TESTBlockHook
{OTHER HOOK: Undeclared}
{UNDECLARED HOOK}

\NewHook{DECLARED HOOK}

\TESTBlockHook
{OTHER HOOK: declared}
{DECLARED HOOK}

\NewReversedHook{DECLARED REVERSED}

\TESTBlockHook
{OTHER HOOK: declared reversed}
{DECLARED REVERSED}

\OMIT
\begin{document}
\TIMO

\BEGINTEST{After \begin{document}}

\BEGINTEST{Commands}
\cmdA
\SEPARATOR
\cmdB
\ENDTEST

\ENDTEST

\TYPE{!!!! If this test changes the documentation needs updating !!!!}

\END
Loading

0 comments on commit d212bc2

Please sign in to comment.