51:7e254352cf05
Anton Shestakov <av6@dwimlabs.net>, Sun, 23 Sep 2018 19:06:26 +0800
pipelines: Bionic has luarocks 2.4.2

previous change 50:5dc03ec4ebbc

spec/hglib_spec.lua

Permissions: -rw-r--r--

Other formats: Feeds:
local hglib = require 'hglib'
describe('hglib helper functions', function()
describe('decode_i4', function()
it('can decode 0', function()
assert.are_equal(0, hglib.decode_i4('\0\0\0\0'))
end)
it('can decode 255', function()
assert.are_equal(255, hglib.decode_i4('\0\0\0\255'))
end)
it('can decode 256', function()
assert.are_equal(256, hglib.decode_i4('\0\0\1\0'))
end)
it('can decode -1', function()
assert.are_equal(-1, hglib.decode_i4('\255\255\255\255'))
end)
end)
end)
describe('hglib client', function()
it('can connect using just file handles', function()
local rh = assert(io.open('spec/data/hello', 'rb'))
local client = hglib.Client.connect(rh, nil)
client:close()
assert.are_equal('closed file', io.type(rh))
assert.is_true(client.capabilities.getencoding)
assert.is_true(client.capabilities.runcommand)
assert.are_equal('UTF-8', client.encoding)
assert.are_equal(3615, client.pid)
assert.are_equal(3615, client.pgid)
end)
it('can launch a new cmdserver process', function()
local client = hglib.Client.open()
assert.is_true(client.capabilities.getencoding)
assert.is_true(client.capabilities.runcommand)
assert.are_equal('string', type(client.encoding))
assert.are_equal('number', type(client.pid))
assert.are_equal('number', type(client.lpcpid))
assert.are_equal('file', io.type(client.rh))
assert.are_equal('file', io.type(client.wh))
client:close()
end)
it('can use getencoding', function()
local client = hglib.Client.open()
local encoding, err = client:getencoding()
client:close()
assert.is_nil(err)
assert.are_equal('string', type(encoding))
end)
it('can use runcommand to request version', function()
local client = hglib.Client.open()
local code, o, e, d = client:runcommand({'version', '--verbose'})
client:close()
assert.is_not_nil(o:find('Mercurial Distributed SCM'))
assert.is_not_nil(o:find('Enabled extensions:'))
assert.are_equal('', e)
assert.are_equal('', d)
assert.are_equal(0, code)
end)
it('can use runcommand to run nonexistent command', function()
local client = hglib.Client.open()
local code, o, e, d = client:runcommand({'extirpate'})
client:close()
assert.is_not_nil(o:find('hg help'))
assert.is_not_nil(o:find('for the full list of commands'))
assert.is_not_nil(e:find('unknown command'))
assert.are_equal('', d)
assert.are_equal(255, code)
end)
it('can use runcommand to inspect this repo', function()
local client = hglib.Client.open('.')
local code, o, e, d = client:runcommand({'log', '-r0'})
client:close()
assert.is_not_nil(o:find('hglib: absolute basics'))
assert.are_equal('', e)
assert.are_equal('', d)
assert.are_equal(0, code)
end)
it('can use runcommand to import a patch and run summary', function()
local client = hglib.Client.open()
do
local code, o, e, d = client:runcommand({'init', 'testrepo'})
finally(function() os.execute('rm -r testrepo') end)
assert.are_equal('', o)
assert.are_equal('', e)
assert.are_equal('', d)
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()
local code, o, e, d = client:runcommand({'-R', 'testrepo', 'import', '-'}, patch)
assert.is_not_nil(o:find('applying patch from stdin'))
assert.are_equal('', e)
assert.are_equal('', d)
assert.are_equal(0, code)
end
do
local code, o, e, d = client:runcommand({'-R', 'testrepo', 'summary'})
assert.is_nil(o:find('empty repository'))
assert.is_not_nil(o:find('parent: 0:[0-9a-f]+ tip'))
assert.are_equal('', e)
assert.are_equal('', d)
assert.are_equal(0, code)
end
client:close()
end)
it('can use runcommand_co to request version', function()
local client = hglib.Client.open()
local co, err = client:runcommand_co({'version'})
assert.is_not_nil(co)
assert.are_equal('thread', type(co))
assert.are_equal('suspended', coroutine.status(co))
assert.is_nil(err)
local channels = {}
while coroutine.status(co) ~= 'dead' do
local status, channel = coroutine.resume(co)
assert.is_true(status)
table.insert(channels, channel)
end
client:close()
assert.are_equal('o', channels[1])
assert.are_equal('r', channels[#channels])
end)
end)