From 2e3b758006a1d0885b8e271760fdb8483811644f Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sat, 3 Jun 2017 10:20:11 -0400 Subject: [PATCH] test,module: make message check MUI dependent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/13393 Fixes: https://github.com/nodejs/node/issues/13376 Reviewed-By: Tobias Nießen --- test/parallel/test-module-loading-error.js | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index fb8ddf5a66b794..5cdf9182608632 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -22,23 +22,38 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); +const { execSync } = require('child_process'); -const error_desc = { +const errorMessagesByPlatform = { win32: ['%1 is not a valid Win32 application'], linux: ['file too short', 'Exec format error'], sunos: ['unknown file type', 'not an ELF file'], darwin: ['file too short'] }; -const dlerror_msg = error_desc[process.platform]; +// If we don't know a priori what the error would be, we accept anything. +const errorMessages = errorMessagesByPlatform[process.platform] || ['']; + +// On Windows, error messages are MUI dependent +// Ref: https://github.com/nodejs/node/issues/13376 +let localeOk = true; +if (common.isWindows) { + const powerShellFindMUI = + 'powershell -NoProfile -ExecutionPolicy Unrestricted -c ' + + '"(Get-UICulture).TwoLetterISOLanguageName"'; + try { + // If MUI != 'en' we'll ignore the content of the message + localeOk = execSync(powerShellFindMUI).toString('utf8').trim() === 'en'; + } catch (_) { + // It's only a best effort try to find the MUI + } +} assert.throws( () => { require('../fixtures/module-loading-error.node'); }, (e) => { - if (dlerror_msg && !dlerror_msg.some((msg) => e.message.includes(msg))) - return false; - if (e.name !== 'Error') + if (localeOk && !errorMessages.some((msg) => e.message.includes(msg))) return false; - return true; + return e.name === 'Error'; } );