diff options
| author | robooo <robo.karasek@gmail.com> | 2016-07-07 21:58:19 +0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2016-07-07 16:58:19 -0300 |
| commit | 5af7e0d7c2dcf65e41ae8523f3771e9528be32a7 (patch) | |
| tree | bcd14624e0566a23da2e708675197d212cecf35d /spec/config_spec.lua | |
| parent | b5b285a678fe78b80d452cc9eb7565b8bf087b81 (diff) | |
| download | luarocks-5af7e0d7c2dcf65e41ae8523f3771e9528be32a7.tar.gz luarocks-5af7e0d7c2dcf65e41ae8523f3771e9528be32a7.tar.bz2 luarocks-5af7e0d7c2dcf65e41ae8523f3771e9528be32a7.zip | |
New test-suite for LuaRocks (#581)
First version of new test-suite, using Busted framework based on Google Summer of Code project:
https://summerofcode.withgoogle.com/projects/#5695811874717696
* Rewritten from Bash to Lua
* Tests now check if they did what they were supposed to, beyond only checking success or failure of the `luarocks` command
* Support for black-box (launching `luarocks` as an external command) and white-box (testing functions in modules directly) testing
Diffstat (limited to 'spec/config_spec.lua')
| -rw-r--r-- | spec/config_spec.lua | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/config_spec.lua b/spec/config_spec.lua new file mode 100644 index 00000000..f6cabd8c --- /dev/null +++ b/spec/config_spec.lua | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | local cfg = require("luarocks.cfg") | ||
| 6 | |||
| 7 | expose("LuaRocks config tests #blackbox #b_config", function() | ||
| 8 | |||
| 9 | before_each(function() | ||
| 10 | test_env.setup_specs(extra_rocks) | ||
| 11 | test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs | ||
| 12 | site_config = require("luarocks.site_config") | ||
| 13 | testing_paths = test_env.testing_paths | ||
| 14 | run = test_env.run | ||
| 15 | end) | ||
| 16 | |||
| 17 | describe("LuaRocks config - basic tests", function() | ||
| 18 | it("LuaRocks config with no flags/arguments", function() | ||
| 19 | assert.is_false(run.luarocks_bool("config")) | ||
| 20 | end) | ||
| 21 | |||
| 22 | it("LuaRocks config include dir", function() | ||
| 23 | local output = run.luarocks("config --lua-incdir") | ||
| 24 | assert.are.same(output, site_config.LUA_INCDIR) | ||
| 25 | end) | ||
| 26 | |||
| 27 | it("LuaRocks config library dir", function() | ||
| 28 | local output = run.luarocks("config --lua-libdir") | ||
| 29 | assert.are.same(output, site_config.LUA_LIBDIR) | ||
| 30 | end) | ||
| 31 | |||
| 32 | it("LuaRocks config lua version", function() | ||
| 33 | local output = run.luarocks("config --lua-ver") | ||
| 34 | local lua_version = _VERSION:gsub("Lua ", "") | ||
| 35 | if test_env.LUAJIT_V then | ||
| 36 | lua_version = "5.1" | ||
| 37 | end | ||
| 38 | assert.are.same(output, lua_version) | ||
| 39 | end) | ||
| 40 | |||
| 41 | it("LuaRocks config rock trees", function() | ||
| 42 | assert.is_true(run.luarocks_bool("config --rock-trees")) | ||
| 43 | end) | ||
| 44 | |||
| 45 | it("LuaRocks config user config", function() | ||
| 46 | local user_config_path = run.luarocks("config --user-config") | ||
| 47 | assert.is.truthy(lfs.attributes(user_config_path)) | ||
| 48 | end) | ||
| 49 | |||
| 50 | it("LuaRocks config missing user config", function() | ||
| 51 | assert.is_false(run.luarocks_bool("config --user-config", {LUAROCKS_CONFIG = "missing_file.lua"})) | ||
| 52 | end) | ||
| 53 | end) | ||
| 54 | |||
| 55 | describe("LuaRocks config - more complex tests", function() | ||
| 56 | it("LuaRocks fail system config", function() | ||
| 57 | os.remove(testing_paths.testing_lrprefix .. "/etc/luarocks/config.lua") | ||
| 58 | assert.is_false(run.luarocks_bool("config --system-config;")) | ||
| 59 | end) | ||
| 60 | |||
| 61 | it("LuaRocks system config", function() | ||
| 62 | local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" | ||
| 63 | lfs.mkdir(testing_paths.testing_lrprefix) | ||
| 64 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | ||
| 65 | lfs.mkdir(scdir) | ||
| 66 | |||
| 67 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | ||
| 68 | sysconfig:write(" ") | ||
| 69 | sysconfig:close() | ||
| 70 | |||
| 71 | local output = run.luarocks("config --system-config;") | ||
| 72 | assert.are.same(output, scdir .. "/config.lua") | ||
| 73 | test_env.remove_dir(testing_paths.testing_lrprefix) | ||
| 74 | end) | ||
| 75 | |||
| 76 | it("LuaRocks fail system config invalid", function() | ||
| 77 | local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" | ||
| 78 | lfs.mkdir(testing_paths.testing_lrprefix) | ||
| 79 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | ||
| 80 | lfs.mkdir(scdir) | ||
| 81 | |||
| 82 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | ||
| 83 | sysconfig:write("if if if") | ||
| 84 | sysconfig:close() | ||
| 85 | |||
| 86 | assert.is_false(run.luarocks_bool("config --system-config;")) | ||
| 87 | test_env.remove_dir(testing_paths.testing_lrprefix) | ||
| 88 | end) | ||
| 89 | end) | ||
| 90 | end) \ No newline at end of file | ||
