int code;
int tc;
int retval;
+ char *path;
char *retstring = NULL;
- plan(96);
+ plan(109);
initialize_CMD_error_table();
- opts = cmd_CreateSyntax(NULL, testproc, NULL, NULL);
+ opts = cmd_CreateSyntax(NULL, testproc, NULL, 0, NULL);
cmd_AddParm(opts, "-flag", CMD_FLAG, CMD_OPTIONAL, "a flag");
cmd_AddParm(opts, "-first", CMD_SINGLE, CMD_REQUIRED, "first option");
cmd_AddParm(opts, "-second", CMD_LIST, CMD_OPTIONAL, "second option");
" ... 1st option matches");
is_string("two", retopts->parms[copt_second].items->data,
" ... 2nd option matches");
- ok(retopts->parms[copt_flag].items != NULL, " ... 3rd option matches");
+ ok(retopts->parms[copt_flag].items != NULL,
+ " ... 3rd option matches");
cmd_FreeOptions(&retopts);
cmd_FreeArgv(tv);
code = cmd_ParseLine("-help", tv, &tc, 100);
is_int(0, code, "cmd_ParseLine succeeds");
code = cmd_Parse(tc, tv, &retopts);
- is_int(CMD_USAGE, code, "cmd_Parse returns usage error with help output");
+ is_int(CMD_HELP, code, "cmd_Parse returns help indicator with help output");
ok(retopts == NULL, " ... and options is empty");
/* Check splitting with '=' */
cmd_FreeOptions(&retopts);
cmd_FreeArgv(tv);
+ /* Now, try adding a configuration file into the mix */
+ if (getenv("SOURCE") == NULL)
+ path = strdup("test1.conf");
+ else {
+ if (asprintf(&path, "%s/cmd/test1.conf", getenv("SOURCE")) < 0)
+ path = NULL;
+ }
+ if (path != NULL) {
+ cmd_SetCommandName("test");
+ code = cmd_OpenConfigFile(path);
+ is_int(0, code, "cmd_OpenConfigFile succeeds");
+ } else {
+ skip("no memory to build config file path");
+ }
+
+ code = cmd_ParseLine("-first 1", tv, &tc, 100);
+ is_int(0, code, "cmd_ParseLine succeeds");
+ code = cmd_Parse(tc, tv, &retopts);
+ is_int(0, code, "cmd_Parse succeeds when we have a config file");
+ code = cmd_OptionAsInt(retopts, copt_perhaps, &retval);
+ is_int(0, code, "cmd_OptionsAsInt succeeds");
+ is_int(10, retval, " ... and we have the correct value for perhaps");
+ code = cmd_OptionAsString(retopts, copt_sanity, &retstring);
+ is_int(0, code, "cmd_OptionAsString succeeds");
+ is_string("testing", retstring,
+ " ... and we have the correct value for sanity");
+
+ /* Check breaking up a list of options */
+ code = cmd_OptionAsList(retopts, copt_second, &list);
+ is_int(0, code, "cmd_OptionAsList succeeds");
+ checkList(list, "one", "two", "three", "four", NULL);
+
return 0;
}