skip non-cmd lines in help output

This commit is contained in:
Sean Lavine 2015-03-24 18:29:20 -07:00
parent bb8d05e556
commit cb95f56e9c

View File

@ -2,36 +2,34 @@ var assert = require('assert'),
bitcoin = require('../'),
config = require('./config'),
commands = require('../lib/commands');
var getHelpCommands = function(client, cb) {
var commandRegex = /^([a-z]+)/;
client.cmd('help', function(err, commandList) {
if (err) return cb(err);
var helpCommands = [];
// split up the command list by newlines
var commandListLines = commandList.split('\n');
var result;
for (var i in commandListLines) {
result = commandRegex.exec(commandListLines[i]);
if (!result) {
return cb(new Error('command list line failed to match regex: ' + commandListLines[i]));
}
if (!result) continue;
helpCommands.push(result[1]);
}
cb(null, helpCommands);
});
};
describe('Client Commands', function() {
it('should have all the commands listed by `help`', function(done) {
var client = new bitcoin.Client(config);
getHelpCommands(client, function(err, helpCommands) {
assert.ifError(err);
for (var i in helpCommands) {
var found = true;
for (var j in commands) {
@ -42,16 +40,16 @@ describe('Client Commands', function() {
}
assert.ok(found, 'missing command found in `help`: ' + helpCommands[i]);
}
done();
});
});
it('should not have any commands not listed by `help`', function(done) {
var client = new bitcoin.Client(config);
getHelpCommands(client, function(err, helpCommands) {
assert.ifError(err);
for (var i in commands) {
var found = false;
for (var j in helpCommands) {
@ -60,7 +58,7 @@ describe('Client Commands', function() {
break;
}
}
// ignore commands not found in help because they are hidden
// if the wallet isn't encrypted
var ignore = ['walletlock', 'walletpassphrase', 'walletpassphrasechange'];
@ -70,9 +68,9 @@ describe('Client Commands', function() {
assert.ok(found, 'command not found in `help`: ' + commands[i]);
}
}
done();
});
});
});