diff options
-rw-r--r-- | src/luarocks/fetch.lua | 7 | ||||
-rw-r--r-- | test/testing.lua | 12 | ||||
-rwxr-xr-x | test/testing.sh | 13 |
3 files changed, 31 insertions, 1 deletions
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 686aadcd..e92aeddf 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
@@ -170,8 +170,13 @@ function fetch.fetch_and_unpack_rock(rock_file, dest) | |||
170 | end | 170 | end |
171 | 171 | ||
172 | function fetch.url_to_base_dir(url) | 172 | function fetch.url_to_base_dir(url) |
173 | -- for extensions like foo.tar.gz, "gz" is stripped first | ||
174 | local known_exts = {} | ||
175 | for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do | ||
176 | known_exts[ext] = "" | ||
177 | end | ||
173 | local base = dir.base_name(url) | 178 | local base = dir.base_name(url) |
174 | return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") | 179 | return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", "")) |
175 | end | 180 | end |
176 | 181 | ||
177 | --- Back-end function that actually loads the local rockspec. | 182 | --- Back-end function that actually loads the local rockspec. |
diff --git a/test/testing.lua b/test/testing.lua index 50911fd4..63dead2b 100644 --- a/test/testing.lua +++ b/test/testing.lua | |||
@@ -441,5 +441,17 @@ local tests = { | |||
441 | return run "$luarocks install luarepl" | 441 | return run "$luarocks install luarepl" |
442 | and run "$luarocks doc luarepl" | 442 | and run "$luarocks doc luarepl" |
443 | end, | 443 | end, |
444 | |||
445 | -- Tests for https://github.com/keplerproject/luarocks/issues/375 | ||
446 | test_fetch_base_dir = function() | ||
447 | local fetch = require "luarocks.fetch" | ||
448 | |||
449 | return assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | ||
450 | and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) | ||
451 | and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) | ||
452 | and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) | ||
453 | and assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) | ||
454 | and assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) | ||
455 | end | ||
444 | 456 | ||
445 | } | 457 | } |
diff --git a/test/testing.sh b/test/testing.sh index 133597ee..6219a38f 100755 --- a/test/testing.sh +++ b/test/testing.sh | |||
@@ -511,6 +511,19 @@ fail_config_user_config() { LUAROCKS_CONFIG="/missing_file.lua" $luarocks config | |||
511 | test_config_rock_trees() { $luarocks config --rock-trees; } | 511 | test_config_rock_trees() { $luarocks config --rock-trees; } |
512 | test_config_help() { $luarocks help config; } | 512 | test_config_help() { $luarocks help config; } |
513 | 513 | ||
514 | # Tests for https://github.com/keplerproject/luarocks/issues/375 | ||
515 | test_fetch_base_dir() { $lua <<EOF | ||
516 | local fetch = require "luarocks.fetch" | ||
517 | |||
518 | assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | ||
519 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) | ||
520 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) | ||
521 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) | ||
522 | assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) | ||
523 | assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) | ||
524 | EOF | ||
525 | } | ||
526 | |||
514 | test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } | 527 | test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } |
515 | 528 | ||
516 | # Driver ######################################### | 529 | # Driver ######################################### |