test: improve formatting of diagnostic messages

Put a space after the '#' and handle messages with newlines.

PR-URL: https://github.com/libuv/libuv/pull/898
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2016-06-06 14:47:51 +02:00
parent dd9f751ead
commit b936ace934
4 changed files with 31 additions and 38 deletions

View File

@ -289,8 +289,7 @@ long int process_output_size(process_info_t *p) {
/* Copy the contents of the stdio output buffer to `fd`. */
int process_copy_output(process_info_t *p, int fd) {
ssize_t nwritten;
int process_copy_output(process_info_t* p, FILE* stream) {
char buf[1024];
int r;
@ -301,18 +300,8 @@ int process_copy_output(process_info_t *p, int fd) {
}
/* TODO: what if the line is longer than buf */
while (fgets(buf, sizeof(buf), p->stdout_file) != NULL) {
/* TODO: what if write doesn't write the whole buffer... */
nwritten = 0;
nwritten += write(fd, "#", 1);
nwritten += write(fd, buf, strlen(buf));
if (nwritten < 0) {
perror("write");
return -1;
}
}
while (fgets(buf, sizeof(buf), p->stdout_file) != NULL)
print_lines(buf, strlen(buf), stream);
if (ferror(p->stdout_file)) {
perror("read");

View File

@ -208,10 +208,9 @@ long int process_output_size(process_info_t *p) {
}
int process_copy_output(process_info_t *p, int fd) {
int process_copy_output(process_info_t* p, FILE* stream) {
DWORD read;
char buf[1024];
char *line, *start;
if (SetFilePointer(p->stdio_out,
0,
@ -220,23 +219,8 @@ int process_copy_output(process_info_t *p, int fd) {
return -1;
}
write(fd, "#", 1);
while (ReadFile(p->stdio_out, (void*)&buf, sizeof(buf), &read, NULL) &&
read > 0) {
start = buf;
while ((line = strchr(start, '\n')) != NULL) {
write(fd, start, line - start + 1);
write(fd, "#", 1);
start = line + 1;
}
if (start < buf + read)
write(fd, start, buf + read - start);
}
write(fd, "\n", 1);
while (ReadFile(p->stdio_out, &buf, sizeof(buf), &read, NULL) && read > 0)
print_lines(buf, read, stream);
if (GetLastError() != ERROR_HANDLE_EOF)
return -1;

View File

@ -282,7 +282,7 @@ out:
/* Show error and output from processes if the test failed. */
if ((status != TEST_OK && status != TEST_SKIP) || task->show_output) {
fprintf(stderr, "#");
fprintf(stderr, "# ");
fflush(stderr);
for (i = 0; i < process_count; i++) {
@ -302,7 +302,7 @@ out:
default:
fprintf(stderr, "Output from process `%s`:\n", process_get_name(&processes[i]));
fflush(stderr);
process_copy_output(&processes[i], fileno(stderr));
process_copy_output(&processes[i], stderr);
break;
}
}
@ -322,7 +322,7 @@ out:
default:
for (i = 0; i < process_count; i++) {
process_copy_output(&processes[i], fileno(stderr));
process_copy_output(&processes[i], stderr);
}
break;
}
@ -408,3 +408,21 @@ void print_tests(FILE* stream) {
}
}
}
void print_lines(const char* buffer, size_t size, FILE* stream) {
const char* start;
const char* end;
start = buffer;
while ((end = memchr(start, '\n', &buffer[size] - start))) {
fprintf(stream, "# %.*s\n", (int) (end - start), start);
fflush(stream);
start = end + 1;
}
if (start < &buffer[size]) {
fprintf(stream, "# %s\n", start);
fflush(stream);
}
}

View File

@ -126,6 +126,8 @@ int run_test_part(const char* test, const char* part);
*/
void print_tests(FILE* stream);
/* Print lines in |buffer| as TAP diagnostics to |stream|. */
void print_lines(const char* buffer, size_t size, FILE* stream);
/*
* Stuff that should be implemented by test-runner-<platform>.h
@ -148,8 +150,8 @@ int process_wait(process_info_t *vec, int n, int timeout);
/* Returns the number of bytes in the stdio output buffer for process `p`. */
long int process_output_size(process_info_t *p);
/* Copy the contents of the stdio output buffer to `fd`. */
int process_copy_output(process_info_t *p, int fd);
/* Copy the contents of the stdio output buffer to `stream`. */
int process_copy_output(process_info_t* p, FILE* stream);
/* Copy the last line of the stdio output buffer to `buffer` */
int process_read_last_line(process_info_t *p,