From 60847652aa39476bd21e7ec0a339b99abd73845d Mon Sep 17 00:00:00 2001 From: Aaron Traas Date: Wed, 28 Jun 2017 12:25:59 -0400 Subject: [PATCH] Test coverage: make LCOV ignore code unreachable without interactive shell --- misc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/misc.c b/misc.c index 81f8e2b..0b28f00 100644 --- a/misc.c +++ b/misc.c @@ -252,7 +252,10 @@ char* get_input() input = NULL; size_t n = 0; if (isatty(0)) + // LCOV_EXCL_START + // Should be unreachable in tests, as they will use a non-interactive shell. printf("%s", input_prompt); + // LCOV_EXCL_STOP IGNORE(getline(&input, &n, stdin)); } @@ -289,10 +292,13 @@ bool yes(const char* question, const char* yes_response, const char* no_response speak(question); reply = get_input(); - if (reply == NULL) { - linenoiseFree(reply); - exit(EXIT_SUCCESS); - } + if (reply == NULL) { + // LCOV_EXCL_START + // Should be unreachable. Reply should never be NULL + linenoiseFree(reply); + exit(EXIT_SUCCESS); + // LCOV_EXCL_STOP + } char* firstword = (char*) xmalloc(strlen(reply)+1); sscanf(reply, "%s", firstword); -- 2.31.1