Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: fix incorrect offsets showing escape codes in output #173222

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/vs/workbench/contrib/testing/common/testResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,24 @@ export class LiveOutputController {
/**
* Appends data to the output.
*/
public append(data: VSBuffer, marker?: number): Promise<void> | void {
public append(data: VSBuffer, marker?: number): { offset: number; done: Promise<void> | void } {
if (this.closed) {
return this.closed;
return { offset: this._offset, done: this.closed };
}

let startOffset = this._offset;
if (marker !== undefined) {
data = VSBuffer.concat([
VSBuffer.fromString(getMarkCode(marker, true)),
data,
VSBuffer.fromString(getMarkCode(marker, false)),
]);
const start = VSBuffer.fromString(getMarkCode(marker, true));
const end = VSBuffer.fromString(getMarkCode(marker, false));
startOffset += start.byteLength;
data = VSBuffer.concat([start, data, end]);
}

this.previouslyWritten?.push(data);
this.dataEmitter.fire(data);
this._offset += data.byteLength;

return this.writer.value[0].write(data);
return { offset: startOffset, done: this.writer.value[0].write(data) };
}

/**
Expand Down Expand Up @@ -359,16 +359,16 @@ export class LiveTestResult implements ITestResult {
marker = this.testMarkerCounter++;
}

const { offset } = this.output.append(output, marker);
const message: ITestOutputMessage = {
location,
message: removeAnsiEscapeCodes(preview),
offset: this.output.offset,
offset,
length: output.byteLength,
marker: marker,
type: TestMessageType.Output,
};

this.output.append(output, marker);

const index = this.mustGetTaskIndex(taskId);
if (testId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@ suite('Workbench - Test Results Service', () => {
assert.deepStrictEqual(await ctrl.getRange(15, 10), VSBuffer.fromString('67890'));
});

test('corrects offsets for marked ranges', async () => {
const ctrl = storage.getOutputController('a');

const a1 = ctrl.append(VSBuffer.fromString('12345'), 1);
const a2 = ctrl.append(VSBuffer.fromString('67890'), 1234);

assert.deepStrictEqual(await ctrl.getRange(a1.offset, 5), VSBuffer.fromString('12345'));
assert.deepStrictEqual(await ctrl.getRange(a2.offset, 5), VSBuffer.fromString('67890'));
});

test('reads stored output ranges', async () => {
const ctrl = storage.getOutputController('a');

Expand Down