1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
25 var common = require('../common');
26 var assert = require('assert');
28 var path = require('path'),
30 fn = path.join(common.fixturesDir, 'non-existent'),
31 existingFile = path.join(common.fixturesDir, 'exit.js'),
32 existingFile2 = path.join(common.fixturesDir, 'create-file.js'),
33 existingDir = path.join(common.fixturesDir, 'empty'),
34 existingDir2 = path.join(common.fixturesDir, 'keys');
38 fs.stat(fn, function(err) {
39 assert.equal(fn, err.path);
40 assert.ok(0 <= err.message.indexOf(fn));
43 fs.lstat(fn, function(err) {
44 assert.ok(0 <= err.message.indexOf(fn));
47 fs.readlink(fn, function(err) {
48 assert.ok(0 <= err.message.indexOf(fn));
51 fs.link(fn, 'foo', function(err) {
52 assert.ok(0 <= err.message.indexOf(fn));
55 fs.link(existingFile, existingFile2, function(err) {
56 assert.ok(0 <= err.message.indexOf(existingFile2));
59 fs.symlink(existingFile, existingFile2, function(err) {
60 assert.ok(0 <= err.message.indexOf(existingFile2));
63 fs.unlink(fn, function(err) {
64 assert.ok(0 <= err.message.indexOf(fn));
67 fs.rename(fn, 'foo', function(err) {
68 assert.ok(0 <= err.message.indexOf(fn));
71 fs.rename(existingDir, existingDir2, function(err) {
72 assert.ok(0 <= err.message.indexOf(existingDir2));
75 fs.rmdir(fn, function(err) {
76 assert.ok(0 <= err.message.indexOf(fn));
79 fs.mkdir(existingFile, 0666, function(err) {
80 assert.ok(0 <= err.message.indexOf(existingFile));
83 fs.rmdir(existingFile, function(err) {
84 assert.ok(0 <= err.message.indexOf(existingFile));
87 fs.chmod(fn, 0666, function(err) {
88 assert.ok(0 <= err.message.indexOf(fn));
91 fs.open(fn, 'r', 0666, function(err) {
92 assert.ok(0 <= err.message.indexOf(fn));
95 fs.readFile(fn, function(err) {
96 assert.ok(0 <= err.message.indexOf(fn));
109 assert.ok(0 <= err.message.indexOf(fn));
114 fs.mkdirSync(existingFile, 0666);
116 errors.push('mkdir');
117 assert.ok(0 <= err.message.indexOf(existingFile));
122 fs.chmodSync(fn, 0666);
124 errors.push('chmod');
125 assert.ok(0 <= err.message.indexOf(fn));
132 errors.push('lstat');
133 assert.ok(0 <= err.message.indexOf(fn));
140 errors.push('readlink');
141 assert.ok(0 <= err.message.indexOf(fn));
146 fs.linkSync(fn, 'foo');
149 assert.ok(0 <= err.message.indexOf(fn));
154 fs.linkSync(existingFile, existingFile2);
157 assert.ok(0 <= err.message.indexOf(existingFile2));
162 fs.symlinkSync(existingFile, existingFile2);
164 errors.push('symlink');
165 assert.ok(0 <= err.message.indexOf(existingFile2));
172 errors.push('unlink');
173 assert.ok(0 <= err.message.indexOf(fn));
180 errors.push('rmdir');
181 assert.ok(0 <= err.message.indexOf(fn));
186 fs.rmdirSync(existingFile);
188 errors.push('rmdir');
189 assert.ok(0 <= err.message.indexOf(existingFile));
194 fs.openSync(fn, 'r');
196 errors.push('opens');
197 assert.ok(0 <= err.message.indexOf(fn));
202 fs.renameSync(fn, 'foo');
204 errors.push('rename');
205 assert.ok(0 <= err.message.indexOf(fn));
210 fs.renameSync(existingDir, existingDir2);
212 errors.push('rename');
213 assert.ok(0 <= err.message.indexOf(existingDir2));
220 errors.push('readdir');
221 assert.ok(0 <= err.message.indexOf(fn));
224 process.on('exit', function() {
225 assert.equal(expected, errors.length,
226 'Test fs sync exceptions raised, got ' + errors.length +
227 ' expected ' + expected);