Skip to content

Commit

Permalink
test: add non-ASCII character embedding test
Browse files Browse the repository at this point in the history
Add a test that verifies that non-ASCII characters may be used
in the source code provided to `LoadEnvironment()`.

PR-URL: #33972
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and jasnell committed Jun 26, 2020
1 parent 074df49 commit db6e6e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/embedding/embedtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ int RunNodeInstance(MultiIsolatePlatform* platform,
"const publicRequire ="
" require('module').createRequire(process.cwd() + '/');"
"globalThis.require = publicRequire;"
"globalThis.embedVars = { nön_ascıı: '🏳️‍🌈' };"
"require('vm').runInThisContext(process.argv[1]);");

if (loadenv_ret.IsEmpty()) // There has been a JS exception.
Expand Down
11 changes: 11 additions & 0 deletions test/embedding/test-embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ const child_process = require('child_process');
const path = require('path');

common.allowGlobals(global.require);
common.allowGlobals(global.embedVars);
let binary = `out/${common.buildType}/embedtest`;
if (common.isWindows) {
binary += '.exe';
}
binary = path.resolve(__dirname, '..', '..', binary);

assert.strictEqual(
child_process.spawnSync(binary, ['console.log(42)'])
.stdout.toString().trim(),
'42');

assert.strictEqual(
child_process.spawnSync(binary, ['console.log(embedVars.nön_ascıı)'])
.stdout.toString().trim(),
'🏳️‍🌈');

assert.strictEqual(
child_process.spawnSync(binary, ['console.log(42)'])
.stdout.toString().trim(),
Expand Down

0 comments on commit db6e6e3

Please sign in to comment.