Skip to content

Commit

Permalink
tst: fix file descriptor leaks (#5568)
Browse files Browse the repository at this point in the history
This is a step towards fixing the `testinstall` test suite on macOS,
where the maximum number of file descriptors seems to exactly match our
limit, so any leaked descriptor causes the 'too many open files' test in
`tst/testinstall/streams.tst` to fail in an unexpected way (namely
because instead of the expected error, OutputTextFile returns 'fail').

Co-authored-by: Chris Jefferson <caj21@st-andrews.ac.uk>
  • Loading branch information
fingolfin and ChrisJefferson authored Jan 10, 2024
1 parent da64791 commit e00b01f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions tst/testbugfix/2006-10-23-t00163.tst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gap> List([0..255], i-> ReadByte(f)) = a;
true
gap> RemoveFile(fnam);
true
gap> CloseStream(f);
11 changes: 7 additions & 4 deletions tst/testinstall/compressed.tst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ gap> rawfname := Filename(dir, "rawtest.g.gz");;
# Let us check when we have written a compressed file by checking the gzip header
# We need raw file access to do this, so we use 'IO'. We stub out this part of the
# test if IO is not loaded
#@if IsPackageLoaded("IO")
gap> checkGzippedFile := function(fname, expected)
> local ins, str;
> if not IsPackageLoaded("IO") then return true; fi;
> # Use 'ValueGlobal' to avoid warnings about undefined functions
> ins := ValueGlobal("IO_File")(fname, "r");
> str := ValueGlobal("IO_Read")(ins, 2);;
> ins := IO_File(fname, "r");
> str := IO_Read(ins, 2);
> IO_Close(ins);
> # All gzipped files should start with these two characters
> return (str = [CharInt(31),CharInt(139)]) = expected;
> end;;
#@else
gap> checkGzippedFile := ReturnTrue;;
#@fi
gap> str := "hello\ngoodbye\n";;

# Write an uncompressed file
Expand Down
6 changes: 6 additions & 0 deletions tst/testinstall/read.tst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ gap> SeekPositionStream(x, 3);
true
gap> ReadAll(x);
"lo\ngoodbye\ni like pies\n"
gap> CloseStream(x);

#
gap> x := InputTextString("hello\ngoodbye\ni like pies\n");;
gap> ReadLine(x);
"hello\n"
Expand Down Expand Up @@ -65,6 +68,9 @@ gap> SeekPositionStream(x, 3);
true
gap> ReadAll(x);
"lo\ngoodbye\ni like pies\n"
gap> CloseStream(x);

#
gap> x := StringFile(Filename( DirectoriesLibrary("tst"), "example.txt" ));;
gap> ReplacedString(x, "\r\n", "\n");
"hello\ngoodbye\ni like pies\n"
Expand Down
1 change: 1 addition & 0 deletions tst/testinstall/streams.tst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ gap> file := InputTextFile( fname );;
gap> repeat
> line := ReadLine( file );
> until line = fail;
gap> CloseStream(file);

# Invalid files
gap> PrintTo("/", "out");
Expand Down

0 comments on commit e00b01f

Please sign in to comment.