Merge "test.c: Add unit test registration checks for summary and description."
authorJoshua Colp <jcolp@digium.com>
Thu, 25 Jun 2015 09:52:02 +0000 (04:52 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Thu, 25 Jun 2015 09:52:02 +0000 (04:52 -0500)
include/asterisk/test.h
main/test.c

index 69f8837..49731fe 100644 (file)
@@ -224,13 +224,22 @@ struct ast_test_info {
        /*!
         * \brief test category
         *
+        * \details
         * Tests are categorized in a directory tree style hierarchy.  It is expected that
         * this string have both a leading and trailing forward slash ('/').
         */
        const char *category;
-       /*! \brief optional short summary of test */
+       /*!
+        * \brief Short summary of test
+        *
+        * \note The summary must not end with a newline.
+        */
        const char *summary;
-       /*! \brief optional brief detailed description of test */
+       /*!
+        * \brief More detailed description of test
+        *
+        * \note The description must not end with a newline.
+        */
        const char *description;
 };
 
index d1dce09..2f6200f 100644 (file)
@@ -640,33 +640,53 @@ static struct ast_test *test_alloc(ast_test_cb_t *cb)
 
        if (ast_strlen_zero(test->info.category)) {
                ast_log(LOG_ERROR, "Test %s has no category, test registration refused.\n",
-                               test->info.name);
+                       test->info.name);
                return test_free(test);
        }
 
        if (test->info.category[0] != '/' || test->info.category[strlen(test->info.category) - 1] != '/') {
                ast_log(LOG_WARNING, "Test category '%s' for test '%s' is missing a leading or trailing slash.\n",
-                               test->info.category, test->info.name);
-               /* Flag an error anyways so test_registrations fails but allow the test to be
-                * registered. */
-               registration_errors++;
+                       test->info.category, test->info.name);
+               /*
+                * Flag an error anyways so test_registrations fails but allow the
+                * test to be registered.
+                */
+               ++registration_errors;
        }
 
        if (ast_strlen_zero(test->info.summary)) {
                ast_log(LOG_ERROR, "Test %s%s has no summary, test registration refused.\n",
-                               test->info.category, test->info.name);
+                       test->info.category, test->info.name);
                return test_free(test);
        }
+       if (test->info.summary[strlen(test->info.summary) - 1] == '\n') {
+               ast_log(LOG_WARNING, "Test %s%s summary has a trailing newline.\n",
+                       test->info.category, test->info.name);
+               /*
+                * Flag an error anyways so test_registrations fails but allow the
+                * test to be registered.
+                */
+               ++registration_errors;
+       }
 
        if (ast_strlen_zero(test->info.description)) {
                ast_log(LOG_ERROR, "Test %s%s has no description, test registration refused.\n",
-                               test->info.category, test->info.name);
+                       test->info.category, test->info.name);
                return test_free(test);
        }
+       if (test->info.description[strlen(test->info.description) - 1] == '\n') {
+               ast_log(LOG_WARNING, "Test %s%s description has a trailing newline.\n",
+                       test->info.category, test->info.name);
+               /*
+                * Flag an error anyways so test_registrations fails but allow the
+                * test to be registered.
+                */
+               ++registration_errors;
+       }
 
        if (!(test->status_str = ast_str_create(128))) {
                ast_log(LOG_ERROR, "Failed to allocate status_str for %s%s, test registration failed.\n",
-                               test->info.category, test->info.name);
+                       test->info.category, test->info.name);
                return test_free(test);
        }