| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 437f387 commit 7744f66
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -418,9 +418,12 @@ function getCallSite(top) { | |||
| 418 | 418 | ||
| 419 | 419 | function mustNotCall(msg) { | |
| 420 | 420 | const callSite = getCallSite(mustNotCall); | |
| 421 | - return function mustNotCall() { | ||
| 421 | + return function mustNotCall(...args) { | ||
| 422 | + const argsInfo = args.length > 0 ? | ||
| 423 | + `\ncalled with arguments: ${args.map(util.inspect).join(', ')}` : ''; | ||
| 422 | 424 | assert.fail( | |
| 423 | - `${msg || 'function should not have been called'} at ${callSite}`); | ||
| 425 | + `${msg || 'function should not have been called'} at ${callSite}` + | ||
| 426 | + argsInfo); | ||
| 424 | 427 | }; | |
| 425 | 428 | } | |
| 426 | 429 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,24 +3,39 @@ | |||
| 3 | 3 | const common = require('../common'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const path = require('path'); | |
| 6 | + const util = require('util'); | ||
| 6 | 7 | ||
| 7 | 8 | const message = 'message'; | |
| 8 | - const testFunction = common.mustNotCall(message); | ||
| 9 | + const testFunction1 = common.mustNotCall(message); | ||
| 9 | 10 | ||
| 10 | - const validateError = common.mustCall((e) => { | ||
| 11 | + const testFunction2 = common.mustNotCall(message); | ||
| 12 | + | ||
| 13 | + const createValidate = (line, args = []) => common.mustCall((e) => { | ||
| 11 | 14 | const prefix = `${message} at `; | |
| 12 | 15 | assert.ok(e.message.startsWith(prefix)); | |
| 13 | 16 | if (process.platform === 'win32') { | |
| 14 | 17 | e.message = e.message.substring(2); // remove 'C:' | |
| 15 | 18 | } | |
| 16 | - const [ fileName, lineNumber ] = e.message | ||
| 17 | - .substring(prefix.length).split(':'); | ||
| 19 | + const msg = e.message.substring(prefix.length); | ||
| 20 | + const firstColon = msg.indexOf(':'); | ||
| 21 | + const fileName = msg.substring(0, firstColon); | ||
| 22 | + const rest = msg.substring(firstColon + 1); | ||
| 18 | 23 | assert.strictEqual(path.basename(fileName), 'test-common-must-not-call.js'); | |
| 19 | - assert.strictEqual(lineNumber, '8'); | ||
| 24 | + const argsInfo = args.length > 0 ? | ||
| 25 | + `\ncalled with arguments: ${args.map(util.inspect).join(', ')}` : ''; | ||
| 26 | + assert.strictEqual(rest, line + argsInfo); | ||
| 20 | 27 | }); | |
| 21 | 28 | ||
| 29 | + const validate1 = createValidate('9'); | ||
| 30 | + try { | ||
| 31 | + testFunction1(); | ||
| 32 | + } catch (e) { | ||
| 33 | + validate1(e); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + const validate2 = createValidate('11', ['hello', 42]); | ||
| 22 | 37 | try { | |
| 23 | - testFunction(); | ||
| 38 | + testFunction2('hello', 42); | ||
| 24 | 39 | } catch (e) { | |
| 25 | - validateError(e); | ||
| 40 | + validate2(e); | ||
| 26 | 41 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments