Anton Shestakov <av6@dwimlabs.net>, Sat, 10 Sep 2016 07:56:45 +0800
examples: version.lua
spec/hglib_spec.lua
Permissions: -rw-r--r--
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')) it('can decode 255', function() assert.are_equal(255, hglib.decode_i4('\0\0\0\255')) it('can decode 256', function() assert.are_equal(256, hglib.decode_i4('\0\0\1\0')) it('can decode -1', function() assert.are_equal(-1, hglib.decode_i4('\255\255\255\255')) describe('hglib client', function() it('can connect using just file handles', function() local rh = io.open('spec/data/hello', 'rb') local client = hglib.Client.connect(rh, nil) 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) 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)) it('can use getencoding', function() local client = hglib.Client.open() local encoding, err = client:getencoding() assert.are_equal('string', type(encoding)) it('can use runcommand to request version', function() local client = hglib.Client.open() local code, o, e, d = client:runcommand('version', '--verbose') assert.are_equal(0, code) assert.is_not_nil(o:find('Mercurial Distributed SCM')) assert.is_not_nil(o:find('Enabled extensions:')) it('can use runcommand to run nonexistent command', function() local client = hglib.Client.open() local code, o, e, d = client:runcommand('extirpate') assert.are_equal(255, code) assert.is_not_nil(o:find('use "hg help" for the full list of commands')) assert.is_not_nil(e:find('unknown command')) it('can use runcommand to inspect this repo', function() local client = hglib.Client.open('.') local code, o, e, d = client:runcommand('log', '-r0') assert.are_equal(0, code) assert.is_not_nil(o:find('hglib: absolute basics'))