diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-06 11:47:43 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-06 14:12:32 -0300 |
| commit | b522656085991297b3ccd0793b5d744653b24dfe (patch) | |
| tree | 368280dcaf417db354dd53d51b968f33882f4449 | |
| parent | f82627800d09755412bc50cbf9f1f964d1b2c5be (diff) | |
| download | luarocks-b522656085991297b3ccd0793b5d744653b24dfe.tar.gz luarocks-b522656085991297b3ccd0793b5d744653b24dfe.tar.bz2 luarocks-b522656085991297b3ccd0793b5d744653b24dfe.zip | |
Tests: add tests for fs.is_file and fs.is_dir with symlinks
Regression test for #1021.
| -rw-r--r-- | spec/fs_spec.lua | 36 |
1 files changed, 36 insertions, 0 deletions
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() | |||
| 377 | lfs.mkdir(tmpdir) | 377 | lfs.mkdir(tmpdir) |
| 378 | assert.same(false, fs.is_file("/nonexistent")) | 378 | assert.same(false, fs.is_file("/nonexistent")) |
| 379 | end) | 379 | end) |
| 380 | |||
| 381 | it("#unix returns false when the argument is a symlink to a directory", function() | ||
| 382 | tmpdir = get_tmp_path() | ||
| 383 | lfs.mkdir(tmpdir) | ||
| 384 | local linkname = tmpdir .. "/symlink" | ||
| 385 | finally(function() os.remove(linkname) end) | ||
| 386 | lfs.link(tmpdir, linkname, true) | ||
| 387 | assert.falsy(fs.is_file(linkname)) | ||
| 388 | end) | ||
| 389 | |||
| 390 | it("#unix returns true when the argument is a symlink to a file", function() | ||
| 391 | tmpfile = get_tmp_path() | ||
| 392 | create_file(tmpfile) | ||
| 393 | local linkname = tmpfile .. "_symlink" | ||
| 394 | finally(function() os.remove(linkname) end) | ||
| 395 | lfs.link(tmpfile, linkname, true) | ||
| 396 | assert.truthy(fs.is_file(linkname)) | ||
| 397 | end) | ||
| 380 | end) | 398 | end) |
| 381 | 399 | ||
| 382 | describe("fs.is_dir", function() | 400 | describe("fs.is_dir", function() |
| @@ -406,6 +424,24 @@ describe("Luarocks fs test #unit", function() | |||
| 406 | assert.falsy(fs.is_dir(tmpfile)) | 424 | assert.falsy(fs.is_dir(tmpfile)) |
| 407 | end) | 425 | end) |
| 408 | 426 | ||
| 427 | it("#unix returns true when the argument is a symlink to a directory", function() | ||
| 428 | tmpdir = get_tmp_path() | ||
| 429 | lfs.mkdir(tmpdir) | ||
| 430 | local linkname = tmpdir .. "/symlink" | ||
| 431 | finally(function() os.remove(linkname) end) | ||
| 432 | lfs.link(tmpdir, linkname, true) | ||
| 433 | assert.truthy(fs.is_dir(linkname)) | ||
| 434 | end) | ||
| 435 | |||
| 436 | it("#unix returns false when the argument is a symlink to a file", function() | ||
| 437 | tmpfile = get_tmp_path() | ||
| 438 | create_file(tmpfile) | ||
| 439 | local linkname = tmpfile .. "_symlink" | ||
| 440 | finally(function() os.remove(linkname) end) | ||
| 441 | lfs.link(tmpfile, linkname, true) | ||
| 442 | assert.falsy(fs.is_dir(linkname)) | ||
| 443 | end) | ||
| 444 | |||
| 409 | it("returns false when the argument does not exist", function() | 445 | it("returns false when the argument does not exist", function() |
| 410 | assert.falsy(fs.is_dir("/nonexistent")) | 446 | assert.falsy(fs.is_dir("/nonexistent")) |
| 411 | end) | 447 | end) |
