Test coverage: make LCOV ignore code unreachable without interactive shell
authorAaron Traas <aaron@traas.org>
Wed, 28 Jun 2017 16:25:59 +0000 (12:25 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 28 Jun 2017 17:23:34 +0000 (13:23 -0400)
misc.c

diff --git a/misc.c b/misc.c
index 81f8e2b2bd4f0212d258495fb0bed42403a7501b..0b28f00a2411e4b1673e9836b604c9c24f22be31 100644 (file)
--- 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);