diff options
Diffstat (limited to 'testes/files.lua')
-rw-r--r-- | testes/files.lua | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/testes/files.lua b/testes/files.lua index 05fae49b..7146ac7c 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
@@ -1,6 +1,8 @@ | |||
1 | -- $Id: testes/files.lua $ | 1 | -- $Id: testes/files.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global <const> * | ||
5 | |||
4 | local debug = require "debug" | 6 | local debug = require "debug" |
5 | 7 | ||
6 | local maxint = math.maxinteger | 8 | local maxint = math.maxinteger |
@@ -347,7 +349,7 @@ collectgarbage() | |||
347 | 349 | ||
348 | assert(io.write(' ' .. t .. ' ')) | 350 | assert(io.write(' ' .. t .. ' ')) |
349 | assert(io.write(';', 'end of file\n')) | 351 | assert(io.write(';', 'end of file\n')) |
350 | f:flush(); io.flush() | 352 | assert(f:flush()); assert(io.flush()) |
351 | f:close() | 353 | f:close() |
352 | print('+') | 354 | print('+') |
353 | 355 | ||
@@ -461,7 +463,24 @@ do -- testing closing file in line iteration | |||
461 | end | 463 | end |
462 | 464 | ||
463 | 465 | ||
464 | -- test for multipe arguments in 'lines' | 466 | do print("testing flush") |
467 | local f = io.output("/dev/null") | ||
468 | assert(f:write("abcd")) -- write to buffer | ||
469 | assert(f:flush()) -- write to device | ||
470 | assert(f:write("abcd")) -- write to buffer | ||
471 | assert(io.flush()) -- write to device | ||
472 | assert(f:close()) | ||
473 | |||
474 | local f = io.output("/dev/full") | ||
475 | assert(f:write("abcd")) -- write to buffer | ||
476 | assert(not f:flush()) -- cannot write to device | ||
477 | assert(f:write("abcd")) -- write to buffer | ||
478 | assert(not io.flush()) -- cannot write to device | ||
479 | assert(f:close()) | ||
480 | end | ||
481 | |||
482 | |||
483 | -- test for multiple arguments in 'lines' | ||
465 | io.output(file); io.write"0123456789\n":close() | 484 | io.output(file); io.write"0123456789\n":close() |
466 | for a,b in io.lines(file, 1, 1) do | 485 | for a,b in io.lines(file, 1, 1) do |
467 | if a == "\n" then assert(not b) | 486 | if a == "\n" then assert(not b) |
@@ -696,6 +715,37 @@ do | |||
696 | end | 715 | end |
697 | 716 | ||
698 | 717 | ||
718 | if T and T.nonblock and not _port then | ||
719 | print("testing failed write") | ||
720 | |||
721 | -- unable to write anything to /dev/full | ||
722 | local f = io.open("/dev/full", "w") | ||
723 | assert(f:setvbuf("no")) | ||
724 | local _, _, err, count = f:write("abcd") | ||
725 | assert(err > 0 and count == 0) | ||
726 | assert(f:close()) | ||
727 | |||
728 | -- receiver will read a "few" bytes (enough to empty a large buffer) | ||
729 | local receiver = [[ | ||
730 | lua -e 'assert(io.stdin:setvbuf("no")); assert(#io.read(1e4) == 1e4)' ]] | ||
731 | |||
732 | local f = io.popen(receiver, "w") | ||
733 | assert(f:setvbuf("no")) | ||
734 | T.nonblock(f) | ||
735 | |||
736 | -- able to write a few bytes | ||
737 | assert(f:write(string.rep("a", 1e2))) | ||
738 | |||
739 | -- Unable to write more bytes than the pipe buffer supports. | ||
740 | -- (In Linux, the pipe buffer size is 64K (2^16). Posix requires at | ||
741 | -- least 512 bytes.) | ||
742 | local _, _, err, count = f:write("abcd", string.rep("a", 2^17)) | ||
743 | assert(err > 0 and count >= 512 and count < 2^17) | ||
744 | |||
745 | assert(f:close()) | ||
746 | end | ||
747 | |||
748 | |||
699 | if not _soft then | 749 | if not _soft then |
700 | print("testing large files (> BUFSIZ)") | 750 | print("testing large files (> BUFSIZ)") |
701 | io.output(file) | 751 | io.output(file) |
@@ -790,13 +840,13 @@ assert(os.date("!\0\0") == "\0\0") | |||
790 | local x = string.rep("a", 10000) | 840 | local x = string.rep("a", 10000) |
791 | assert(os.date(x) == x) | 841 | assert(os.date(x) == x) |
792 | local t = os.time() | 842 | local t = os.time() |
793 | D = os.date("*t", t) | 843 | global D = os.date("*t", t) |
794 | assert(os.date(string.rep("%d", 1000), t) == | 844 | assert(os.date(string.rep("%d", 1000), t) == |
795 | string.rep(os.date("%d", t), 1000)) | 845 | string.rep(os.date("%d", t), 1000)) |
796 | assert(os.date(string.rep("%", 200)) == string.rep("%", 100)) | 846 | assert(os.date(string.rep("%", 200)) == string.rep("%", 100)) |
797 | 847 | ||
798 | local function checkDateTable (t) | 848 | local function checkDateTable (t) |
799 | _G.D = os.date("*t", t) | 849 | D = os.date("*t", t) |
800 | assert(os.time(D) == t) | 850 | assert(os.time(D) == t) |
801 | load(os.date([[assert(D.year==%Y and D.month==%m and D.day==%d and | 851 | load(os.date([[assert(D.year==%Y and D.month==%m and D.day==%d and |
802 | D.hour==%H and D.min==%M and D.sec==%S and | 852 | D.hour==%H and D.min==%M and D.sec==%S and |