diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-26 17:47:28 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-27 13:28:33 -0300 |
| commit | 5cba4b83f60966045b86ac615df2692c953ebba7 (patch) | |
| tree | 445d1f58e589b53e4ee8cda5984f430f54fd2b36 /spec/unit/dir_spec.lua | |
| parent | 6bc6ede826843c3692971c14c27c3d27714b2126 (diff) | |
| download | luarocks-5cba4b83f60966045b86ac615df2692c953ebba7.tar.gz luarocks-5cba4b83f60966045b86ac615df2692c953ebba7.tar.bz2 luarocks-5cba4b83f60966045b86ac615df2692c953ebba7.zip | |
fix(fs): make current_dir always return 1 arg only
Diffstat (limited to 'spec/unit/dir_spec.lua')
| -rw-r--r-- | spec/unit/dir_spec.lua | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/unit/dir_spec.lua b/spec/unit/dir_spec.lua new file mode 100644 index 00000000..b5dadda8 --- /dev/null +++ b/spec/unit/dir_spec.lua | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | local test_env = require("spec.util.test_env") | ||
| 2 | local testing_paths = test_env.testing_paths | ||
| 3 | local P = test_env.P | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | test_env.setup_specs() | ||
| 7 | local dir = require("luarocks.dir") | ||
| 8 | |||
| 9 | describe("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 | |||
| 72 | end) | ||
