Skip to content

Commit

Permalink
testing: fix incorrect offsets showing escape codes in output (#173222)
Browse files Browse the repository at this point in the history
Fixes #166270
  • Loading branch information
connor4312 authored Feb 3, 2023
1 parent 86e7df9 commit c4a609f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
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

0 comments on commit c4a609f

Please sign in to comment.