Skip to content

Commit f31274d

Browse files
committed
test: search cctest files
The cctest file `test_encoding_binding.cc` is never tested and it is not a valid test. Binding functions should never be tested with V8 API circumvented. A binding function should only be tested with JS calls. To prevent a new cctest missing from the `node.gyp`, search cctest files with tool `search_files.py` at configure time.
1 parent 04f147b commit f31274d

File tree

3 files changed

+50
-196
lines changed

3 files changed

+50
-196
lines changed

node.gyp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -402,26 +402,8 @@
402402
],
403403
'node_cctest_sources': [
404404
'src/node_snapshot_stub.cc',
405-
'test/cctest/node_test_fixture.cc',
406-
'test/cctest/node_test_fixture.h',
407-
'test/cctest/test_aliased_buffer.cc',
408-
'test/cctest/test_base64.cc',
409-
'test/cctest/test_base_object_ptr.cc',
410-
'test/cctest/test_cppgc.cc',
411-
'test/cctest/test_node_postmortem_metadata.cc',
412-
'test/cctest/test_node_task_runner.cc',
413-
'test/cctest/test_environment.cc',
414-
'test/cctest/test_linked_binding.cc',
415-
'test/cctest/test_node_api.cc',
416-
'test/cctest/test_path.cc',
417-
'test/cctest/test_per_process.cc',
418-
'test/cctest/test_platform.cc',
419-
'test/cctest/test_report.cc',
420-
'test/cctest/test_json_utils.cc',
421-
'test/cctest/test_sockaddr.cc',
422-
'test/cctest/test_traced_value.cc',
423-
'test/cctest/test_util.cc',
424-
'test/cctest/test_dataqueue.cc',
405+
'<!@(<(python) tools/search_files.py . test/cctest cc)',
406+
'<!@(<(python) tools/search_files.py . test/cctest h)',
425407
],
426408
'node_cctest_openssl_sources': [
427409
'test/cctest/test_crypto_clienthello.cc',

test/cctest/test_encoding_binding.cc

Lines changed: 0 additions & 176 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Flags: --expose-internals
2+
3+
'use strict';
4+
5+
require('../common');
6+
7+
const assert = require('node:assert');
8+
const { internalBinding } = require('internal/test/binding');
9+
const binding = internalBinding('encoding_binding');
10+
11+
{
12+
// Valid input
13+
const buf = Uint8Array.from([0xC1, 0xE9, 0xF3]);
14+
assert.strictEqual(binding.decodeLatin1(buf, false, false), 'Áéó');
15+
}
16+
17+
{
18+
// Empty input
19+
const buf = Uint8Array.from([]);
20+
assert.strictEqual(binding.decodeLatin1(buf, false, false), '');
21+
}
22+
23+
{
24+
// Invalid input, but Latin1 has no invalid chars and should never throw.
25+
const buf = new TextEncoder().encode('Invalid Latin1 🧑‍🧑‍🧒‍🧒');
26+
assert.strictEqual(
27+
binding.decodeLatin1(buf, false, false),
28+
'Invalid Latin1 ð\x9F§\x91â\x80\x8Dð\x9F§\x91â\x80\x8Dð\x9F§\x92â\x80\x8Dð\x9F§\x92'
29+
);
30+
}
31+
32+
{
33+
// IgnoreBOM with BOM
34+
const buf = Uint8Array.from([0xFE, 0xFF, 0xC1, 0xE9, 0xF3]);
35+
assert.strictEqual(binding.decodeLatin1(buf, true, false), 'þÿÁéó');
36+
}
37+
38+
{
39+
// Fatal and InvalidInput, but Latin1 has no invalid chars and should never throw.
40+
const buf = Uint8Array.from([0xFF, 0xFF, 0xFF]);
41+
assert.strictEqual(binding.decodeLatin1(buf, false, true), 'ÿÿÿ');
42+
}
43+
44+
{
45+
// IgnoreBOM and Fatal, but Latin1 has no invalid chars and should never throw.
46+
const buf = Uint8Array.from([0xFE, 0xFF, 0xC1, 0xE9, 0xF3]);
47+
assert.strictEqual(binding.decodeLatin1(buf, true, true), 'þÿÁéó');
48+
}

0 commit comments

Comments
 (0)