Skip to content

Commit

Permalink
test: configure module paths for queue init
Browse files Browse the repository at this point in the history
Set up package paths so queue test instances could be run with arbitrary
work_dir.

Part of #215
  • Loading branch information
DifferentialOrange committed Dec 13, 2022
1 parent abcafcf commit 6cfd45b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clean:

.PHONY: deps
deps: clean
( cd ./queue; tarantoolctl rocks install queue 1.2.1 )
( cd ./queue/testdata; tarantoolctl rocks install queue 1.2.1 )

.PHONY: datetime-timezones
datetime-timezones:
Expand Down
25 changes: 25 additions & 0 deletions queue/testdata/config.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
-- configure path so that you can run application
-- from outside the root directory
if package.setsearchroot ~= nil then
package.setsearchroot()
else
-- Workaround for rocks loading in tarantool 1.10
-- It can be removed in tarantool > 2.2
-- By default, when you do require('mymodule'), tarantool looks into
-- the current working directory and whatever is specified in
-- package.path and package.cpath. If you run your app while in the
-- root directory of that app, everything goes fine, but if you try to
-- start your app with "tarantool myapp/init.lua", it will fail to load
-- its modules, and modules from myapp/.rocks.
local fio = require('fio')
local app_dir = fio.abspath(fio.dirname(arg[0]))
package.path = app_dir .. '/?.lua;' .. package.path
package.path = app_dir .. '/?/init.lua;' .. package.path
package.path = app_dir .. '/.rocks/share/tarantool/?.lua;' .. package.path
package.path = app_dir .. '/.rocks/share/tarantool/?/init.lua;' .. package.path
package.cpath = app_dir .. '/?.so;' .. package.cpath
package.cpath = app_dir .. '/?.dylib;' .. package.cpath
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.so;' .. package.cpath
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.dylib;' .. package.cpath
end

local queue = require('queue')
rawset(_G, 'queue', queue)

Expand Down
25 changes: 25 additions & 0 deletions queue/testdata/pool.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
-- configure path so that you can run application
-- from outside the root directory
if package.setsearchroot ~= nil then
package.setsearchroot()
else
-- Workaround for rocks loading in tarantool 1.10
-- It can be removed in tarantool > 2.2
-- By default, when you do require('mymodule'), tarantool looks into
-- the current working directory and whatever is specified in
-- package.path and package.cpath. If you run your app while in the
-- root directory of that app, everything goes fine, but if you try to
-- start your app with "tarantool myapp/init.lua", it will fail to load
-- its modules, and modules from myapp/.rocks.
local fio = require('fio')
local app_dir = fio.abspath(fio.dirname(arg[0]))
package.path = app_dir .. '/?.lua;' .. package.path
package.path = app_dir .. '/?/init.lua;' .. package.path
package.path = app_dir .. '/.rocks/share/tarantool/?.lua;' .. package.path
package.path = app_dir .. '/.rocks/share/tarantool/?/init.lua;' .. package.path
package.cpath = app_dir .. '/?.so;' .. package.cpath
package.cpath = app_dir .. '/?.dylib;' .. package.cpath
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.so;' .. package.cpath
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.dylib;' .. package.cpath
end

local queue = require('queue')
rawset(_G, 'queue', queue)

Expand Down

0 comments on commit 6cfd45b

Please sign in to comment.