From 952c027ba90f7b157445c78a4865b2ccbcb606f6 Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Wed, 25 Dec 2024 18:03:58 +0100 Subject: [PATCH] Refactoring pushd, popd unit tests and outputs --- .../resources.resjson/en-US/resources.resjson | 45 ++++++----- node/lib.json | 81 ++++++++++--------- node/task.ts | 7 +- node/test/popd.ts | 5 +- node/test/pushd.ts | 5 +- 5 files changed, 73 insertions(+), 70 deletions(-) diff --git a/node/Strings/resources.resjson/en-US/resources.resjson b/node/Strings/resources.resjson/en-US/resources.resjson index 41844a99b..d2f90304e 100644 --- a/node/Strings/resources.resjson/en-US/resources.resjson +++ b/node/Strings/resources.resjson/en-US/resources.resjson @@ -1,36 +1,39 @@ { - "loc.messages.LIB_UnhandledEx": "Unhandled: %s", + "loc.messages.LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s", + "loc.messages.LIB_DirectoryStackEmpty": "Directory stack is empty", + "loc.messages.LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s", + "loc.messages.LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s", + "loc.messages.LIB_EndpointNotExist": "Endpoint not present: %s", "loc.messages.LIB_FailOnCode": "Failure return code: %d", + "loc.messages.LIB_InputRequired": "Input required: %s", + "loc.messages.LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s", + "loc.messages.LIB_InvalidPattern": "Invalid pattern: '%s'", + "loc.messages.LIB_InvalidSecureFilesInput": "Invalid secure file input: %s", + "loc.messages.LIB_LocStringNotFound": "Can\\'t find loc string for key: %s", + "loc.messages.LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.", "loc.messages.LIB_MkdirFailed": "Unable to create directory '%s'. %s", "loc.messages.LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'", "loc.messages.LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'", "loc.messages.LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.", "loc.messages.LIB_MultilineSecret": "Secrets cannot contain multiple lines", + "loc.messages.LIB_NotFoundPreviousDirectory": "Could not find previous directory", + "loc.messages.LIB_OperationFailed": "Failed %s: %s", + "loc.messages.LIB_ParameterIsRequired": "%s not supplied", + "loc.messages.LIB_PathHasNullByte": "Path cannot contain null bytes", + "loc.messages.LIB_PathIsNotADirectory": "Path is not a directory: %s", + "loc.messages.LIB_PathNotFound": "Not found %s: %s", + "loc.messages.LIB_PlatformNotSupported": "Platform not supported: %s", "loc.messages.LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s", "loc.messages.LIB_ProcessExitCode": "The process '%s' failed with exit code %s", "loc.messages.LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream", - "loc.messages.LIB_ReturnCode": "Return code: %d", - "loc.messages.LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s", "loc.messages.LIB_ResourceFileAlreadySet": "Resource file has already set to: %s", + "loc.messages.LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s", "loc.messages.LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s", + "loc.messages.LIB_ReturnCode": "Return code: %d", "loc.messages.LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.", - "loc.messages.LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.", - "loc.messages.LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.", - "loc.messages.LIB_LocStringNotFound": "Can\\'t find loc string for key: %s", - "loc.messages.LIB_ParameterIsRequired": "%s not supplied", - "loc.messages.LIB_InputRequired": "Input required: %s", - "loc.messages.LIB_InvalidPattern": "Invalid pattern: '%s'", - "loc.messages.LIB_EndpointNotExist": "Endpoint not present: %s", - "loc.messages.LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s", - "loc.messages.LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s", - "loc.messages.LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s", - "loc.messages.LIB_InvalidSecureFilesInput": "Invalid secure file input: %s", - "loc.messages.LIB_PathNotFound": "Not found %s: %s", - "loc.messages.LIB_PathHasNullByte": "Path cannot contain null bytes", - "loc.messages.LIB_OperationFailed": "Failed %s: %s", + "loc.messages.LIB_UndefinedNodeVersion": "Node version is undefined.", + "loc.messages.LIB_UnhandledEx": "Unhandled: %s", "loc.messages.LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.", - "loc.messages.LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.", - "loc.messages.LIB_PlatformNotSupported": "Platform not supported: %s", - "loc.messages.LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s", - "loc.messages.LIB_UndefinedNodeVersion": "Node version is undefined." + "loc.messages.LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.", + "loc.messages.LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file." } \ No newline at end of file diff --git a/node/lib.json b/node/lib.json index 144a949c7..adbc62565 100644 --- a/node/lib.json +++ b/node/lib.json @@ -1,40 +1,41 @@ -{ - "messages": { - "LIB_UnhandledEx": "Unhandled: %s", - "LIB_FailOnCode": "Failure return code: %d", - "LIB_MkdirFailed": "Unable to create directory '%s'. %s", - "LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'", - "LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'", - "LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.", - "LIB_MultilineSecret": "Secrets cannot contain multiple lines", - "LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s", - "LIB_ProcessExitCode": "The process '%s' failed with exit code %s", - "LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream", - "LIB_ReturnCode": "Return code: %d", - "LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s", - "LIB_ResourceFileAlreadySet": "Resource file has already set to: %s", - "LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s", - "LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.", - "LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.", - "LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.", - "LIB_LocStringNotFound": "Can\\'t find loc string for key: %s", - "LIB_ParameterIsRequired": "%s not supplied", - "LIB_InputRequired": "Input required: %s", - "LIB_InvalidPattern": "Invalid pattern: '%s'", - "LIB_EndpointNotExist": "Endpoint not present: %s", - "LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s", - "LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s", - "LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s", - "LIB_InvalidSecureFilesInput": "Invalid secure file input: %s", - "LIB_PathIsNotADirectory": "Path is not a directory: %s", - "LIB_PathNotFound": "Not found %s: %s", - "LIB_PathHasNullByte": "Path cannot contain null bytes", - "LIB_OperationFailed": "Failed %s: %s", - "LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.", - "LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.", - "LIB_NotFoundPreviousDirectory": "Could not find previous directory", - "LIB_PlatformNotSupported": "Platform not supported: %s", - "LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s", - "LIB_UndefinedNodeVersion": "Node version is undefined." - } -} +{ + "messages": { + "LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s", + "LIB_DirectoryStackEmpty": "Directory stack is empty", + "LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s", + "LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s", + "LIB_EndpointNotExist": "Endpoint not present: %s", + "LIB_FailOnCode": "Failure return code: %d", + "LIB_InputRequired": "Input required: %s", + "LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s", + "LIB_InvalidPattern": "Invalid pattern: '%s'", + "LIB_InvalidSecureFilesInput": "Invalid secure file input: %s", + "LIB_LocStringNotFound": "Can\\'t find loc string for key: %s", + "LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.", + "LIB_MkdirFailed": "Unable to create directory '%s'. %s", + "LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'", + "LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'", + "LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.", + "LIB_MultilineSecret": "Secrets cannot contain multiple lines", + "LIB_NotFoundPreviousDirectory": "Could not find previous directory", + "LIB_OperationFailed": "Failed %s: %s", + "LIB_ParameterIsRequired": "%s not supplied", + "LIB_PathHasNullByte": "Path cannot contain null bytes", + "LIB_PathIsNotADirectory": "Path is not a directory: %s", + "LIB_PathNotFound": "Not found %s: %s", + "LIB_PlatformNotSupported": "Platform not supported: %s", + "LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s", + "LIB_ProcessExitCode": "The process '%s' failed with exit code %s", + "LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream", + "LIB_ResourceFileAlreadySet": "Resource file has already set to: %s", + "LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s", + "LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s", + "LIB_ReturnCode": "Return code: %d", + "LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.", + "LIB_UndefinedNodeVersion": "Node version is undefined.", + "LIB_UnhandledEx": "Unhandled: %s", + "LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.", + "LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.", + "LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file." + } +} \ No newline at end of file diff --git a/node/task.ts b/node/task.ts index 7dc0aaafd..c52687305 100644 --- a/node/task.ts +++ b/node/task.ts @@ -833,7 +833,7 @@ export function pushd(dir: string = ''): string[] { if (dirs.length > 1) { dirs.splice(0, 0, ...dirs.splice(1, 1)); } else { - throw new Error(`Failed pushd: no other directory`); + throw new Error(loc('LIB_DirectoryStackEmpty')); } } else if (!isNaN(maybeIndex)) { if (maybeIndex < dirStack.length + 1) { @@ -850,11 +850,12 @@ export function pushd(dir: string = ''): string[] { cd(_path); } catch (error) { if (!fs.existsSync(_path)) { - throw new Error(`Failed pushd: no such file or directory: ${_path}`); + throw new Error(loc('Not found', 'pushd', _path)); } throw error; } + dirStack.splice(0, dirStack.length, ...dirs); return getActualStack(); } @@ -867,7 +868,7 @@ export function pushd(dir: string = ''): string[] { */ export function popd(index: string = ''): string[] { if (dirStack.length === 0) { - throw new Error(`Failed popd: directory stack empty`); + throw new Error(loc('LIB_DirectoryStackEmpty')); } let maybeIndex = parseInt(index); diff --git a/node/test/popd.ts b/node/test/popd.ts index 6548456ca..460b0dbfe 100644 --- a/node/test/popd.ts +++ b/node/test/popd.ts @@ -1,4 +1,3 @@ -import fs = require('node:fs'); import path = require('node:path'); import assert = require('node:assert'); @@ -121,7 +120,7 @@ describe('popd cases', () => { }); it('Using when stack is empty', (done) => { - assert.throws(() => tl.popd(), { message: 'Failed popd: directory stack empty' }); + assert.throws(() => tl.popd(), { message: 'Directory stack is empty' }); done(); }); @@ -133,7 +132,7 @@ describe('popd cases', () => { assert.ok(trail[0], path.resolve(DIRNAME, TEMP_DIR_PATH)); assert.ok(process.cwd(), trail[0]); - assert.throws(() => tl.popd(), { message: 'Failed popd: directory stack empty' }); + assert.throws(() => tl.popd(), { message: 'Directory stack is empty' }); done(); }); diff --git a/node/test/pushd.ts b/node/test/pushd.ts index 09df41bf9..ab05aa18e 100644 --- a/node/test/pushd.ts +++ b/node/test/pushd.ts @@ -1,4 +1,3 @@ -import fs = require('node:fs'); import path = require('node:path'); import assert = require('node:assert'); @@ -293,7 +292,7 @@ describe('pushd cases', () => { it('Using invalid directory', (done) => { const oldCwd = process.cwd(); - assert.throws(() => tl.pushd('does/not/exist'), { message: /^Failed pushd: no such file or directory:/ }); + assert.throws(() => tl.pushd('does/not/exist'), { message: /^Not found pushd/ }); assert.equal(process.cwd(), oldCwd); done(); @@ -332,7 +331,7 @@ describe('pushd cases', () => { }); it('Using without arguments invalid when stack is empty', (done) => { - assert.throws(() => tl.pushd(), { message: 'Failed pushd: no other directory' }); + assert.throws(() => tl.pushd(), { message: 'Directory stack is empty' }); done(); });