summaryrefslogtreecommitdiff
path: root/test/parallel/test-uv-errno.js
blob: ccada53f29b581ea8330ed3f91334640a70227fd (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Flags: --expose-internals
'use strict';

const common = require('../common');
const assert = require('assert');
const {
  getSystemErrorName,
  _errnoException
} = require('util');

const { internalBinding } = require('internal/test/binding');
const uv = internalBinding('uv');
const keys = Object.keys(uv);

keys.forEach((key) => {
  if (!key.startsWith('UV_'))
    return;

  const err = _errnoException(uv[key], 'test');
  const name = uv.errname(uv[key]);
  assert.strictEqual(getSystemErrorName(uv[key]), name);
  assert.strictEqual(err.code, name);
  assert.strictEqual(err.code, err.errno);
  assert.strictEqual(err.message, `test ${name}`);
});

function runTest(fn) {
  ['test', {}, []].forEach((err) => {
    common.expectsError(
      () => fn(err),
      {
        code: 'ERR_INVALID_ARG_TYPE',
        type: TypeError,
        message: 'The "err" argument must be of type number.' +
                 common.invalidArgTypeHelper(err)
      });
  });

  [0, 1, Infinity, -Infinity, NaN].forEach((err) => {
    common.expectsError(
      () => fn(err),
      {
        code: 'ERR_OUT_OF_RANGE',
        type: RangeError,
        message: 'The value of "err" is out of range. ' +
                 'It must be a negative integer. ' +
                 `Received ${err}`
      });
  });
}

runTest(_errnoException);
runTest(getSystemErrorName);