|
1 | 1 | 'use strict';
|
2 | 2 | require('../common');
|
3 |
| -var assert = require('assert'); |
4 |
| -var util = require('util'); |
| 3 | +const assert = require('assert'); |
| 4 | +const util = require('util'); |
5 | 5 | const vm = require('vm');
|
6 | 6 |
|
7 | 7 | assert.equal(util.inspect(1), '1');
|
@@ -288,19 +288,33 @@ assert.equal(util.inspect(setter, true), '{ [b]: [Setter] }');
|
288 | 288 | assert.equal(util.inspect(getterAndSetter, true), '{ [c]: [Getter/Setter] }');
|
289 | 289 |
|
290 | 290 | // exceptions should print the error message, not '{}'
|
291 |
| -assert.equal(util.inspect(new Error()), '[Error]'); |
292 |
| -assert.equal(util.inspect(new Error('FAIL')), '[Error: FAIL]'); |
293 |
| -assert.equal(util.inspect(new TypeError('FAIL')), '[TypeError: FAIL]'); |
294 |
| -assert.equal(util.inspect(new SyntaxError('FAIL')), '[SyntaxError: FAIL]'); |
| 291 | +const errors = []; |
| 292 | +errors.push(new Error()); |
| 293 | +errors.push(new Error('FAIL')); |
| 294 | +errors.push(new TypeError('FAIL')); |
| 295 | +errors.push(new SyntaxError('FAIL')); |
| 296 | +errors.forEach(function(err) { |
| 297 | + assert.equal(util.inspect(err), err.stack); |
| 298 | +}); |
295 | 299 | try {
|
296 | 300 | undef();
|
297 | 301 | } catch (e) {
|
298 |
| - assert.equal(util.inspect(e), '[ReferenceError: undef is not defined]'); |
| 302 | + assert.equal(util.inspect(e), e.stack); |
299 | 303 | }
|
300 | 304 | var ex = util.inspect(new Error('FAIL'), true);
|
301 |
| -assert.ok(ex.indexOf('[Error: FAIL]') != -1); |
| 305 | +assert.ok(ex.indexOf('Error: FAIL') != -1); |
302 | 306 | assert.ok(ex.indexOf('[stack]') != -1);
|
303 | 307 | assert.ok(ex.indexOf('[message]') != -1);
|
| 308 | +// Doesn't capture stack trace |
| 309 | +function BadCustomError(msg) { |
| 310 | + Error.call(this); |
| 311 | + Object.defineProperty(this, 'message', |
| 312 | + { value: msg, enumerable: false }); |
| 313 | + Object.defineProperty(this, 'name', |
| 314 | + { value: 'BadCustomError', enumerable: false }); |
| 315 | +} |
| 316 | +util.inherits(BadCustomError, Error); |
| 317 | +assert.equal(util.inspect(new BadCustomError('foo')), '[BadCustomError: foo]'); |
304 | 318 |
|
305 | 319 | // GH-1941
|
306 | 320 | // should not throw:
|
|
0 commit comments