Lua 单元测试moonscript可怕的配置
为了学习lua/moonscript,我正在尝试将我的很棒的配置文件(rc.lua)迁移到和一些事情。为此,我将rc.lua设置为需要这样的moonscript配置文件Lua 单元测试moonscript可怕的配置,lua,awesome-wm,moonscript,Lua,Awesome Wm,Moonscript,为了学习lua/moonscript,我正在尝试将我的很棒的配置文件(rc.lua)迁移到和一些事情。为此,我将rc.lua设置为需要这样的moonscript配置文件 package.path = pathsToAdd .. package.path -- a bit of a hassle to amend the lua require paths -- correctly; I boldly assume for now that these are not the -- cause o
package.path = pathsToAdd .. package.path
-- a bit of a hassle to amend the lua require paths
-- correctly; I boldly assume for now that these are not the
-- cause of the problem
require('moonscript')
require('config')
对于第一个单元测试,检查我的配置是否调用了模块“gears”的特定函数,这一切都进行得相当顺利。最后,我模拟了gears模块,每次调用
require('gears')
通过这样设置单元测试
package.loaded.gears = myMockVersion
快进到测试中的配置文件需要“可怕”模块时:
它的init.lua被调用,并立即执行
return
{
client = require("awful.client");
...
}
这导致client.lua正在做什么
...
local tag = require("awful.tag")
...
local client = {}
-- define lots of functions, register some signal handlers
return client
现在,对于仍在阅读的每个人来说,tag.lua中的问题是:
...
local capi =
{
...
client = client,
...
}
...
capi.client.connect_signal(...)
最后一个电话给了我一个好机会
attempt to index a nil value (field 'client')
我认为这是因为client.lua尚未运行过最初的几个require调用,因此根本无法在全球范围内使用,或者至少尚未定义其功能。最后,这让我想到了一个问题: 首先,为什么在你每天的创业过程中都会出现这种情况(糟糕几乎是核心模块),在尝试复制它所处的环境时,我会错过什么呢 非常感谢您的光临。
你真正的awesome的C核心导出一些对象供lua使用。糟糕的(还有很多其他人)直接使用这些。这些都在awesome 3.5中(请参阅):
- 标签
- 计时器
- 缩进
- 键盘抓取器
- 可牵引
- 根
- 老鼠
- 客户
- 屏风
- 棒极了
- 捕鼠人
- 挑选
- 钥匙
- dbus
- 钮扣
编辑:顺便说一下,这就是为什么在正常的lua promt中不能
要求(“糟糕”)
。相同的内置对象丢失了。太好了,直截了当地回答了……与此同时,在阅读了一些令人惊叹的资料后,我自己找到了答案的大致部分。我的进一步方法很可能是模拟所有内容。为此,存储在“\u G”中的全局上下文可以使用类似“rawset\u G”、“moduletobemock”、“mockVersion”的内容进行修改