summaryrefslogtreecommitdiff
path: root/test/parallel/test-common-must-not-call.js
blob: d70daabf0a4bd0efba9f03b4a3c5347708e03340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';

const common = require('../common');
const assert = require('assert');
const path = require('path');

const message = 'message';
const testFunction = common.mustNotCall(message);

const validateError = common.mustCall((e) => {
  const prefix = `${message} at `;
  assert.ok(e.message.startsWith(prefix));
  if (process.platform === 'win32') {
    e.message = e.message.substring(2); // remove 'C:'
  }
  const [ fileName, lineNumber ] = e.message
                                    .substring(prefix.length).split(':');
  assert.strictEqual(path.basename(fileName), 'test-common-must-not-call.js');
  assert.strictEqual(lineNumber, '8');
});

try {
  testFunction();
} catch (e) {
  validateError(e);
}