Skip to content

Commit 580a453

Browse files
vinimdocarmoitaloacasas
authored andcommittedJan 30, 2017
test: expand test coverage of fs.js
* test calling truncateSync() passing a file descriptor * test calling truncate() passing undefined as the 2nd argument Refs: https://coverage.nodejs.org/coverage-8ab561b2432bdae3/root/fs.js.html (line 673 and 692) PR-URL: nodejs#10972 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 1fae98b commit 580a453

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
 
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const path = require('path');
5+
const fs = require('fs');
6+
const tmp = common.tmpDir;
7+
8+
common.refreshTmpDir();
9+
10+
const filename = path.resolve(tmp, 'truncate-sync-file.txt');
11+
12+
fs.writeFileSync(filename, 'hello world', 'utf8');
13+
14+
const fd = fs.openSync(filename, 'r+');
15+
16+
fs.truncateSync(fd, 5);
17+
assert(fs.readFileSync(fd).equals(Buffer.from('hello')));
18+
19+
fs.closeSync(fd);
20+
fs.unlinkSync(filename);

‎test/parallel/test-fs-truncate.js

+11
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,14 @@ function testFtruncate(cb) {
146146
assert(fs.readFileSync(file4).equals(Buffer.from('Hi\u0000\u0000')));
147147
}));
148148
}
149+
150+
{
151+
const file5 = path.resolve(tmp, 'truncate-file-5.txt');
152+
fs.writeFileSync(file5, 'Hi');
153+
const fd = fs.openSync(file5, 'r+');
154+
process.on('exit', () => fs.closeSync(fd));
155+
fs.ftruncate(fd, undefined, common.mustCall(function(err) {
156+
assert.ifError(err);
157+
assert(fs.readFileSync(file5).equals(Buffer.from('')));
158+
}));
159+
}

0 commit comments

Comments
 (0)