diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-02-22 17:35:41 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-02-22 17:35:41 -0300 |
| commit | 06a46560944c0f2685222931362061a3f64db8b6 (patch) | |
| tree | 9cdff42d6fd166c89642f10e713ce8c536e15863 | |
| parent | b6badbab8ec8aac3741fb53f5343da37e966c7ac (diff) | |
| download | luarocks-06a46560944c0f2685222931362061a3f64db8b6.tar.gz luarocks-06a46560944c0f2685222931362061a3f64db8b6.tar.bz2 luarocks-06a46560944c0f2685222931362061a3f64db8b6.zip | |
Tests: add unit test for fs.is_file
| -rw-r--r-- | .busted | 2 | ||||
| -rw-r--r-- | spec/fs_spec.lua | 36 |
2 files changed, 38 insertions, 0 deletions
| @@ -1,5 +1,7 @@ | |||
| 1 | return { | 1 | return { |
| 2 | default = { | 2 | default = { |
| 3 | output = "gtest", | ||
| 4 | verbose = true, | ||
| 3 | helper = "spec.util.test_env", | 5 | helper = "spec.util.test_env", |
| 4 | ["auto-insulate"] = false | 6 | ["auto-insulate"] = false |
| 5 | } | 7 | } |
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index 17ac90ab..a6622f16 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua | |||
| @@ -2,6 +2,7 @@ local test_env = require("spec.util.test_env") | |||
| 2 | 2 | ||
| 3 | test_env.unload_luarocks() | 3 | test_env.unload_luarocks() |
| 4 | local fs = require("luarocks.fs") | 4 | local fs = require("luarocks.fs") |
| 5 | local lfs = require("lfs") | ||
| 5 | local is_win = test_env.TEST_TARGET_OS == "windows" | 6 | local is_win = test_env.TEST_TARGET_OS == "windows" |
| 6 | 7 | ||
| 7 | describe("Luarocks fs test #whitebox #w_fs", function() | 8 | describe("Luarocks fs test #whitebox #w_fs", function() |
| @@ -18,4 +19,39 @@ describe("Luarocks fs test #whitebox #w_fs", function() | |||
| 18 | assert.are.same(is_win and [["\\"%" \\\\" \\\\\\"]] or [['\% \\" \\\']], fs.Q([[\% \\" \\\]])) | 19 | assert.are.same(is_win and [["\\"%" \\\\" \\\\\\"]] or [['\% \\" \\\']], fs.Q([[\% \\" \\\]])) |
| 19 | end) | 20 | end) |
| 20 | end) | 21 | end) |
| 22 | |||
| 23 | describe("fs.is_file", function() | ||
| 24 | local tmpfile | ||
| 25 | local tmpdir | ||
| 26 | |||
| 27 | after_each(function() | ||
| 28 | if tmpfile then | ||
| 29 | os.remove(tmpfile) | ||
| 30 | tmpfile = nil | ||
| 31 | end | ||
| 32 | if tmpdir then | ||
| 33 | lfs.rmdir(tmpdir) | ||
| 34 | tmpdir = nil | ||
| 35 | end | ||
| 36 | end) | ||
| 37 | |||
| 38 | it("returns true when the argument is a file", function() | ||
| 39 | tmpfile = os.tmpname() | ||
| 40 | local fd = assert(io.open(tmpfile, "w")) | ||
| 41 | fd:write("foo") | ||
| 42 | fd:close() | ||
| 43 | assert.same(true, fs.is_file(tmpfile)) | ||
| 44 | end) | ||
| 45 | |||
| 46 | it("returns false when the argument does not exist", function() | ||
| 47 | assert.same(false, fs.is_file("/nonexistent")) | ||
| 48 | end) | ||
| 49 | |||
| 50 | it("returns false when arguments exists but is not a file", function() | ||
| 51 | tmpdir = os.tmpname() | ||
| 52 | os.remove(tmpdir) | ||
| 53 | lfs.mkdir(tmpdir) | ||
| 54 | assert.same(false, fs.is_file("/nonexistent")) | ||
| 55 | end) | ||
| 56 | end) | ||
| 21 | end) | 57 | end) |
