summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/luv/tests/test-fs.lua
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-02-21 11:48:45 +0100
committer ImJezze <jezze@gmx.net>2016-02-21 11:48:45 +0100
commitcc24a339d8c0517259084b5c178d784626ba965c (patch)
tree9868e9687b5802ae0a3733712a3bbeb3bc75c953 /3rdparty/luv/tests/test-fs.lua
parentb5daabda5495dea5c50e17961ecfed2ea8619d76 (diff)
Merge remote-tracking branch 'refs/remotes/mamedev/master'
Second attempt
Diffstat (limited to '3rdparty/luv/tests/test-fs.lua')
-rw-r--r--3rdparty/luv/tests/test-fs.lua90
1 files changed, 90 insertions, 0 deletions
diff --git a/3rdparty/luv/tests/test-fs.lua b/3rdparty/luv/tests/test-fs.lua
new file mode 100644
index 00000000000..4bfd67e6578
--- /dev/null
+++ b/3rdparty/luv/tests/test-fs.lua
@@ -0,0 +1,90 @@
+return require('lib/tap')(function (test)
+
+ test("read a file sync", function (print, p, expect, uv)
+ local fd = assert(uv.fs_open('README.md', 'r', tonumber('644', 8)))
+ p{fd=fd}
+ local stat = assert(uv.fs_fstat(fd))
+ p{stat=stat}
+ local chunk = assert(uv.fs_read(fd, stat.size, 0))
+ assert(#chunk == stat.size)
+ assert(uv.fs_close(fd))
+ end)
+
+ test("read a file async", function (print, p, expect, uv)
+ uv.fs_open('README.md', 'r', tonumber('644', 8), expect(function (err, fd)
+ assert(not err, err)
+ p{fd=fd}
+ uv.fs_fstat(fd, expect(function (err, stat)
+ assert(not err, err)
+ p{stat=stat}
+ uv.fs_read(fd, stat.size, 0, expect(function (err, chunk)
+ assert(not err, err)
+ p{chunk=#chunk}
+ assert(#chunk == stat.size)
+ uv.fs_close(fd, expect(function (err)
+ assert(not err, err)
+ end))
+ end))
+ end))
+ end))
+ end)
+
+ test("fs.write", function (print, p, expect, uv)
+ local path = "_test_"
+ local fd = assert(uv.fs_open(path, "w", 438))
+ uv.fs_write(fd, "Hello World\n", -1)
+ uv.fs_write(fd, {"with\n", "more\n", "lines\n"}, -1)
+ uv.fs_close(fd)
+ uv.fs_unlink(path)
+ end)
+
+ test("fs.stat sync", function (print, p, expect, uv)
+ local stat = assert(uv.fs_stat("README.md"))
+ assert(stat.size)
+ end)
+
+ test("fs.stat async", function (print, p, expect, uv)
+ assert(uv.fs_stat("README.md", expect(function (err, stat)
+ assert(not err, err)
+ assert(stat.size)
+ end)))
+ end)
+
+ test("fs.stat sync error", function (print, p, expect, uv)
+ local stat, err, code = uv.fs_stat("BAD_FILE!")
+ p{err=err,code=code,stat=stat}
+ assert(not stat)
+ assert(err)
+ assert(code == "ENOENT")
+ end)
+
+ test("fs.stat async error", function (print, p, expect, uv)
+ assert(uv.fs_stat("BAD_FILE@", expect(function (err, stat)
+ p{err=err,stat=stat}
+ assert(err)
+ assert(not stat)
+ end)))
+ end)
+
+ test("fs.scandir", function (print, p, expect, uv)
+ local req = uv.fs_scandir('.')
+ local function iter()
+ return uv.fs_scandir_next(req)
+ end
+ for name, ftype in iter do
+ p{name=name, ftype=ftype}
+ assert(name)
+ -- ftype is not available in all filesystems; for example it's
+ -- provided for HFS+ (OSX), NTFS (Windows) but not for ext4 (Linux).
+ end
+ end)
+
+ test("fs.realpath", function (print, p, expect, uv)
+ p(assert(uv.fs_realpath('.')))
+ assert(uv.fs_realpath('.', expect(function (err, path)
+ assert(not err, err)
+ p(path)
+ end)))
+ end)
+
+end)