Test coverage: make LCOV ignore code unreachable without interactive shell

This commit is contained in:
Aaron Traas 2017-06-28 12:25:59 -04:00 committed by Eric S. Raymond
parent 6521d49c07
commit 60847652aa

14
misc.c
View file

@ -252,7 +252,10 @@ char* get_input()
input = NULL; input = NULL;
size_t n = 0; size_t n = 0;
if (isatty(0)) if (isatty(0))
// LCOV_EXCL_START
// Should be unreachable in tests, as they will use a non-interactive shell.
printf("%s", input_prompt); printf("%s", input_prompt);
// LCOV_EXCL_STOP
IGNORE(getline(&input, &n, stdin)); IGNORE(getline(&input, &n, stdin));
} }
@ -289,10 +292,13 @@ bool yes(const char* question, const char* yes_response, const char* no_response
speak(question); speak(question);
reply = get_input(); reply = get_input();
if (reply == NULL) { if (reply == NULL) {
linenoiseFree(reply); // LCOV_EXCL_START
exit(EXIT_SUCCESS); // Should be unreachable. Reply should never be NULL
} linenoiseFree(reply);
exit(EXIT_SUCCESS);
// LCOV_EXCL_STOP
}
char* firstword = (char*) xmalloc(strlen(reply)+1); char* firstword = (char*) xmalloc(strlen(reply)+1);
sscanf(reply, "%s", firstword); sscanf(reply, "%s", firstword);