From da8e13b45eb7e3569628439699919739b13ebf04 Mon Sep 17 00:00:00 2001 From: Dave Eddy Date: Wed, 2 Sep 2015 23:30:07 -0400 Subject: [PATCH] more assertions in common, ensure tests run with assertions --- Makefile | 4 ++-- lib/common.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 128e91d..fb624e5 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,11 @@ all: .PHONY: test test: - ./node_modules/.bin/tape test/unit/*.test.js + NODE_NDEBUG= ./node_modules/.bin/tape test/unit/*.test.js .PHONY: 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 git-hooks: diff --git a/lib/common.js b/lib/common.js index 5a89619..42be0ef 100644 --- a/lib/common.js +++ b/lib/common.js @@ -47,6 +47,9 @@ var TABULA_OPTIONS = [ // ---- support stuff function objCopy(obj, target) { + assert.object(obj, 'obj'); + assert.optionalObject(obj, 'target'); + if (target === undefined) { target = {}; } @@ -64,6 +67,9 @@ function deepObjCopy(obj) { function zeroPad(n, width) { var s = String(n); + assert.number(width, 'width'); + assert.string(s, 'string'); + while (s.length < width) { s = '0' + s; } @@ -117,8 +123,8 @@ function jsonStream(arr, stream) { * @param {Array} valid (optional) - an array to validate pairs */ function kvToObj(kvs, valid) { - assert.arrayOfString(kvs); - assert.optionalArrayOfString(valid); + assert.arrayOfString(kvs, 'kvs'); + assert.optionalArrayOfString(valid, 'valid'); var o = {}; for (var i = 0; i < kvs.length; i++) { @@ -148,6 +154,8 @@ function kvToObj(kvs, valid) { */ function longAgo(when, now) { now = now || new Date(); + assert.date(now, 'now'); + var seconds = Math.round((now - when) / 1000); var times = [ seconds / 60 / 60 / 24 / 365, // years @@ -172,6 +180,7 @@ function longAgo(when, now) { * is a UUID or not */ function isUUID(s) { + assert.string(s, '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) { + assert.string(s, 's'); 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. */ function normShortId(s) { + assert.string(s, 's'); + var shortIdCharsRe = /^[a-f0-9]+$/; var shortId; if (s.indexOf('-') === -1) {