Skip to content

Commit cd2a5d9

Browse files
jasnelladuh95
authored andcommitted
test: add known issue tests for fs.cp
PR-URL: #58883 Refs: #58634 Refs: #58869 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jason Zhang <[email protected]> Reviewed-By: Dario Piotrowicz <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 02e9711 commit cd2a5d9

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
// We expect this test to fail because the implementation of fsPromise.cp
4+
// does not properly support the use of Buffer as the source or destination
5+
// argument like fs.cpSync does.
6+
// Refs: https://github.com/nodejs/node/issues/58634
7+
// Refs: https://github.com/nodejs/node/issues/58869
8+
9+
const common = require('../common');
10+
const { mkdirSync, promises } = require('fs');
11+
const { join } = require('path');
12+
const tmpdir = require('../common/tmpdir');
13+
14+
tmpdir.refresh();
15+
16+
const tmpA = join(tmpdir.path, 'a');
17+
const tmpB = join(tmpdir.path, 'b');
18+
19+
mkdirSync(tmpA, { recursive: true });
20+
21+
promises.cp(Buffer.from(tmpA), Buffer.from(tmpB), {
22+
recursive: true,
23+
}).then(common.mustCall());
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
// This test will fail because the the implementation does not properly
4+
// handle the case when the `src` or `dest` is a Buffer and the `filter`
5+
// function is utilized when recursively copying directories.
6+
// Refs: https://github.com/nodejs/node/issues/58634
7+
// Refs: https://github.com/nodejs/node/issues/58869
8+
9+
const common = require('../common');
10+
11+
const {
12+
cpSync,
13+
mkdirSync,
14+
} = require('fs');
15+
16+
const {
17+
join,
18+
} = require('path');
19+
20+
const tmpdir = require('../common/tmpdir');
21+
tmpdir.refresh();
22+
23+
const pathA = join(tmpdir.path, 'a');
24+
const pathAC = join(pathA, 'c');
25+
const pathB = join(tmpdir.path, 'b');
26+
mkdirSync(pathAC, { recursive: true });
27+
28+
cpSync(Buffer.from(pathA), Buffer.from(pathB), {
29+
recursive: true,
30+
// This should be called multiple times, once for each file/directory,
31+
// but it's only called once in this test because we're expecting this
32+
// to fail.
33+
filter: common.mustCall(() => true, 1),
34+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
// Refs: https://github.com/nodejs/node/issues/58634
4+
// Refs: https://github.com/nodejs/node/issues/58869
5+
6+
const common = require('../common');
7+
8+
if (!common.isLinux) {
9+
common.skip('This test is only applicable to Linux');
10+
}
11+
12+
const { ok, strictEqual } = require('assert');
13+
const { join } = require('path');
14+
const path = require('path');
15+
const tmpdir = require('../common/tmpdir');
16+
const {
17+
cpSync,
18+
existsSync,
19+
mkdirSync,
20+
writeFileSync,
21+
readFileSync,
22+
} = require('fs');
23+
tmpdir.refresh();
24+
25+
const tmpdirPath = Buffer.from(join(tmpdir.path, 'a', 'c'));
26+
const sepBuf = Buffer.from(path.sep);
27+
28+
mkdirSync(tmpdirPath, { recursive: true });
29+
30+
// The name is the Shift-JIS encoded version of こんにちは世界,
31+
// or "Hello, World" in Japanese. On Linux systems, this name is
32+
// a valid path name and should be handled correctly by the copy
33+
// operation. However, the implementation of cp makes the assumption
34+
// that the path names are UTF-8 encoded, so while we can create the
35+
// file and check its existence using a Buffer, the recursive cp
36+
// operation will fail because it tries to interpret every file name
37+
// as UTF-8.
38+
const name = Buffer.from([
39+
0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82,
40+
0xBF, 0x82, 0xCD, 0x90, 0x6C, 0x8C, 0x8E,
41+
]);
42+
const testPath = Buffer.concat([tmpdirPath, sepBuf, name]);
43+
44+
writeFileSync(testPath, 'test content');
45+
ok(existsSync(testPath));
46+
strictEqual(readFileSync(testPath, 'utf8'), 'test content');
47+
48+
// The cpSync is expected to fail because the implementation does not
49+
// properly handle non-UTF8 names in the path.
50+
51+
cpSync(join(tmpdir.path, 'a'), join(tmpdir.path, 'b'), {
52+
recursive: true,
53+
filter: common.mustCall(() => true, 1),
54+
});

0 commit comments

Comments
 (0)