1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:04:42 -07:00

playground.js: make output of "Run" clearer

This CL changes the last line displayed after the program was run
to display more details on what happened.

If the program cannot be built,
the last message is "Go build failed".

If the program has tests,
the last message is "All tests passed" in case of success.
Otherwise it is "N tests failed".

If the program has exited with non-zero code,
the exit message is postfixed with the code.

This CL adds output for timed out programs.

This CL is prerequisite for the backend change in CL 141478.
Dockerfile in playground repo has to be updated to include this CL.

Updates golang/go#10590
Updates golang/go#25454

Change-Id: Ie0a51b0729c574d2508a4a1b89f629def1d79fd6
Reviewed-on: https://go-review.googlesource.com/c/141477
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
Yury Smolsky 2018-10-11 12:34:09 +03:00
parent 4fd3307906
commit 321fe744f3
2 changed files with 42 additions and 7 deletions

View File

@ -46,12 +46,36 @@ here's a skeleton implementation of a playground transport.
function HTTPTransport(enableVet) {
'use strict';
function playback(output, events) {
function playback(output, data) {
// Backwards compatibility: default values do not affect the output.
var events = data.Events || [];
var errors = data.Errors || "";
var status = data.Status || 0;
var isTest = data.IsTest || false;
var testsFailed = data.TestsFailed || 0;
var timeout;
output({Kind: 'start'});
function next() {
if (!events || events.length === 0) {
output({Kind: 'end'});
if (isTest) {
if (testsFailed > 0) {
output({Kind: 'system', Body: '\n'+testsFailed+' test'+(testsFailed>1?'s':'')+' failed.'});
} else {
output({Kind: 'system', Body: '\nAll tests passed.'});
}
} else {
if (status > 0) {
output({Kind: 'end', Body: 'status ' + status + '.'});
} else {
if (errors !== "") {
// errors are displayed only in the case of timeout.
output({Kind: 'end', Body: errors + '.'});
} else {
output({Kind: 'end'});
}
}
}
return;
}
var e = events.shift();
@ -79,6 +103,12 @@ function HTTPTransport(enableVet) {
output({Kind: 'end'});
}
function buildFailed(output, msg) {
output({Kind: 'start'});
output({Kind: 'stderr', Body: msg});
output({Kind: 'system', Body: '\nGo build failed.'});
}
var seq = 0;
return {
Run: function(body, output, options) {
@ -94,12 +124,17 @@ function HTTPTransport(enableVet) {
if (!data) return;
if (playing != null) playing.Stop();
if (data.Errors) {
error(output, data.Errors);
if (data.Errors === 'process took too long') {
// Playback the output that was captured before the timeout.
playing = playback(output, data);
} else {
buildFailed(output, data.Errors);
}
return;
}
if (!enableVet) {
playing = playback(output, data.Events);
playing = playback(output, data);
return;
}
@ -116,10 +151,10 @@ function HTTPTransport(enableVet) {
data.Events.unshift({Message: 'Go vet exited.\n\n', Kind: 'system', Delay: 0});
data.Events.unshift({Message: dataVet.Errors, Kind: 'stderr', Delay: 0});
}
playing = playback(output, data.Events);
playing = playback(output, data);
},
error: function() {
playing = playback(output, data.Events);
playing = playback(output, data);
}
});
},

File diff suppressed because one or more lines are too long