Download:
child 41:de1feec4a126
parent 39:bb3fd0111e75
40:ad0bca5aeecc
Anton Shestakov <av6@dwimlabs.net>, Mon, 24 Oct 2016 14:05:51 +0800
hglib: handle cases when user didn't provide any input

3 файлов изменено, 10 вставок(+), 3 удалений(-) [+]
README.md file | annotate | diff | comparison | revisions
hglib.lua file | annotate | diff | comparison | revisions
spec/hglib_spec.lua file | annotate | diff | comparison | revisions
--- a/README.md Mon Oct 24 00:41:04 2016 +0800
+++ b/README.md Mon Oct 24 14:05:51 2016 +0800
@@ -43,5 +43,4 @@
- Better docs
- Maybe use something better than lpc
-- Handle cases when command needs input, but user provided nil
- ??????
--- a/hglib.lua Mon Oct 24 00:41:04 2016 +0800
+++ b/hglib.lua Mon Oct 24 14:05:51 2016 +0800
@@ -157,6 +157,7 @@
local o = ''
local e = ''
local d = ''
+ input = input or ''
local function write_input(length)
write_block(self.wh, input:sub(1, length))
self.wh:flush()
@@ -175,9 +176,9 @@
e = e .. message
elseif channel == 'd' then
d = d .. message
- elseif channel == 'I' and input ~= nil then
+ elseif channel == 'I' then
write_input(message)
- elseif channel == 'L' and input ~= nil then
+ elseif channel == 'L' then
write_input(math.min(input:find('\n') or message, message))
elseif channel:lower() ~= channel then
e = e .. '\nhglib: unexpected data on required channel "' .. channel .. '"'
--- a/spec/hglib_spec.lua Mon Oct 24 00:41:04 2016 +0800
+++ b/spec/hglib_spec.lua Mon Oct 24 14:05:51 2016 +0800
@@ -92,6 +92,13 @@
assert.are_equal(0, code)
end
do
+ local code, o, e, d = client:runcommand({'-R', 'testrepo', 'import', '-'})
+ assert.is_not_nil(o:find('applying patch from stdin'))
+ assert.is_not_nil(e:find('abort: stdin: no diffs found'))
+ assert.are_equal('', d)
+ assert.are_equal(255, code)
+ end
+ do
local pf = assert(io.open('spec/data/foo.patch', 'rb'))
local patch = pf:read('*all')
pf:close()