Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how Test handles #@exec comments in .tst files (by executing these earlier to allow #@if comments to depend on them) #5049

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/test.gi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
## end;

InstallGlobalFunction(ParseTestInput, function(str, ignorecomments, fnam)
local lines, inp, pos, outp, ign, commands, i, skipstate, checkifelseendif, foundcmd, testError;
local lines, inp, pos, outp, ign, commands, i, skipstate, checkifelsefi, foundcmd, testError;
lines := SplitString(str, "\n", "");
inp := [];
pos := [];
Expand All @@ -31,8 +31,8 @@ InstallGlobalFunction(ParseTestInput, function(str, ignorecomments, fnam)
ErrorNoReturn(s, " at ", fnam, ":", i);
fi;
end;
checkifelseendif := l -> ForAny(["#@if","#@else","#@fi"], x -> StartsWith(l, x));
# Set to true if we find a #@if, #@else or #@endif. Used to check these do not
checkifelsefi := l -> ForAny(["#@if","#@else","#@fi"], x -> StartsWith(l, x));
# Set to true if we find a #@if, #@else or #@fi. Used to check these do not
# occur in the middle of a single input/output test block.
foundcmd := false;
# skipstate represents the current status of '#@if/#@else/#@fi'
Expand All @@ -44,7 +44,7 @@ InstallGlobalFunction(ParseTestInput, function(str, ignorecomments, fnam)
# Code is executed whenever skipstate >= 0
skipstate := 0;
while i <= Length(lines) do
if checkifelseendif(lines[i]) then
if checkifelsefi(lines[i]) then
foundcmd := true;
Add(ign, i);
if StartsWith(lines[i], "#@if") then
Expand Down Expand Up @@ -87,7 +87,10 @@ InstallGlobalFunction(ParseTestInput, function(str, ignorecomments, fnam)
if ignorecomments = true then
# ignore comment lines and empty lines at beginning of file
Add(ign, i);
if Length(lines[i]) > 3 and lines[i]{[1..2]} = "#@" then
# execute `#@exec` immediately so `#@if` can depend on it
if StartsWith(lines[i], "#@exec") then
Read(InputTextString(Concatenation(lines[i]{[7..Length(lines[i])]}, ";\n")));
elif Length(lines[i]) > 3 and lines[i]{[1..2]} = "#@" then
Add(commands, lines[i]);
fi;
i := i+1;
Expand Down Expand Up @@ -346,7 +349,12 @@ end);
## <C>#@if</C> are used until either a <C>#@else</C> or <C>#@fi</C> is
## reached. If a <C>#@else</C> is present then the code after the <C>#@else</C>
## is used if and only if <C>EXPR</C> evaluated to <K>false</K>. Finally,
## once <C>#endif</C> is reached, evaluation continues normally.
## once <C>#fi</C> is reached, evaluation continues normally.
## <P/>
## Note that <C>EXPR</C> is evaluated after all <C>#@exec</C> lines have been
## executed but before any tests are run. Thus, it cannot depend on test
## results or packages loaded in tests, but it can depend on packages loaded
## via <C>#@exec</C>.
## </Item>
## </List>
## By default the actual &GAP; output is compared exactly with the
Expand Down Expand Up @@ -648,8 +656,6 @@ InstallGlobalFunction("Test", function(arg)
else
opts.localdef := Concatenation(opts.localdef, ", ", line);
fi;
elif StartsWith(line, "#@exec") then
Read(InputTextString(Concatenation(line{[7..Length(line)]}, ";\n")));
else
ErrorNoReturn("Invalid #@ test option: ", line);
fi;
Expand Down