Skip to content

Commit

Permalink
tst: fix file descriptor leaks
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').
  • Loading branch information
fingolfin committed Jan 9, 2024
1 parent 5ae6e1e commit 2a7b9a1
Show file tree
Hide file tree
Showing 3 changed files with 14 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

0 comments on commit 2a7b9a1

Please sign in to comment.