Skip to content

Commit

Permalink
Merge pull request #2343 from akshita31/stdout_messages
Browse files Browse the repository at this point in the history
Show the standard output and standard error messages in tests
  • Loading branch information
akshita31 authored May 29, 2018
2 parents 0a4c6cc + 632e208 commit 66d72a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
17 changes: 14 additions & 3 deletions src/observers/DotnetTestLoggerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,23 @@ export default class DotNetTestLoggerObserver extends BaseLoggerObserver {
this.logger.increaseIndent();
this.logger.appendLine(`Outcome: ${processOutcome(result.Outcome)}`);
if (result.ErrorMessage) {
this.logger.appendLine(`Error Message: ${result.ErrorMessage}`);

this.logger.appendLine(`Error Message:`);
this.logger.appendLine(result.ErrorMessage);
}

if (result.ErrorStackTrace) {
this.logger.appendLine(`Stack Trace: ${result.ErrorStackTrace}`);
this.logger.appendLine(`Stack Trace:`);
this.logger.appendLine(result.ErrorStackTrace);
}

if (result.StandardOutput && result.StandardOutput.length > 0) {
this.logger.appendLine("Standard Output Messages:");
result.StandardOutput.forEach(message => this.logger.appendLine(message));
}

if (result.StandardError && result.StandardError.length > 0) {
this.logger.appendLine("Standard Error Messages:");
result.StandardError.forEach(message => this.logger.appendLine(message));
}

this.logger.appendLine();
Expand Down
2 changes: 2 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ export namespace V2 {
Outcome: string;
ErrorMessage: string;
ErrorStackTrace: string;
StandardOutput: string[];
StandardError: string[];
}

export interface RunTestResponse {
Expand Down
32 changes: 24 additions & 8 deletions test/unitTests/logging/DotnetTestLoggerObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ suite(`${DotNetTestLoggerObserver.name}`, () => {
suite(`${ReportDotNetTestResults.name}`, () => {
let event = new ReportDotNetTestResults(
[
getDotNetTestResults("foo", "failed", "assertion failed", "stacktrace1"),
getDotNetTestResults("failinator", "failed", "error occured", "stacktrace2"),
getDotNetTestResults("bar", "skipped", "", ""),
getDotNetTestResults("passinator", "passed", "", ""),
getDotNetTestResults("foo", "failed", "assertion failed", "stacktrace1" , ["message1", "message2"], ["errorMessage1"]),
getDotNetTestResults("failinator", "failed", "error occured", "stacktrace2", [], []),
getDotNetTestResults("bar", "skipped", "", "", ["message3", "message4"], []),
getDotNetTestResults("passinator", "passed", "", "", [], []),
]);

test(`Displays the outcome of each test`, () => {
Expand All @@ -79,17 +79,33 @@ suite(`${DotNetTestLoggerObserver.name}`, () => {

test('Displays the error message and error stack trace if any is present', () => {
observer.post(event);
expect(appendedMessage).to.contain("foo:\n Outcome: Failed\n Error Message: assertion failed\n Stack Trace: stacktrace1");
expect(appendedMessage).to.contain("failinator:\n Outcome: Failed\n Error Message: error occured\n Stack Trace: stacktrace2");
expect(appendedMessage).to.contain("foo:\n Outcome: Failed\n Error Message:\n assertion failed\n Stack Trace:\n stacktrace1");
expect(appendedMessage).to.contain("failinator:\n Outcome: Failed\n Error Message:\n error occured\n Stack Trace:\n stacktrace2");
});

test(`Displays the standard output messages if any`, () => {
observer.post(event);
event.results.forEach(result => {
result.StandardOutput.forEach(message => expect(appendedMessage).to.contain(message));
});
});

test(`Displays the standard error messages if any`, () => {
observer.post(event);
event.results.forEach(result => {
result.StandardError.forEach(message => expect(appendedMessage).to.contain(message));
});
});
});
});

function getDotNetTestResults(methodname: string, outcome: string, errorMessage: string, errorStackTrace: string): protocol.V2.DotNetTestResult {
function getDotNetTestResults(methodname: string, outcome: string, errorMessage: string, errorStackTrace: string, stdoutMessages: string[], stdErrorMessages: string[]): protocol.V2.DotNetTestResult {
return {
MethodName: methodname,
Outcome: outcome,
ErrorMessage: errorMessage,
ErrorStackTrace: errorStackTrace
ErrorStackTrace: errorStackTrace,
StandardOutput : stdoutMessages,
StandardError: stdErrorMessages
};
}

0 comments on commit 66d72a7

Please sign in to comment.