diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-04-03 11:32:49 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-04-03 11:32:49 -0300 |
| commit | 3f4f28010aa5065456f1edf97de1ab268cc49944 (patch) | |
| tree | 18ef631f33d1e71cf7f9d20b67d9148499a9dcf4 /testes | |
| parent | 93e347b51923a3f0b993aac37c74e1489c02f3b5 (diff) | |
| download | lua-3f4f28010aa5065456f1edf97de1ab268cc49944.tar.gz lua-3f4f28010aa5065456f1edf97de1ab268cc49944.tar.bz2 lua-3f4f28010aa5065456f1edf97de1ab268cc49944.zip | |
io.write returns number of written bytes on error
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/files.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/testes/files.lua b/testes/files.lua index 05fae49b..2c802047 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
| @@ -696,6 +696,37 @@ do | |||
| 696 | end | 696 | end |
| 697 | 697 | ||
| 698 | 698 | ||
| 699 | if T and T.nonblock then | ||
| 700 | print("testing failed write") | ||
| 701 | |||
| 702 | -- unable to write anything to /dev/full | ||
| 703 | local f = io.open("/dev/full", "w") | ||
| 704 | assert(f:setvbuf("no")) | ||
| 705 | local _, _, err, count = f:write("abcd") | ||
| 706 | assert(err > 0 and count == 0) | ||
| 707 | assert(f:close()) | ||
| 708 | |||
| 709 | -- receiver will read a "few" bytes (enough to empty a large buffer) | ||
| 710 | local receiver = [[ | ||
| 711 | lua -e 'assert(io.stdin:setvbuf("no")); assert(#io.read(1e4) == 1e4)' ]] | ||
| 712 | |||
| 713 | local f = io.popen(receiver, "w") | ||
| 714 | assert(f:setvbuf("no")) | ||
| 715 | T.nonblock(f) | ||
| 716 | |||
| 717 | -- able to write a few bytes | ||
| 718 | assert(f:write(string.rep("a", 1e2))) | ||
| 719 | |||
| 720 | -- Unable to write more bytes than the pipe buffer supports. | ||
| 721 | -- (In Linux, the pipe buffer size is 64K (2^16). Posix requires at | ||
| 722 | -- least 512 bytes.) | ||
| 723 | local _, _, err, count = f:write("abcd", string.rep("a", 2^17)) | ||
| 724 | assert(err > 0 and count >= 512 and count < 2^17) | ||
| 725 | |||
| 726 | assert(f:close()) | ||
| 727 | end | ||
| 728 | |||
| 729 | |||
| 699 | if not _soft then | 730 | if not _soft then |
| 700 | print("testing large files (> BUFSIZ)") | 731 | print("testing large files (> BUFSIZ)") |
| 701 | io.output(file) | 732 | io.output(file) |
