Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 580a453

Browse filesBrowse files
vinimdocarmoItalo A. Casas
authored andcommitted
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: #10972 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 1fae98b commit 580a453
Copy full SHA for 580a453

File tree

Expand file treeCollapse file tree

2 files changed

+31
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-0
lines changed
Open diff view settings
Collapse file
+20Lines changed: 20 additions & 0 deletions
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);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-truncate.js
+11Lines changed: 11 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.