blob: b3aa76659cee04c9b94c7e67bfee3b65315572a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
-- vim:foldmethod=marker
local r = require 'repl' -- we don't call it 'repl' so we don't shadow
-- repl in the plugin environment
pcall(require, 'luarocks.loader')
require 'Test.More'
local utils = require 'test-utils'
plan(5)
local clone = r:clone()
do -- basic tests {{{
local with_plugin = clone:clone()
function with_plugin:foo()
end
local line_no
local _, err = pcall(function()
with_plugin:loadplugin(function()
line_no = utils.next_line_number()
function repl:foo()
end
end)
end)
like(err, string.format("%d: The 'foo' method already exists", line_no))
with_plugin:loadplugin(function()
function repl:bar()
return 17
end
end)
is(with_plugin:bar(), 17)
with_plugin:loadplugin(function()
repl.baz = 18
end)
is(with_plugin.baz, 18)
end -- }}}
do -- conflict tests {{{
local clone = r:clone()
local line_no
clone:loadplugin(function()
function repl:foo()
end
end)
local _, err = pcall(function()
clone:loadplugin(function()
line_no = utils.next_line_number()
function repl:foo()
end
end)
end)
like(err, tostring(line_no) .. ": The 'foo' method already exists")
end -- }}}
do -- proxy tests {{{
local clone = r:clone()
clone:loadplugin(function()
features = 'foo'
end)
clone:loadplugin(function()
ok(repl:hasfeature 'foo')
end)
end -- }}}
|