From b522656085991297b3ccd0793b5d744653b24dfe Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 6 Jun 2019 11:47:43 -0300 Subject: Tests: add tests for fs.is_file and fs.is_dir with symlinks Regression test for #1021. --- spec/fs_spec.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'spec') diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index 631d15c6..0acca613 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua @@ -377,6 +377,24 @@ describe("Luarocks fs test #unit", function() lfs.mkdir(tmpdir) assert.same(false, fs.is_file("/nonexistent")) end) + + it("#unix returns false when the argument is a symlink to a directory", function() + tmpdir = get_tmp_path() + lfs.mkdir(tmpdir) + local linkname = tmpdir .. "/symlink" + finally(function() os.remove(linkname) end) + lfs.link(tmpdir, linkname, true) + assert.falsy(fs.is_file(linkname)) + end) + + it("#unix returns true when the argument is a symlink to a file", function() + tmpfile = get_tmp_path() + create_file(tmpfile) + local linkname = tmpfile .. "_symlink" + finally(function() os.remove(linkname) end) + lfs.link(tmpfile, linkname, true) + assert.truthy(fs.is_file(linkname)) + end) end) describe("fs.is_dir", function() @@ -406,6 +424,24 @@ describe("Luarocks fs test #unit", function() assert.falsy(fs.is_dir(tmpfile)) end) + it("#unix returns true when the argument is a symlink to a directory", function() + tmpdir = get_tmp_path() + lfs.mkdir(tmpdir) + local linkname = tmpdir .. "/symlink" + finally(function() os.remove(linkname) end) + lfs.link(tmpdir, linkname, true) + assert.truthy(fs.is_dir(linkname)) + end) + + it("#unix returns false when the argument is a symlink to a file", function() + tmpfile = get_tmp_path() + create_file(tmpfile) + local linkname = tmpfile .. "_symlink" + finally(function() os.remove(linkname) end) + lfs.link(tmpfile, linkname, true) + assert.falsy(fs.is_dir(linkname)) + end) + it("returns false when the argument does not exist", function() assert.falsy(fs.is_dir("/nonexistent")) end) -- cgit v1.2.3-55-g6feb