Skip to content

Commit

Permalink
Print out the generators that was used to generated the failing input
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Jul 17, 2016
1 parent 7b1ef3a commit 55f0da4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions documentation/assertions/function/to-be-valid-for-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Ran 67 iterations and found 1 errors
counterexample:
Generated input: ''
with: string({ length: natural({ max: 200 }) })
TypeError('Cannot read property \'forEach\' of null')
```
Expand Down
2 changes: 2 additions & 0 deletions documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Ran 1000 iterations and found 14 errors
counterexample:
Generated input: [ 2, 10 ]
with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 }))
expected [ 10, 2 ] to be sorted
```
Expand Down Expand Up @@ -206,6 +207,7 @@ Ran 100 iterations and found 4 errors
counterexample:
Generated input: [ 0, -1, 4, 10 ]
with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 }))
expected [ -1, 0, 10, 4 ] to be sorted
```
Expand Down
24 changes: 20 additions & 4 deletions lib/unexpected-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
return {
name: 'unexpected-check',
installInto: function (expect) {
expect.addType({
name: 'chance-generator',
identify: function (value) {
return value && value.isGenerator;
},
inspect: function (value, depth, output) {
output.jsFunctionName(value.generatorName);
if (value.args.length > 0) {
output.text('(');
output.appendItems(value.args, ', ');
output.text(')');
}
}
});

var promiseLoop = function (condition, action) {
return expect.promise(function (resolve, reject) {
var loop = function () {
Expand Down Expand Up @@ -137,10 +152,11 @@

output.indentLines();
output.i().block(function (output) {
output.text('Generated input: ').appendItems(bestFailure.args, ', ');
output.nl(2).block(function (output) {
output.appendErrorMessage(bestFailure.error);
});
output.text('Generated input: ').appendItems(bestFailure.args, ', ').nl()
.text('with: ').appendItems(options.generators, ', ').nl(2)
.block(function (output) {
output.appendErrorMessage(bestFailure.error);
});
});
});
}
Expand Down
7 changes: 7 additions & 0 deletions test/unexpected-check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('unexpected-check', function () {
'counterexample:\n' +
'\n' +
' Generated input: [ -1, -2 ]\n' +
' with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 }))\n' +
'\n' +
' expected [ -1, -2 ] to be sorted');
});
Expand All @@ -58,6 +59,7 @@ describe('unexpected-check', function () {
'counterexample:\n' +
'\n' +
' Generated input: [ 2 ]\n' +
' with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 }))\n' +
'\n' +
' expected [ 2 ] not to contain 2\n' +
'\n' +
Expand Down Expand Up @@ -85,6 +87,7 @@ describe('unexpected-check', function () {
'counterexample:\n' +
'\n' +
' Generated input: [ 0 ], 0\n' +
' with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 })), integer({ min: -20, max: 20 })\n' +
'\n' +
' expected [ 0 ] not to contain 0\n' +
'\n' +
Expand All @@ -105,6 +108,7 @@ describe('unexpected-check', function () {
'counterexample:\n' +
'\n' +
' Generated input: [ 0 ]\n' +
' with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 }))\n' +
'\n' +
' expected [ 0 ]\n' +
' to have items satisfying function (item, i) { expect(item, \'not to be\', i); }\n' +
Expand All @@ -128,6 +132,7 @@ describe('unexpected-check', function () {
'counterexample:\n' +
'\n' +
' Generated input: [ \')\' ]\n' +
' with: n(string, integer({ min: 1, max: 20 }))\n' +
'\n' +
' expected [ \')\' ] to have items satisfying\n' +
' function (item) {\n' +
Expand All @@ -154,6 +159,7 @@ describe('unexpected-check', function () {
'counterexample:\n' +
'\n' +
' Generated input: [ 0 ], 0\n' +
' with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 })), integer({ min: -20, max: 20 })\n' +
'\n' +
' expected [ 0 ] not to contain 0\n' +
'\n' +
Expand All @@ -178,6 +184,7 @@ describe('unexpected-check', function () {
'counterexample:\n' +
'\n' +
' Generated input: [ 0 ], 0\n' +
' with: n(integer({ min: -20, max: 20 }), integer({ min: 1, max: 20 })), integer({ min: -20, max: 20 })\n' +
'\n' +
' expected [ 0 ] not to contain 0\n' +
'\n' +
Expand Down

0 comments on commit 55f0da4

Please sign in to comment.