[asterisk-commits] dvossel: branch dvossel/test_api r234340 - /team/dvossel/test_api/main/test.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Dec 10 16:38:09 CST 2009
Author: dvossel
Date: Thu Dec 10 16:38:06 2009
New Revision: 234340
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=234340
Log:
neato cli tab completion for 'test execute' and 'test show registered'
Modified:
team/dvossel/test_api/main/test.c
Modified: team/dvossel/test_api/main/test.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/main/test.c?view=diff&rev=234340&r1=234339&r2=234340
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Thu Dec 10 16:38:06 2009
@@ -281,32 +281,40 @@
static char *test_cli_show_registered(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT "%-15s %-20s %-30s %-10s\n"
+ static const char * const option1[] = { "all", "catagory", NULL };
+ static const char * const option2[] = { "name", NULL };
struct ast_test *test = NULL;
int count = 0;
switch (cmd) {
case CLI_INIT:
e->command = "test show registered";
+
e->usage =
- "Usage: test show registered [test catagory] [test name] \n"
- " Shows registered tests. Has three modes.\n"
- " 1. If no arguments are provided, all registered tests will be shown\n"
- " 2. If [test catagory] is provided only tests which fall within that\n"
- " catagory will be shown.\n"
- " 3. If both [test catagory] and [test name] is provided, only the test\n"
- " within [test catagory] matching [test name] will be shown \n";
+ "Usage: test execute can be used in three ways.\n"
+ " 1. 'test show registered all' shows all registered tests\n"
+ " 2. 'test show registered catagory [test catagory]' shows all tests in the given\n"
+ " catagory.\n"
+ " 3. 'test show registered catagory [test catagory] name [test name]' shows all\n"
+ " tests in a given catagory matching a given name\n";
return NULL;
case CLI_GENERATE:
+ if (a->pos == 3) {
+ return ast_cli_complete(a->word, option1, a->n);
+ }
+ if (a->pos == 5) {
+ return ast_cli_complete(a->word, option2, a->n);
+ }
return NULL;
case CLI_HANDLER:
- if (a->argc < 3 || a->argc > 5) {
+ if ((a->argc < 4) || ((a->argc == 4) && strcmp(a->argv[3], "all")) || (a->argc > 7)) {
return CLI_SHOWUSAGE;
}
ast_cli(a->fd, FORMAT, "Name", "Catagory", "Summary", "Test Result");
AST_LIST_LOCK(&tests);
AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
- if ((a->argc == 3) ||
- ((a->argc == 4) && !strcmp(test->catagory, a->argv[3])) ||
- ((a->argc == 5) && !strcmp(test->catagory, a->argv[3]) && !strcmp(test->name, a->argv[4]))) {
+ if ((a->argc == 4) ||
+ ((a->argc == 5) && !strcmp(test->catagory, a->argv[4])) ||
+ ((a->argc == 7) && !strcmp(test->catagory, a->argv[4]) && !strcmp(test->name, a->argv[6]))) {
ast_cli(a->fd, FORMAT, test->name, test->catagory, test->summary, test_result2str[test->result.state]);
count ++;
@@ -324,31 +332,42 @@
static char *test_cli_execute_registered(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
+ static const char * const option1[] = { "all", "catagory", NULL };
+ static const char * const option2[] = { "name", NULL };
switch (cmd) {
case CLI_INIT:
e->command = "test execute";
e->usage =
- "Usage: test execute [test catagory] [test name]\n"
- " Executes registered tests. Has three modes.\n"
- " 1. If no arguments are provided, all registered tests will execute\n"
- " 2. If [test catagory] is provided only tests which fall within that\n"
- " catagory will be executed.\n"
- " 3. If both [test catagory] and [test name] is provided, only the test\n"
- " within [test catagory] matching [test name] will execute \n";
+ "Usage: test execute can be used in three ways.\n"
+ " 1. 'test execute all' runs all registered tests\n"
+ " 2. 'test execute catagory [test catagory]' runs all tests in the given\n"
+ " catagory.\n"
+ " 3. 'test execute catagory [test catagory] name [test name]' runs all\n"
+ " tests in a given catagory matching a given name\n";
return NULL;
case CLI_GENERATE:
+ if (a->pos == 2) {
+ return ast_cli_complete(a->word, option1, a->n);
+ }
+ if (a->pos == 4) {
+ return ast_cli_complete(a->word, option2, a->n);
+ }
return NULL;
case CLI_HANDLER:
- if (a->argc == 2) { /* run all registered tests */
+ if (a->argc < 3|| a->argc > 6) {
+ return CLI_SHOWUSAGE;
+ }
+
+ if ((a->argc == 3) && !strcmp(a->argv[2], "all")) { /* run all registered tests */
ast_cli(a->fd, "Running all available tests...\n");
ast_test_execute(NULL, NULL);
- } else if (a->argc == 3) { /* run only tests within a catagory */
- ast_cli(a->fd, "Running all available tests matching catagory %s\n", a->argv[2]);
- ast_test_execute(NULL, a->argv[2]);
- } else if (a->argc == 4) { /* run only a single test matching the catagory and name */
- ast_cli(a->fd, "Running all available tests matching catagory %s and name %s\n", a->argv[2], a->argv[3]);
- ast_test_execute(a->argv[3], a->argv[2]);
+ } else if (a->argc == 4) { /* run only tests within a catagory */
+ ast_cli(a->fd, "Running all available tests matching catagory %s\n", a->argv[3]);
+ ast_test_execute(NULL, a->argv[3]);
+ } else if (a->argc == 6) { /* run only a single test matching the catagory and name */
+ ast_cli(a->fd, "Running all available tests matching catagory %s and name %s\n", a->argv[5], a->argv[3]);
+ ast_test_execute(a->argv[5], a->argv[3]);
} else {
return CLI_SHOWUSAGE;
}
@@ -368,6 +387,8 @@
{
#define FORMAT_RES_ALL "%-10s %-15s %-20s %-30s\n"
struct ast_test *test = NULL;
+ int failed = 0;
+ int passed = 0;
switch (cmd) {
case CLI_INIT:
e->command = "test show results all";
@@ -387,6 +408,7 @@
AST_LIST_LOCK(&tests);
AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
if (test->result.state != AST_TEST_NOT_RUN) {
+ test->result.state == AST_TEST_FAIL ? failed++ : passed++;
ast_cli(a->fd, FORMAT_RES_ALL,
test_result2str[test->result.state],
test->name,
@@ -400,7 +422,7 @@
if (!last_results.count) {
ast_cli(a->fd, "--- No Test Results Found ---\n");
}
- ast_cli(a->fd, "%d Test(s) Executed %d Passed %d Failed\n", last_results.count, last_results.passed, last_results.failed);
+ ast_cli(a->fd, "%d Test(s) Executed %d Passed %d Failed\n", (failed + passed), passed, failed);
default:
return NULL;
}
@@ -412,6 +434,8 @@
{
#define FORMAT_RES_FAIL "%-10s %-15s %-20s %-30s\n"
struct ast_test *test = NULL;
+ int failed = 0;
+
switch (cmd) {
case CLI_INIT:
e->command = "test show results failed";
@@ -431,6 +455,7 @@
AST_LIST_LOCK(&tests);
AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
if (test->result.state == AST_TEST_FAIL) {
+ failed++;
ast_cli(a->fd, FORMAT_RES_FAIL,
test_result2str[test->result.state],
test->name,
@@ -444,7 +469,7 @@
if (!last_results.failed) {
ast_cli(a->fd, "--- No failed test results found---\n");
}
- ast_cli(a->fd, "%d Test(s) Executed %d Passed %d Failed\n", last_results.count, last_results.passed, last_results.failed);
+ ast_cli(a->fd, "%d Test(s) Failed\n", failed);
default:
return NULL;
}
More information about the asterisk-commits
mailing list