aboutsummaryrefslogtreecommitdiff
path: root/testes/files.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/files.lua')
-rw-r--r--testes/files.lua58
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
4global <const> *
5
4local debug = require "debug" 6local debug = require "debug"
5 7
6local maxint = math.maxinteger 8local maxint = math.maxinteger
@@ -347,7 +349,7 @@ collectgarbage()
347 349
348assert(io.write(' ' .. t .. ' ')) 350assert(io.write(' ' .. t .. ' '))
349assert(io.write(';', 'end of file\n')) 351assert(io.write(';', 'end of file\n'))
350f:flush(); io.flush() 352assert(f:flush()); assert(io.flush())
351f:close() 353f:close()
352print('+') 354print('+')
353 355
@@ -461,7 +463,24 @@ do -- testing closing file in line iteration
461end 463end
462 464
463 465
464-- test for multipe arguments in 'lines' 466do 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())
480end
481
482
483-- test for multiple arguments in 'lines'
465io.output(file); io.write"0123456789\n":close() 484io.output(file); io.write"0123456789\n":close()
466for a,b in io.lines(file, 1, 1) do 485for 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
696end 715end
697 716
698 717
718if 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())
746end
747
748
699if not _soft then 749if 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")
790local x = string.rep("a", 10000) 840local x = string.rep("a", 10000)
791assert(os.date(x) == x) 841assert(os.date(x) == x)
792local t = os.time() 842local t = os.time()
793D = os.date("*t", t) 843global D = os.date("*t", t)
794assert(os.date(string.rep("%d", 1000), t) == 844assert(os.date(string.rep("%d", 1000), t) ==
795 string.rep(os.date("%d", t), 1000)) 845 string.rep(os.date("%d", t), 1000))
796assert(os.date(string.rep("%", 200)) == string.rep("%", 100)) 846assert(os.date(string.rep("%", 200)) == string.rep("%", 100))
797 847
798local function checkDateTable (t) 848local 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