Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor generic utilities into shared file. Add constructor config o…

…ption to prevent auto printing stdout/err, with associated nodeunit test cases. Note: the prevention of auto printing is not fully implemented with this commit.
  • Loading branch information...
commit 0de09ae619596b9b0f3899abd4dd6848e85d6485 1 parent 144ef79
@ryan-self authored
Showing with 75 additions and 0 deletions.
  1. +45 −0 test/ExecPlanTest.js
  2. +30 −0 utils.js
View
45 test/ExecPlanTest.js
@@ -0,0 +1,45 @@
+/* --- ENVIRONMENT SETUP --- */
+
+var ExecPlan = require('exec-plan').ExecPlan;
+var utils = require('../utils');
+var isFunction = utils.isFunction;
+var isDefined = utils.isDefined;
+var isNumber = utils.isNumber;
+var isString = utils.isString;
+var isObject = utils.isObject;
+var isArray = utils.isArray;
+
+/* ------------------------- */
+
+/* --- TEST CASES --- */
+
+// verification of correct construction
+exports['Passing in no constructor config object makes autoPrintOut and autoPrintErr true'] =
+ function (test) {
+ var execPlan = new ExecPlan();
+ test.ok(execPlan.willAutoPrintOut());
+ test.ok(execPlan.willAutoPrintErr());
+ test.done();
+};
+
+exports['Constructor config {autoPrintOut:false} sets autoPrintOut and autoPrintErr accordingly'] = function (test) {
+ var execPlan = new ExecPlan({autoPrintOut: false});
+ test.equal(execPlan.willAutoPrintOut(), false, 'execPlan will not auto print stdout');
+ test.ok(execPlan.willAutoPrintErr(), 'execPlan will auto print stderr');
+ test.done();
+};
+
+exports['Constructor config {autoPrintErr:false} sets autoPrintOut and autoPrintErr accordingly'] = function (test) {
+ var execPlan = new ExecPlan({autoPrintErr: false});
+ test.ok(execPlan.willAutoPrintOut(), 'execPlan will auto print stderr');
+ test.equal(execPlan.willAutoPrintErr(), false, 'execPlan will not auto print stderr');
+ test.done();
+};
+
+exports['Constructor config {autoPrintOut:false, autoPrintErr:false} sets autoPrintOut and ' +
+ 'autoPrintErr accordingly'] = function (test) {
+ var execPlan = new ExecPlan({autoPrintOut: false, autoPrintErr: false});
+ test.equal(execPlan.willAutoPrintOut(), false, 'execPlan will not auto print stdout');
+ test.equal(execPlan.willAutoPrintErr(), false, 'execPlan will not auto print stderr');
+ test.done();
+};
View
30 utils.js
@@ -0,0 +1,30 @@
+/* --- STUBS --- */
+
+var emptyFn = exports.emptyFn = (function () {});
+
+/* --- CONVERTERS --- */
+
+var toString = exports.toString = function (value) {
+ return Object.prototype.toString.call(value);
+};
+
+/* --- TYPE CHECKERS --- */
+
+var isDefined = exports.isDefined = function (value) {
+ return typeof value !== 'undefined';
+};
+var isString = exports.isString = function (value) {
+ return typeof value === 'string';
+};
+var isNumber = exports.isNumber = function (value) {
+ return typeof value === 'number';
+};
+var isFunction = exports.isFunction = function (value) {
+ return typeof value === 'function';
+};
+var isArray = exports.isArray = function (value) {
+ return toString(value) === '[object Array]';
+};
+var isObject = exports.isObject = function (value) {
+ return toString(value) === '[object Object]';
+};
Please sign in to comment.
Something went wrong with that request. Please try again.