• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const path = require('path');
6const util = require('util');
7
8const message = 'message';
9const testFunction1 = common.mustNotCall(message);
10
11const testFunction2 = common.mustNotCall(message);
12
13const createValidate = (line, args = []) => common.mustCall((e) => {
14  const prefix = `${message} at `;
15  assert.ok(e.message.startsWith(prefix));
16  if (process.platform === 'win32') {
17    e.message = e.message.substring(2); // remove 'C:'
18  }
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);
23  assert.strictEqual(path.basename(fileName), 'test-common-must-not-call.js');
24  const argsInfo = args.length > 0 ?
25    `\ncalled with arguments: ${args.map(util.inspect).join(', ')}` : '';
26  assert.strictEqual(rest, line + argsInfo);
27});
28
29const validate1 = createValidate('9');
30try {
31  testFunction1();
32} catch (e) {
33  validate1(e);
34}
35
36const validate2 = createValidate('11', ['hello', 42]);
37try {
38  testFunction2('hello', 42);
39} catch (e) {
40  validate2(e);
41}
42