joyent/node — pull request #5761 by benjamn (2013-06-28 19:06:08+00:00)
Title: assert: display failing assert expression in assertion messages

This is a less hairy alternative to a previous proposal to display C-style assertion messages: https://github.com/joyent/node/pull/2444

Whereas C's `#define assert` displays the original source of the condition argument, I am proposing to display the resulting/computed values of all the arguments, including any provided message arguments.

Consider the following failing assertion:
```js
function getObject() {
return { mark: 333 * 2 }
}

require("assert").notDeepEqual(getObject(), { mark: 666 }, getObject.name +
" returned the forbidden value");
```
With my proposed changes, the first line of the resulting error message would be:
```
AssertionError: assert.notDeepEqual({"mark":666}, {"mark":666}, "getObject returned the forbidden value")
```
This output is more helpful than what is currently displayed:
```
AssertionError: getObject returned the forbidden value
```
because it mentions the `notDeepEqual` method and displays a the final values that were expected to be unequal, along with any other arguments that were passed. In other words, you can now pass as many or as few trailing message arguments as you like.

The new behavior is also slightly less confusing when no message is provided:
```js
assert.notEqual("hello", "hel" + "lo");
```
Compare the new output:
```
AssertionError: assert.notEqual("hello", "hello")
```
to the old:
```
AssertionError: "hello" != "hello"
```
This treatment of error messages paves the way for more sophisticated assertions, such as
```js
assert.every(isEven, [a(), b(), c()], "some values were odd")
```
The `require("assert")._checkResult` function is exported so that external code can easily augment the assertion module:
```js
var assert = require("assert");

assert.every = function every(predicate, list) {
return assert._checkResult(list.every(predicate), arguments);
};
```