From 22911efbba782fd1fc235a72ee6a3e5f4610924f Mon Sep 17 00:00:00 2001 From: Reinis Cirpons <43414125+reiniscirpons@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:38:32 +0000 Subject: [PATCH] Fix issue with Test when rewriteToFile is set (#5686) --- lib/test.gi | 10 +- .../2024-03-20-Test-rewriteToFile-option.tst | 332 ++++++++++++++++++ 2 files changed, 339 insertions(+), 3 deletions(-) create mode 100644 tst/testbugfix/2024-03-20-Test-rewriteToFile-option.tst diff --git a/lib/test.gi b/lib/test.gi index ef875501aa..3de30989a5 100644 --- a/lib/test.gi +++ b/lib/test.gi @@ -718,9 +718,13 @@ InstallGlobalFunction("Test", function(arg) od; for i in [1..Length(pf.inp)] do new[pf.pos[i]] := ""; - for j in [1..Number(pf.inp[i], c-> c = '\n')] do - Append(new[pf.pos[i]], lines[pf.pos[i]+j-1]); - Add(new[pf.pos[i]], '\n'); + for j in [1 .. Number(pf.inp[i], c -> c = '\n') + + Number(pf.outp[i], c -> c = '\n')] do + if (j = 1 and StartsWith(lines[pf.pos[i] + j - 1], "gap> ")) or + (j > 1 and StartsWith(lines[pf.pos[i] + j - 1], "> ")) then + Append(new[pf.pos[i]], lines[pf.pos[i] + j - 1]); + Add(new[pf.pos[i]], '\n'); + fi; od; if PositionSublist(pf.inp[i], "STOP_TEST") <> 1 then Append(new[pf.pos[i]], pf.cmp[i]); diff --git a/tst/testbugfix/2024-03-20-Test-rewriteToFile-option.tst b/tst/testbugfix/2024-03-20-Test-rewriteToFile-option.tst new file mode 100644 index 0000000000..e878536b40 --- /dev/null +++ b/tst/testbugfix/2024-03-20-Test-rewriteToFile-option.tst @@ -0,0 +1,332 @@ +# Fix issue with `rewriteToFile` option in test cases with mixed input/output +# See https://github.com/gap-system/gap/issues/5685 +gap> temp_dir := DirectoryTemporary();; +gap> FileString(Filename(temp_dir, "test_in_001.tst"), \ +> """gap> if true then +> > Print("true\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> """);; +gap> Test(Filename(temp_dir, "test_in_001.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_001.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_001.tst")) = \ +> """gap> if true then +> > Print("true\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> """; +true +gap> temp_dir := DirectoryTemporary();; +gap> FileString(Filename(temp_dir, "test_in_002.tst"), \ +> """gap> if true then +> > Print("true\n"); +> true +> > else +> > Print("false\n"); +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_002.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_002.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_002.tst")) = \ +> """gap> if true then +> > Print("true\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> """; +true +gap> FileString(Filename(temp_dir, "test_in_003.tst"), \ +> """gap> if true then +> true +> > Print("true\n"); +> > else +> > Print("false\n"); +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_003.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_003.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_003.tst")) = \ +> """gap> if true then +> > Print("true\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> """; +true +gap> FileString(Filename(temp_dir, "test_in_004.tst"), \ +> """gap> if true then +> > Print("true\n"); +> > else +> true +> > Print("false\n"); +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_004.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_004.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_004.tst")) = \ +> """gap> if true then +> > Print("true\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> """; +true +gap> FileString(Filename(temp_dir, "test_in_005.tst"), \ +> """gap> if true then +> > Print("true\n"); +> > else +> > Print("false\n"); +> true +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_005.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_005.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_005.tst")) = \ +> """gap> if true then +> > Print("true\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> """; +true +gap> FileString(Filename(temp_dir, "test_in_006.tst"), \ +> """gap> if true then +> > Print("true\nfail\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> """);; +gap> Test(Filename(temp_dir, "test_in_006.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_006.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_006.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> """; +true +gap> FileString(Filename(temp_dir, "test_in_007.tst"), \ +> """gap> if true then +> > Print("true\nfail\n"); +> true +> > else +> > Print("false\n"); +> > fi; +> fail +> """);; +gap> Test(Filename(temp_dir, "test_in_007.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_007.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_007.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> """; +true +gap> FileString(Filename(temp_dir, "test_in_008.tst"), \ +> """gap> if true then +> > Print("true\nfail\n"); +> true +> > else +> > Print("false\n"); +> fail +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_008.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_008.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_008.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> """; +true +gap> FileString(Filename(temp_dir, "test_in_009.tst"), \ +> """gap> if true then +> > Print("true\nfail\n"); +> true +> fail +> > else +> > Print("false\n"); +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_009.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_009.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_009.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> """; +true +gap> FileString(Filename(temp_dir, "test_in_010.tst"), \ +> """gap> if true then +> true +> > Print("true\nfail\n"); +> fail +> > else +> > Print("false\n"); +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_010.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_010.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_010.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> """; +true +gap> FileString(Filename(temp_dir, "test_in_011.tst"), \ +> """gap> if true then +> true +> fail +> +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_011.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_011.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_011.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> +> """; +true +gap> FileString(Filename(temp_dir, "test_in_012.tst"), \ +> """gap> if true then +> true +> fail +> +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> gap> Print("Hello\nWorld\n"); +> Hello +> World +> """);; +gap> Test(Filename(temp_dir, "test_in_012.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_012.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_012.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> +> gap> Print("Hello\nWorld\n"); +> Hello +> World +> """; +true +gap> FileString(Filename(temp_dir, "test_in_013.tst"), \ +> """gap> if true then +> true +> fail +> +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> +> # New test case +> gap> Print("Hello\nWorld\n"); +> Hello +> World +> """);; +gap> Test(Filename(temp_dir, "test_in_013.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_013.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_013.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> +> +> # New test case +> gap> Print("Hello\nWorld\n"); +> Hello +> World +> """; +true +gap> FileString(Filename(temp_dir, "test_in_014.tst"), \ +> """gap> if true then +> true +> fail +> +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> +> # New test case +> gap> if true then +> true +> fail +> +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> """);; +gap> Test(Filename(temp_dir, "test_in_014.tst"), +> rec(rewriteToFile := Filename(temp_dir, "test_out_014.tst")));; +gap> StringFile(Filename(temp_dir, "test_out_014.tst")) = \ +> """gap> if true then +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> +> +> # New test case +> gap> if true then +> > Print("true\nfail\n\n"); +> > else +> > Print("false\n"); +> > fi; +> true +> fail +> +> """; +true