aboutsummaryrefslogtreecommitdiff
path: root/spec/dir_spec.lua
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-02-26 17:47:28 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-02-27 13:28:33 -0300
commit5cba4b83f60966045b86ac615df2692c953ebba7 (patch)
tree445d1f58e589b53e4ee8cda5984f430f54fd2b36 /spec/dir_spec.lua
parent6bc6ede826843c3692971c14c27c3d27714b2126 (diff)
downloadluarocks-5cba4b83f60966045b86ac615df2692c953ebba7.tar.gz
luarocks-5cba4b83f60966045b86ac615df2692c953ebba7.tar.bz2
luarocks-5cba4b83f60966045b86ac615df2692c953ebba7.zip
fix(fs): make current_dir always return 1 arg only
Diffstat (limited to 'spec/dir_spec.lua')
-rw-r--r--spec/dir_spec.lua72
1 files changed, 0 insertions, 72 deletions
diff --git a/spec/dir_spec.lua b/spec/dir_spec.lua
deleted file mode 100644
index b5dadda8..00000000
--- a/spec/dir_spec.lua
+++ /dev/null
@@ -1,72 +0,0 @@
1local test_env = require("spec.util.test_env")
2local testing_paths = test_env.testing_paths
3local P = test_env.P
4
5test_env.unload_luarocks()
6test_env.setup_specs()
7local dir = require("luarocks.dir")
8
9describe("luarocks.dir #unit", function()
10 local runner
11
12 setup(function()
13 runner = require("luacov.runner")
14 runner.init(testing_paths.testrun_dir .. "/luacov.config")
15 runner.tick = true
16 end)
17
18 teardown(function()
19 runner.shutdown()
20 end)
21
22 describe("dir.is_basic_protocol", function()
23 it("checks whether the arguments represent a valid protocol and returns the result of the check", function()
24 assert.truthy(dir.is_basic_protocol("http"))
25 assert.truthy(dir.is_basic_protocol("https"))
26 assert.truthy(dir.is_basic_protocol("ftp"))
27 assert.truthy(dir.is_basic_protocol("file"))
28 assert.falsy(dir.is_basic_protocol("git"))
29 assert.falsy(dir.is_basic_protocol("git+https"))
30 assert.falsy(dir.is_basic_protocol("invalid"))
31 end)
32 end)
33
34 describe("dir.deduce_base_dir", function()
35 it("deduces the base dir from archives", function()
36 assert.are.same("v0.3", dir.deduce_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3.zip"))
37 assert.are.same("lua-compat-5.2", dir.deduce_base_dir("https://example.com/hishamhm/lua-compat-5.2.zip"))
38 assert.are.same("lua-compat-5.2", dir.deduce_base_dir("https://example.com/hishamhm/lua-compat-5.2.tar.gz"))
39 assert.are.same("lua-compat-5.2", dir.deduce_base_dir("https://example.com/hishamhm/lua-compat-5.2.tar.bz2"))
40 end)
41 it("returns the basename when not given an archive", function()
42 assert.are.same("parser.moon", dir.deduce_base_dir("git://example.com/Cirru/parser.moon"))
43 assert.are.same("v0.3", dir.deduce_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3"))
44 end)
45 end)
46
47 describe("dir.normalize", function()
48 it("converts backslashes and removes trailing slashes", function()
49 assert.are.same(P"/foo/ovo", dir.normalize("\\foo\\ovo\\"))
50 assert.are.same(P"c:/some/dir", dir.normalize("c:\\..\\some\\foo\\..\\dir"))
51 assert.are.same("http://example.com/foo/ovo", dir.normalize("http://example.com/foo\\ovo\\"))
52 end)
53 it("strips unneeded /../ and /./", function()
54 assert.are.same(P"/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt"))
55 assert.are.same(P"/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt"))
56 assert.are.same(P"/some/dir", dir.normalize("/../../../some/./foo/bar/.././../dir/./some/subdir/../.."))
57 assert.are.same(P"/some/dir", dir.normalize("/../../../some/./foo/bar/.././../dir/./."))
58 end)
59 it("respects relative paths", function()
60 assert.are.same(P".", dir.normalize("."))
61 assert.are.same(P"boo", dir.normalize("./boo"))
62 assert.are.same(P"/boo", dir.normalize("/./boo"))
63 assert.are.same(P"../../../../boo", dir.normalize("../../../hello/world/../../../boo"))
64 end)
65 it("respects root directory", function()
66 assert.are.same(P"/", dir.normalize("/"))
67 assert.are.same(P"/", dir.normalize("/////"))
68 assert.are.same(P"/", dir.normalize("/a/b/.././../c/./../../"))
69 end)
70 end)
71
72end)