From adc89f7977ae4b1e86cb413fb52406865150b064 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 15 Aug 2022 09:08:24 +0100 Subject: Add unit tests for pkgmgr.install_dir --- builtin/mainmenu/pkgmgr.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'builtin/mainmenu/pkgmgr.lua') diff --git a/builtin/mainmenu/pkgmgr.lua b/builtin/mainmenu/pkgmgr.lua index 3028295c8..9fa9aebb0 100644 --- a/builtin/mainmenu/pkgmgr.lua +++ b/builtin/mainmenu/pkgmgr.lua @@ -244,11 +244,7 @@ end -------------------------------------------------------------------------------- function pkgmgr.is_valid_modname(modpath) - if modpath:find("-") ~= nil then - return false - end - - return true + return modpath:match("[^a-z0-9_]") == nil end -------------------------------------------------------------------------------- @@ -521,6 +517,8 @@ function pkgmgr.install_dir(expected_type, path, basename, targetpath) local basefolder = pkgmgr.get_base_folder(path) if expected_type == "txp" then + assert(basename) + -- There's no good way to detect a texture pack, so let's just assume -- it's correct for now. if basefolder and basefolder.type ~= "invalid" and basefolder.type ~= "txp" then @@ -544,7 +542,7 @@ function pkgmgr.install_dir(expected_type, path, basename, targetpath) -- Check type if basefolder.type ~= expected_type and (basefolder.type ~= "modpack" or expected_type ~= "mod") then - return nil, fgettext("Unable to install a $1 as a $1", basefolder.type, expected_type) + return nil, fgettext("Unable to install a $1 as a $2", basefolder.type, expected_type) end -- Set targetpath if not predetermined -- cgit v1.2.3