Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinícius do Carmo <vinicius.m.do.carmo@gmail.com>2017-01-24 06:58:00 +0300
committerMyles Borins <myles.borins@gmail.com>2017-03-09 04:11:18 +0300
commit0b5f2b45f97b8c02fe478a392b60a3a6e35c4500 (patch)
tree8ca055918c589e7c6a2dc7d16f5072375a0cf22b
parentd9362efb6c95ab8154b13cc35cb5f7a521e92995 (diff)
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: https://github.com/nodejs/node/pull/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>
-rw-r--r--test/parallel/test-fs-truncate-sync.js20
-rw-r--r--test/parallel/test-fs-truncate.js11
2 files changed, 31 insertions, 0 deletions
diff --git a/test/parallel/test-fs-truncate-sync.js b/test/parallel/test-fs-truncate-sync.js
new file mode 100644
index 00000000000..a7ce2f4d97f
--- /dev/null
+++ b/test/parallel/test-fs-truncate-sync.js
@@ -0,0 +1,20 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const path = require('path');
+const fs = require('fs');
+const tmp = common.tmpDir;
+
+common.refreshTmpDir();
+
+const filename = path.resolve(tmp, 'truncate-sync-file.txt');
+
+fs.writeFileSync(filename, 'hello world', 'utf8');
+
+const fd = fs.openSync(filename, 'r+');
+
+fs.truncateSync(fd, 5);
+assert(fs.readFileSync(fd).equals(Buffer.from('hello')));
+
+fs.closeSync(fd);
+fs.unlinkSync(filename);
diff --git a/test/parallel/test-fs-truncate.js b/test/parallel/test-fs-truncate.js
index 1ba0db7f012..de8d6d9fdce 100644
--- a/test/parallel/test-fs-truncate.js
+++ b/test/parallel/test-fs-truncate.js
@@ -146,3 +146,14 @@ function testFtruncate(cb) {
assert(fs.readFileSync(file4).equals(Buffer.from('Hi\u0000\u0000')));
}));
}
+
+{
+ const file5 = path.resolve(tmp, 'truncate-file-5.txt');
+ fs.writeFileSync(file5, 'Hi');
+ const fd = fs.openSync(file5, 'r+');
+ process.on('exit', () => fs.closeSync(fd));
+ fs.ftruncate(fd, undefined, common.mustCall(function(err) {
+ assert.ifError(err);
+ assert(fs.readFileSync(file5).equals(Buffer.from('')));
+ }));
+}