more assertions in common, ensure tests run with assertions

This commit is contained in:
Dave Eddy 2015-09-02 23:30:07 -04:00
parent b6e4c06742
commit da8e13b45e
2 changed files with 16 additions and 4 deletions

View File

@ -26,11 +26,11 @@ all:
.PHONY: test .PHONY: test
test: test:
./node_modules/.bin/tape test/unit/*.test.js NODE_NDEBUG= ./node_modules/.bin/tape test/unit/*.test.js
.PHONY: test-integration .PHONY: test-integration
test-integration: test-integration:
./node_modules/.bin/tape test/integration/*.test.js NODE_NDEBUG= ./node_modules/.bin/tape test/integration/*.test.js
.PHONY: git-hooks .PHONY: git-hooks
git-hooks: git-hooks:

View File

@ -47,6 +47,9 @@ var TABULA_OPTIONS = [
// ---- support stuff // ---- support stuff
function objCopy(obj, target) { function objCopy(obj, target) {
assert.object(obj, 'obj');
assert.optionalObject(obj, 'target');
if (target === undefined) { if (target === undefined) {
target = {}; target = {};
} }
@ -64,6 +67,9 @@ function deepObjCopy(obj) {
function zeroPad(n, width) { function zeroPad(n, width) {
var s = String(n); var s = String(n);
assert.number(width, 'width');
assert.string(s, 'string');
while (s.length < width) { while (s.length < width) {
s = '0' + s; s = '0' + s;
} }
@ -117,8 +123,8 @@ function jsonStream(arr, stream) {
* @param {Array} valid (optional) - an array to validate pairs * @param {Array} valid (optional) - an array to validate pairs
*/ */
function kvToObj(kvs, valid) { function kvToObj(kvs, valid) {
assert.arrayOfString(kvs); assert.arrayOfString(kvs, 'kvs');
assert.optionalArrayOfString(valid); assert.optionalArrayOfString(valid, 'valid');
var o = {}; var o = {};
for (var i = 0; i < kvs.length; i++) { for (var i = 0; i < kvs.length; i++) {
@ -148,6 +154,8 @@ function kvToObj(kvs, valid) {
*/ */
function longAgo(when, now) { function longAgo(when, now) {
now = now || new Date(); now = now || new Date();
assert.date(now, 'now');
var seconds = Math.round((now - when) / 1000); var seconds = Math.round((now - when) / 1000);
var times = [ var times = [
seconds / 60 / 60 / 24 / 365, // years seconds / 60 / 60 / 24 / 365, // years
@ -172,6 +180,7 @@ function longAgo(when, now) {
* is a UUID or not * is a UUID or not
*/ */
function isUUID(s) { function isUUID(s) {
assert.string(s, 's');
return /^([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}?)$/i.test(s); return /^([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}?)$/i.test(s);
} }
@ -276,6 +285,7 @@ function humanSizeFromBytes(opts, bytes) {
} }
function capitalize(s) { function capitalize(s) {
assert.string(s, 's');
return s[0].toUpperCase() + s.substr(1); return s[0].toUpperCase() + s.substr(1);
} }
@ -290,6 +300,8 @@ function capitalize(s) {
* - support docker ID *longer* than a UUID? The curr implementation does. * - support docker ID *longer* than a UUID? The curr implementation does.
*/ */
function normShortId(s) { function normShortId(s) {
assert.string(s, 's');
var shortIdCharsRe = /^[a-f0-9]+$/; var shortIdCharsRe = /^[a-f0-9]+$/;
var shortId; var shortId;
if (s.indexOf('-') === -1) { if (s.indexOf('-') === -1) {