Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Updated for 0.7 release
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohansen committed Oct 1, 2012
1 parent 35fa117 commit 828dc8a
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 121 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Christian Johansen, christian@cjohansen.no
August Lilleaas, august@augustl.com
Stein Magnus Jodal, stein.magnus@jodal.no
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(The BSD License)

Copyright (c) 2010-2012, Christian Johansen, christian@cjohansen.no and
August Lilleaas, august.lilleaas@gmail.com. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Christian Johansen nor the names of his contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 changes: 21 additions & 0 deletions autolint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
paths: [
"lib/*.js",
"test/*.js"
],
linterOptions: {
node: true,
browser: true,
plusplus: true,
sloppy: true,
vars: true,
nomen: true,
forin: true,
predef: [
"define",
"assert",
"refute",
"buster"
]
}
};
18 changes: 0 additions & 18 deletions autolint.json

This file was deleted.

35 changes: 21 additions & 14 deletions lib/buster-cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
var B = require("buster-core");
var bane = require("bane");
var args = require("./buster-cli/args");
var help = require("./buster-cli/help");
var logger = require("./buster-cli/logger");
var config = require("./buster-cli/config");

function F() {}
function create(obj) {
F.prototype = obj;
return new F();
}

function BusterCli(options) {
var cliArgs = create(args);
this.args = cliArgs;
this.opt = cliArgs.opt.bind(cliArgs);
this.opd = cliArgs.opd.bind(cliArgs);
this.shorthand = cliArgs.addShorthand.bind(cliArgs);
this.environmentVariable = options && options.environmentVariable;
var cliHelp = help.create(this, options || {});
this.addHelpOption = cliHelp.addHelpOption.bind(cliHelp);
}

// Public API

module.exports = B.extend(B.create(B.eventEmitter), {
module.exports = BusterCli.prototype = bane.createEventEmitter({
validators: args.validators,

// Create a cli helper. Options:
Expand All @@ -18,17 +35,7 @@ module.exports = B.extend(B.create(B.eventEmitter), {
// }
//
create: function (options) {
var cliArgs = B.create(args);
var cli = B.extend(B.create(this), {
args: cliArgs,
opt: B.bind(cliArgs, "opt"),
opd: B.bind(cliArgs, "opd"),
shorthand: B.bind(cliArgs, "addShorthand"),
environmentVariable: options && options.environmentVariable
});
var cliHelp = help.create(cli, options || {});
cli.addHelpOption = B.bind(cliHelp, "addHelpOption");
return cli;
return new BusterCli(options);
},

environmentArgs: function () {
Expand Down Expand Up @@ -62,7 +69,7 @@ module.exports = B.extend(B.create(B.eventEmitter), {
cfg.addGroupOption();
cfg.addTestsOption();
cfg.addEnvOption();
this.loadConfig = B.bind(cfg, "loadConfig");
this.loadConfig = cfg.loadConfig.bind(cfg);
},

pref: function (prefs, arg, property) {
Expand Down
29 changes: 16 additions & 13 deletions lib/buster-cli/args.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var B = require("buster-core");
var bane = require("bane");
var args = require("posix-argv-parser");
var v = args.validators;

Expand Down Expand Up @@ -26,17 +26,20 @@ function getValidators(options) {
return validators;
}

module.exports = B.extend(B.create(args), B.create(B.eventEmitter), {
validators: args.validators,
function Args() {}
Args.prototype = args;

opt: function (flags, options) {
options.description = getDescription(options);
options.hasValue = !!options.values || !!options.hasValue;
options.validators = getValidators(options);
return this.createOption(flags, options);
},
module.exports = bane.createEventEmitter(new Args());

opd: function (signature, options) {
return this.createOperand(signature, options);
}
});
module.exports.validators= args.validators;

module.exports.opt = function (flags, options) {
options.description = getDescription(options);
options.hasValue = !!options.values || !!options.hasValue;
options.validators = getValidators(options);
return this.createOption(flags, options);
};

module.exports.opd = function (signature, options) {
return this.createOperand(signature, options);
};
36 changes: 18 additions & 18 deletions lib/buster-cli/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var B = require("buster-core");
var Path = require("path");
var fs = require("fs");
var configuration = require("buster-configuration");
var bc = require("buster-configuration");
var Minimatch = require("minimatch").Minimatch;

function prop(name) {
Expand Down Expand Up @@ -59,21 +58,22 @@ function emptyFiles(config) {
}, []);
}

module.exports = {
function Config(cli, options) {
options = options || {};
this.baseName = options.baseName;
this.cli = cli;
if (options.defaultLocations) {
cli.defaultLocations = options.defaultLocations;
}
cli.opt(["-c", "--config"], {
description: "Test configuration file",
hasValue: true
});
}

module.exports = Config.prototype = {
create: function (cli, options) {
options = options || {};
var config = B.extend(B.create(this), {
baseName: options.baseName,
cli: cli
});
if (options.defaultLocations) {
cli.defaultLocations = options.defaultLocations;
}
cli.opt(["-c", "--config"], {
description: "Test configuration file",
hasValue: true
});
return config;
return new Config(cli, options);
},

addGroupOption: function () {
Expand Down Expand Up @@ -126,7 +126,7 @@ module.exports = {
}
try {
callback(null, files.map(function (f) {
return inflate(configuration.create(), f);
return inflate(bc.createConfiguration(), f);
}));
} catch (e) {
callback(e);
Expand All @@ -142,7 +142,7 @@ module.exports = {
},

loadConfig: function (options, callback) {
configuration.create().loadFiles(
bc.createConfiguration().loadFiles(
(options["-c"].value || "").split(","),
this.baseName,
this.defaultLocations,
Expand Down
72 changes: 61 additions & 11 deletions lib/buster-cli/help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
var B = require("buster-core");
var S = require("buster-terminal");
var color = require("ansi-colorizer");

/* Helper functions originally in buster-terminal.
* Moved inline here as this was the only place using them.
*/
function repeat(character, times) {
var str = "";
while (times--) {
str += character;
}
return str;
}

function reflowLine(length, text) {
var line = "";
return text.split(" ").reduce(function (lines, word) {
if (line.length > 0 && line.length + word.length + 1 > length) {
lines.push(line);
line = "";
}
line += (!!line ? " " : "") + word;
return lines;
}, []).concat([line]).join("\n");
}

function reflow(text, length) {
return text.split("\n").map(reflowLine.bind(null, length)).join("\n");
}

function alignLeft(string, width) {
var len = color.charCount(string);
return string + repeat(" ", width - len);
}

function maxWidth(strings) {
var i, l, width, str;
for (i = 0, l = strings.length, width = 0; i < l; i++) {
str = (strings[i] == null ? "" : String(strings[i]));
width = Math.max(color.charCount(str), width);
}
return width;
}

/* End old buster-terminal helpers */

function helpTopicsFor(opt, helpTopics) {
if (!helpTopics) { return ""; }
Expand All @@ -17,26 +59,34 @@ function logHelpTopic(logger, topics, topic) {

function reflowAndIndent(text) {
var indDepth = this.sigWidth + this.spacing + this.indent;
var indentation = S.repeat(" ", indDepth);
var indentation = repeat(" ", indDepth);
var width = this.width - indentation.length;
return S.reflow(text, width).split("\n").join("\n" + indentation);
return reflow(text, width).split("\n").join("\n" + indentation);
}

function optionHelpSummary(option) {
var topics = helpTopicsFor(option, this.cli.helpTopics);
return S.repeat(" ", this.indent) +
S.alignLeft(option.signature, this.sigWidth) +
S.repeat(" ", this.spacing) +
return repeat(" ", this.indent) +
alignLeft(option.signature, this.sigWidth) +
repeat(" ", this.spacing) +
reflowAndIndent.call(this, option.description + topics);
}

module.exports = {
function Help(cli, options) {
this.cli = cli;

for (var prop in options) {
this[prop] = options[prop];
}
}

Help.prototype = module.exports = {
width: 80,
indent: 4,
spacing: 3,

create: function (cli, options) {
return B.extend(B.create(this), { cli: cli }, options);
return new Help(cli, options);
},

addHelpOption: function (missionStatement, description, topics) {
Expand Down Expand Up @@ -75,9 +125,9 @@ module.exports = {

formatHelp: function (args) {
var signatures = args.options.map(function (a) { return a.signature; });
this.sigWidth = S.maxWidth(signatures);
this.sigWidth = maxWidth(signatures);
return args.options.filter(function (opt) {
return !!opt.signature;
}).map(B.bind(this, optionHelpSummary)).join("\n");
}).map(optionHelpSummary.bind(this)).join("\n");
}
};
9 changes: 5 additions & 4 deletions lib/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var streamLogger = require("stream-logger");
var buster = require("buster");
var referee = require("referee");
var rmrf = require("rimraf");
var path = require("path");
var fs = require("fs");
Expand All @@ -16,12 +16,13 @@ module.exports = {
toString: function () { return this.content; }
};

buster.assertions.add(name, {
referee.add(name, {
assert: function (expected) {
return buster.assertions.match(stream.toString(), expected);
return referee.match(stream.toString(), expected);
},
assertMessage: "${2}Expected " + name + "\n${0}\nto match\n${1}",
refuteMessage: "${2}Expected " + name + "\n${0}\nnot to match\n${1}",
refuteMessage: "${2}Expected " + name +
"\n${0}\nnot to match\n${1}",
values: function (expected, message) {
return [stream.toString(), expected, message || ""];
}
Expand Down
Loading

0 comments on commit 828dc8a

Please sign in to comment.