Skip to content

Commit

Permalink
Implement program.assert.
Browse files Browse the repository at this point in the history
Closes #136.
  • Loading branch information
flatheadmill committed Jan 18, 2016
1 parent 20a98a4 commit 6c510df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions program.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Program.prototype.required = function () {
}, this)
}

Program.prototype.assert = function (condition, message) {
if (!condition) this.abend(message)
}

Program.prototype.numeric = function () {
this.validate.apply(this, [ '%s is not numeric' ].concat(slice.call(arguments))
.concat(isNumeric))
Expand Down
10 changes: 9 additions & 1 deletion t/arguable/program.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ function prove (async, assert) {
assert(error.stderr, 'A bad thing happened.', 'error with code')
assert(error.code, 127, 'code for error with code')
})
createProgram(__filename, {}, [], io = {
stderr: new stream.PassThrough
}, cadence(function (async, program) {
program.assert(true, 'badness')
program.assert(false, 'badness')
}), function (error, code) {
assert(error.stderr, 'A bad thing happened.', 'failed assertion')
})
createProgram(__filename, {}, [], io = {
stderr: new stream.PassThrough
}, cadence(function (async, program) {
Expand Down Expand Up @@ -157,4 +165,4 @@ function prove (async, assert) {
io.events.emit('SIGINT')
}

require('proof')(28, cadence(prove))
require('proof')(29, cadence(prove))

0 comments on commit 6c510df

Please sign in to comment.