aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.busted2
-rw-r--r--spec/fs_spec.lua36
2 files changed, 38 insertions, 0 deletions
diff --git a/.busted b/.busted
index 8b246f0c..a77c8dae 100644
--- a/.busted
+++ b/.busted
@@ -1,5 +1,7 @@
1return { 1return {
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
3test_env.unload_luarocks() 3test_env.unload_luarocks()
4local fs = require("luarocks.fs") 4local fs = require("luarocks.fs")
5local lfs = require("lfs")
5local is_win = test_env.TEST_TARGET_OS == "windows" 6local is_win = test_env.TEST_TARGET_OS == "windows"
6 7
7describe("Luarocks fs test #whitebox #w_fs", function() 8describe("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)
21end) 57end)