local test_env = require("spec.util.test_env") test_env.unload_luarocks() local fs = require("luarocks.fs") local lfs = require("lfs") local is_win = test_env.TEST_TARGET_OS == "windows" describe("Luarocks fs test #whitebox #w_fs", function() describe("fs.Q", function() it("simple argument", function() assert.are.same(is_win and '"foo"' or "'foo'", fs.Q("foo")) end) it("argument with quotes", function() assert.are.same(is_win and [["it's \"quoting\""]] or [['it'\''s "quoting"']], fs.Q([[it's "quoting"]])) end) it("argument with special characters", function() assert.are.same(is_win and [["\\"%" \\\\" \\\\\\"]] or [['\% \\" \\\']], fs.Q([[\% \\" \\\]])) end) end) describe("fs.is_file", function() local tmpfile local tmpdir after_each(function() if tmpfile then os.remove(tmpfile) tmpfile = nil end if tmpdir then lfs.rmdir(tmpdir) tmpdir = nil end end) it("returns true when the argument is a file", function() tmpfile = os.tmpname() local fd = assert(io.open(tmpfile, "w")) fd:write("foo") fd:close() assert.same(true, fs.is_file(tmpfile)) end) it("returns false when the argument does not exist", function() assert.same(false, fs.is_file("/nonexistent")) end) it("returns false when arguments exists but is not a file", function() tmpdir = os.tmpname() os.remove(tmpdir) lfs.mkdir(tmpdir) assert.same(false, fs.is_file("/nonexistent")) end) end) end)