diff options
Diffstat (limited to 'spec/config_spec.lua')
| -rw-r--r-- | spec/config_spec.lua | 70 |
1 files changed, 51 insertions, 19 deletions
diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 0dee8620..439d0493 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua | |||
| @@ -2,6 +2,7 @@ local test_env = require("test/test_environment") | |||
| 2 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
| 3 | local run = test_env.run | 3 | local run = test_env.run |
| 4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
| 5 | local env_variables = test_env.env_variables | ||
| 5 | local site_config | 6 | local site_config |
| 6 | 7 | ||
| 7 | test_env.unload_luarocks() | 8 | test_env.unload_luarocks() |
| @@ -21,12 +22,20 @@ describe("LuaRocks config tests #blackbox #b_config", function() | |||
| 21 | 22 | ||
| 22 | it("LuaRocks config include dir", function() | 23 | it("LuaRocks config include dir", function() |
| 23 | local output = run.luarocks("config --lua-incdir") | 24 | local output = run.luarocks("config --lua-incdir") |
| 24 | assert.are.same(output, site_config.LUA_INCDIR) | 25 | if test_env.TEST_TARGET_OS == "windows" then |
| 26 | assert.are.same(output, site_config.LUA_INCDIR:gsub("\\","/")) | ||
| 27 | else | ||
| 28 | assert.are.same(output, site_config.LUA_INCDIR) | ||
| 29 | end | ||
| 25 | end) | 30 | end) |
| 26 | 31 | ||
| 27 | it("LuaRocks config library dir", function() | 32 | it("LuaRocks config library dir", function() |
| 28 | local output = run.luarocks("config --lua-libdir") | 33 | local output = run.luarocks("config --lua-libdir") |
| 29 | assert.are.same(output, site_config.LUA_LIBDIR) | 34 | if test_env.TEST_TARGET_OS == "windows" then |
| 35 | assert.are.same(output, site_config.LUA_LIBDIR:gsub("\\","/")) | ||
| 36 | else | ||
| 37 | assert.are.same(output, site_config.LUA_LIBDIR) | ||
| 38 | end | ||
| 30 | end) | 39 | end) |
| 31 | 40 | ||
| 32 | it("LuaRocks config lua version", function() | 41 | it("LuaRocks config lua version", function() |
| @@ -53,38 +62,61 @@ describe("LuaRocks config tests #blackbox #b_config", function() | |||
| 53 | end) | 62 | end) |
| 54 | 63 | ||
| 55 | describe("LuaRocks config - more complex tests", function() | 64 | describe("LuaRocks config - more complex tests", function() |
| 65 | local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" | ||
| 66 | local versioned_scname = scdir .. "/config-" .. env_variables.LUA_VERSION .. ".lua" | ||
| 67 | local scname = scdir .. "/config.lua" | ||
| 68 | |||
| 69 | local configfile | ||
| 70 | if test_env.TEST_TARGET_OS == "windows" then | ||
| 71 | configfile = versioned_scname | ||
| 72 | else | ||
| 73 | configfile = scname | ||
| 74 | end | ||
| 75 | |||
| 56 | it("LuaRocks fail system config", function() | 76 | it("LuaRocks fail system config", function() |
| 57 | os.remove(testing_paths.testing_lrprefix .. "/etc/luarocks/config.lua") | 77 | os.rename(versioned_scname, versioned_scname .. ".bak") |
| 58 | assert.is_false(run.luarocks_bool("config --system-config;")) | 78 | assert.is_false(run.luarocks_bool("config --system-config")) |
| 79 | os.rename(versioned_scname .. ".bak", versioned_scname) | ||
| 59 | end) | 80 | end) |
| 60 | 81 | ||
| 61 | it("LuaRocks system config", function() | 82 | it("LuaRocks system config", function() |
| 62 | local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" | ||
| 63 | lfs.mkdir(testing_paths.testing_lrprefix) | 83 | lfs.mkdir(testing_paths.testing_lrprefix) |
| 64 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | 84 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") |
| 65 | lfs.mkdir(scdir) | 85 | lfs.mkdir(scdir) |
| 66 | 86 | ||
| 67 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | 87 | if test_env.TEST_TARGET_OS == "windows" then |
| 68 | sysconfig:write(" ") | 88 | local output = run.luarocks("config --system-config") |
| 69 | sysconfig:close() | 89 | assert.are.same(output, versioned_scname) |
| 70 | 90 | else | |
| 71 | local output = run.luarocks("config --system-config;") | 91 | sysconfig = io.open(scname, "w+") |
| 72 | assert.are.same(output, scdir .. "/config.lua") | 92 | sysconfig:write(" ") |
| 73 | test_env.remove_dir(testing_paths.testing_lrprefix) | 93 | sysconfig:close() |
| 94 | |||
| 95 | local output = run.luarocks("config --system-config") | ||
| 96 | assert.are.same(output, scname) | ||
| 97 | os.remove(scname) | ||
| 98 | end | ||
| 74 | end) | 99 | end) |
| 75 | 100 | ||
| 76 | it("LuaRocks fail system config invalid", function() | 101 | it("LuaRocks fail system config invalid", function() |
| 77 | local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" | ||
| 78 | lfs.mkdir(testing_paths.testing_lrprefix) | 102 | lfs.mkdir(testing_paths.testing_lrprefix) |
| 79 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | 103 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") |
| 80 | lfs.mkdir(scdir) | 104 | lfs.mkdir(scdir) |
| 81 | 105 | ||
| 82 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | 106 | if test_env.TEST_TARGET_OS == "windows" then |
| 83 | sysconfig:write("if if if") | 107 | test_env.copy(versioned_scname, "versioned_scname_temp") |
| 84 | sysconfig:close() | 108 | sysconfig = io.open(versioned_scname, "w+") |
| 85 | 109 | sysconfig:write("if if if") | |
| 86 | assert.is_false(run.luarocks_bool("config --system-config;")) | 110 | sysconfig:close() |
| 87 | test_env.remove_dir(testing_paths.testing_lrprefix) | 111 | assert.is_false(run.luarocks_bool("config --system-config")) |
| 112 | test_env.copy("versioned_scname_temp", versioned_scname) | ||
| 113 | else | ||
| 114 | sysconfig = io.open(scname, "w+") | ||
| 115 | sysconfig:write("if if if") | ||
| 116 | sysconfig:close() | ||
| 117 | assert.is_false(run.luarocks_bool("config --system-config")) | ||
| 118 | os.remove(scname) | ||
| 119 | end | ||
| 88 | end) | 120 | end) |
| 89 | end) | 121 | end) |
| 90 | end) | 122 | end) |
