Skip to content

Commit

Permalink
fix for multiple brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Sep 10, 2023
1 parent e7ecb5a commit 11cf0b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/client/testing/testController/common/resultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ export class PythonResultResolver implements ITestResultResolver {
throw new Error('Parent test item not found');
}
} else if (rawTestExecData.result[keyTemp].outcome === 'subtest-success') {
// split on " " since the subtest ID has the parent test ID in the first part of the ID.
const parentTestCaseId = keyTemp.split(' [')[0];
const subtestId = `[${keyTemp.split(' [')[1]}`;
// split only on first " [" since the subtest ID has the parent test ID in the first part of the ID.
const index = keyTemp.indexOf(' [');
const parentTestCaseId = keyTemp.substring(0, index);
// add one to index to remove the space from the start of the subtest ID
const subtestId = keyTemp.substring(index + 1, keyTemp.length);
const parentTestItem = this.runIdToTestItem.get(parentTestCaseId);

// find the subtest's parent test item
Expand Down
13 changes: 7 additions & 6 deletions src/test/testing/testController/resultResolver.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,16 @@ suite('Result Resolver tests', () => {
testProvider,
workspaceUri,
);
const mockSubtestItem = createMockTestItem('parentTest [subTest with spaces]');
const subtestName = 'parentTest [subTest with spaces and [brackets]]';
const mockSubtestItem = createMockTestItem(subtestName);
// add a mock test item to the map of known VSCode ids to run ids
resultResolver.runIdToVSid.set('mockTestItem2', 'mockTestItem2');
// creates a mock test item with a space which will be used to split the runId
resultResolver.runIdToVSid.set('parentTest [subTest with spaces]', 'parentTest [subTest with spaces]');
resultResolver.runIdToVSid.set(subtestName, subtestName);

// add this mock test to the map of known test items
resultResolver.runIdToTestItem.set('parentTest', mockTestItem2);
resultResolver.runIdToTestItem.set('parentTest [subTest with spaces]', mockSubtestItem);
resultResolver.runIdToTestItem.set(subtestName, mockSubtestItem);

let generatedId: string | undefined;
testControllerMock
Expand All @@ -294,12 +295,12 @@ suite('Result Resolver tests', () => {
cwd: workspaceUri.fsPath,
status: 'success',
result: {
'parentTest [subTest with spaces]': {
'parentTest [subTest with spaces and [brackets]]': {
test: 'parentTest',
outcome: 'subtest-success', // failure, passed-unexpected, skipped, success, expected-failure, subtest-failure, subtest-succcess
message: 'message',
traceback: 'traceback',
subtest: 'parentTest [subTest with spaces]',
subtest: subtestName,
},
},
error: '',
Expand All @@ -310,7 +311,7 @@ suite('Result Resolver tests', () => {

// verify that the passed function was called for the single test item
assert.ok(generatedId);
assert.strictEqual(generatedId, '[subTest with spaces]');
assert.strictEqual(generatedId, '[subTest with spaces and [brackets]]');
});
test('resolveExecution handles failed tests correctly', async () => {
// test specific constants used expected values
Expand Down

0 comments on commit 11cf0b8

Please sign in to comment.