summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-readfile-error.js
blob: c61449a2db9b56bec953fec069042b1fbe4f8e80 (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
'use strict';
var common = require('../common');
var assert = require('assert');
var exec = require('child_process').exec;
var path = require('path');

// `fs.readFile('/')` does not fail on FreeBSD, because you can open and read
// the directory there.
if (process.platform === 'freebsd') {
  console.log('1..0 # Skipped: platform not supported.');
  return;
}

var callbacks = 0;

function test(env, cb) {
  var filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js');
  var execPath = '"' + process.execPath + '" "' + filename + '"';
  var options = { env: Object.assign(process.env, env) };
  exec(execPath, options, function(err, stdout, stderr) {
    assert(err);
    assert.equal(stdout, '');
    assert.notEqual(stderr, '');
    cb('' + stderr);
  });
}

test({ NODE_DEBUG: '' }, function(data) {
  assert(/EISDIR/.test(data));
  assert(!/test-fs-readfile-error/.test(data));
  callbacks++;
});

test({ NODE_DEBUG: 'fs' }, function(data) {
  assert(/EISDIR/.test(data));
  assert(/test-fs-readfile-error/.test(data));
  callbacks++;
});

process.on('exit', function() {
  assert.equal(callbacks, 2);
});