forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loaders: add require_first function (internal)
Usage example: ```lua local loaders = require('internal.loaders') local vshard = loaders.require_first('vshard-ee', 'vshard') ``` The function is for internal use. It would be nice to have something of this kind in the public API, but I'm not going to solve it within this patch. Needed for tarantool/tarantool-ee#815 NO_DOC=no public API changes NO_CHANGELOG=see NO_DOC
- Loading branch information
1 parent
6d5f1db
commit 3abd4f9
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local t = require('luatest') | ||
local treegen = require('test.treegen') | ||
local justrun = require('test.justrun') | ||
|
||
local g = t.group() | ||
|
||
g.before_all(treegen.init) | ||
g.after_all(treegen.clean) | ||
|
||
-- A few test cases for the loaders.require_first() function. | ||
-- | ||
-- Note: The loaders module is internal. | ||
g.test_basic = function(g) | ||
local dir = treegen.prepare_directory(g, {}, {}) | ||
treegen.write_script(dir, 'a.lua', 'return {whoami = "a"}') | ||
treegen.write_script(dir, 'b.lua', 'return {whoami = "b"}') | ||
|
||
treegen.write_script(dir, 'main.lua', string.dump(function() | ||
local loaders = require('internal.loaders') | ||
local t = require('luatest') | ||
|
||
for i, case in ipairs({ | ||
-- Positive test cases. | ||
{args = {'a', 'b'}, exp = {whoami = 'a'}}, | ||
{args = {'b', 'a'}, exp = {whoami = 'b'}}, | ||
{args = {'a', 'c'}, exp = {whoami = 'a'}}, | ||
{args = {'c', 'a'}, exp = {whoami = 'a'}}, | ||
-- Negative test cases. | ||
{args = {}, err = 'loaders.require_first expects at least one ' .. | ||
'argument'}, | ||
{args = {'c'}, err = 'neither of modules "c" are found'}, | ||
{args = {'c', 'd'}, err = 'neither of modules "c", "d" are found'}, | ||
}) do | ||
if case.exp ~= nil then | ||
assert(case.err == nil) | ||
local res = loaders.require_first(unpack(case.args)) | ||
t.assert_equals(res, case.exp, ('case #%03d'):format(i)) | ||
else | ||
assert(case.err ~= nil) | ||
t.assert_error_msg_equals(case.err, loaders.require_first, | ||
unpack(case.args)) | ||
end | ||
end | ||
end)) | ||
|
||
local opts = {nojson = true, stderr = true} | ||
local res = justrun.tarantool(dir, {}, {'main.lua'}, opts) | ||
t.assert_equals(res.exit_code, 0, {res.stdout, res.stderr}) | ||
end |