From 2f3c8648289bb4e22eee5f8ff8d27afca6592fa4 Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 21 Aug 2016 21:50:38 +0200 Subject: Windows and appveyor support for tests --- spec/util_spec.lua | 59 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'spec/util_spec.lua') diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 23e3ebd8..e6776e4b 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -27,7 +27,7 @@ describe("Basic tests #blackbox #b_util", function() assert.is_false(run.luarocks_bool("invalid=5")) end) - it("LuaRocks execute from not existing directory", function() + it("LuaRocks execute from not existing directory #unix", function() local main_path = lfs.currentdir() assert.is_true(lfs.mkdir("idontexist")) assert.is_true(lfs.chdir("idontexist")) @@ -66,34 +66,53 @@ describe("Basic tests #blackbox #b_util", function() assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua")) end) - describe("LuaRocks sysconfig fails", function() - local scdir = "" - - before_each(function() - scdir = testing_paths.testing_lrprefix .. "/etc/luarocks/" + -- Disable versioned config temporarily, because it always takes + -- precedence over config.lua (config-5.x.lua is installed by default on Windows, + -- but not on Unix, so on Unix the os.rename commands below will fail silently, but this is harmless) + describe("LuaRocks config - more complex tests", function() + local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" + local versioned_scname = scdir .. "/config-" .. env_variables.LUA_VERSION .. ".lua" + local scname = scdir .. "/config.lua" + + local configfile + if test_env.TEST_TARGET_OS == "windows" then + configfile = versioned_scname + else + configfile = scname + end + + it("LuaRocks fail system config", function() + os.rename(versioned_scname, versioned_scname .. "bak") + local ok = run.luarocks_bool("config --system-config") + os.rename(versioned_scname .. ".bak", versioned_scname) + assert.is_false(ok) + end) + + it("LuaRocks system config", function() lfs.mkdir(testing_paths.testing_lrprefix) lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") lfs.mkdir(scdir) - end) - - after_each(function() - test_env.remove_dir(testing_paths.testing_lrprefix) - end) - it("LuaRocks sysconfig fail", function() - local sysconfig = io.open(scdir .. "/config.lua", "w+") - sysconfig:write("aoeui") + local sysconfig = io.open(configfile, "w+") + sysconfig:write(" ") sysconfig:close() - assert.is_false(run.luarocks_bool("list")) + local output = run.luarocks("config --system-config") + os.remove(configfile) + assert.are.same(output, configfile) end) - it("LuaRocks sysconfig fail", function() - local sysconfig = io.open(scdir .. "/config-" .. env_variables.LUA_VERSION .. ".lua", "w+") - sysconfig:write("aoeui") - sysconfig:close() + it("LuaRocks fail system config invalid", function() + lfs.mkdir(testing_paths.testing_lrprefix) + lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") + lfs.mkdir(scdir) - assert.is_false(run.luarocks_bool("list")) + local sysconfig = io.open(configfile, "w+") + sysconfig:write("if if if") + sysconfig:close() + local ok = run.luarocks_bool("config --system-config") + os.remove(configfile) + assert.is_false(ok) end) end) end) -- cgit v1.2.3-55-g6feb From adcba81974979be3763c8d9d46eb2de9a88ff67c Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Thu, 6 Oct 2016 16:24:55 +0300 Subject: Add tests for util.sortedpairs --- spec/util_spec.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'spec/util_spec.lua') diff --git a/spec/util_spec.lua b/spec/util_spec.lua index e6776e4b..2779b1ce 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -116,3 +116,59 @@ describe("Basic tests #blackbox #b_util", function() end) end) end) + +test_env.unload_luarocks() +local util = require("luarocks.util") + +describe("Luarocks util test #whitebox #w_util", function() + describe("util.sortedpairs", function() + local function collect(iter, state, var) + local collected = {} + + while true do + local returns = {iter(state, var)} + + if returns[1] == nil then + return collected + else + table.insert(collected, returns) + var = returns[1] + end + end + end + + it("default sort", function() + assert.are.same({}, collect(util.sortedpairs({}))) + assert.are.same({ + {1, "v1"}, + {2, "v2"}, + {3, "v3"}, + {"bar", "v5"}, + {"foo", "v4"} + }, collect(util.sortedpairs({"v1", "v2", "v3", foo = "v4", bar = "v5"}))) + end) + + it("sort by function", function() + local function compare(a, b) return a > b end + assert.are.same({}, collect(util.sortedpairs({}, compare))) + assert.are.same({ + {3, "v3"}, + {2, "v2"}, + {1, "v1"} + }, collect(util.sortedpairs({"v1", "v2", "v3"}, compare))) + end) + + it("sort by priority table", function() + assert.are.same({}, collect(util.sortedpairs({}, {"k1", "k2"}))) + assert.are.same({ + {"k3", "v3"}, + {"k2", "v2", {"sub order"}}, + {"k1", "v1"}, + {"k4", "v4"}, + {"k5", "v5"}, + }, collect(util.sortedpairs({ + k1 = "v1", k2 = "v2", k3 = "v3", k4 = "v4", k5 = "v5" + }, {"k3", {"k2", {"sub order"}}, "k1"}))) + end) + end) +end) -- cgit v1.2.3-55-g6feb