Skip to content

Commit

Permalink
Refactoring pushd, popd unit tests and outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanduplenskikh committed Dec 25, 2024
1 parent 617e64e commit 952c027
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 70 deletions.
45 changes: 24 additions & 21 deletions node/Strings/resources.resjson/en-US/resources.resjson
Original file line number Diff line number Diff line change
@@ -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."
}
81 changes: 41 additions & 40 deletions node/lib.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
7 changes: 4 additions & 3 deletions node/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions node/test/popd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs = require('node:fs');
import path = require('node:path');
import assert = require('node:assert');

Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand Down
5 changes: 2 additions & 3 deletions node/test/pushd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs = require('node:fs');
import path = require('node:path');
import assert = require('node:assert');

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 952c027

Please sign in to comment.