summaryrefslogtreecommitdiff
path: root/i/marvin/src/tester/tester.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/tester/tester.cc')
-rw-r--r--i/marvin/src/tester/tester.cc66
1 files changed, 37 insertions, 29 deletions
diff --git a/i/marvin/src/tester/tester.cc b/i/marvin/src/tester/tester.cc
index 58e62c8..2532f7b 100644
--- a/i/marvin/src/tester/tester.cc
+++ b/i/marvin/src/tester/tester.cc
@@ -30,8 +30,9 @@
#include <sstream> // std::ostringstream
/// Constructor.
-Tester::Tester (int argc, char **argv)
- : config_ (argc, argv), program_(argv[0])
+Tester::Tester (int argc, char **argv, const std::string &description)
+ : config_ (argc, argv), program_(argv[0]), description_ (description),
+ showCmd_ (false)
{
// Parse command line
getOpt (argc, argv);
@@ -42,10 +43,11 @@ Tester::Tester (int argc, char **argv)
/// - -c 'commands list'
/// - -f <file>
/// - -h : help
+/// - -l : list commands suppoted
void
Tester::getOpt (int argc, char **argv)
{
- char *optstring = "hc:f:";
+ char *optstring = "hlc:f:";
int option;
std::string strTmp;
@@ -66,17 +68,20 @@ Tester::getOpt (int argc, char **argv)
{
case 'c':
// Check commands
- strTmp = optarg;
- listOpts_.push_back (Opt(false, strTmp));
+ commands_ += optarg;
break;
case 'f':
- strTmp = optarg;
- listOpts_.push_back (Opt(true, strTmp));
+ commands_ += ";include \"";
+ commands_ += optarg;
+ commands_ += "\";";
break;
case 'h':
usage ();
std::exit (0);
break;
+ case 'l':
+ showCmd_ = true;
+ break;
case '?':
default:
usage ();
@@ -84,6 +89,11 @@ Tester::getOpt (int argc, char **argv)
break;
}
}
+ if (commands_.empty () && !showCmd_)
+ {
+ usage ();
+ std::exit (2);
+ }
}
/// Print usage to stdout.
@@ -91,17 +101,23 @@ void
Tester::usage (void) const
{
std::cout << "Usage: " << program_
- << " [-c <commands list>]"
- << " [-f <file_with_commands>]"
+ << " [-c <commands>]"
+ << " [-f <file>]"
<< std::endl;
+ if (!description_.empty ())
+ std::cout << description_ << std::endl;
+ std::cout << " -c <commands> Commands to run" << std::endl;
+ std::cout << " -f <file> File with commands" << std::endl;
+ std::cout << " -l List all known commands by "
+ << program_ << std::endl;
}
-
-/// Add a test function, Tester owns f.
-void
-Tester::add (const std::string &s, Interpreter::Func *f)
+/// Print all knwon function and role to stdout.
+void
+Tester::listCmd (void) const
{
- interpreter_.add (s, f);
+ std::cout << "Commands known by " << program_ << " :" << std::endl;
+ std::cout << interpreter_.help ();
}
/// Run commands.
@@ -110,24 +126,16 @@ Tester::run (void)
{
// Pre-run
preRun ();
- // Run
- ListOpts::const_iterator it;
- // Check all, dry run
- for (it = listOpts_.begin (); it != listOpts_.end (); it++)
+ if (showCmd_)
{
- if (it->first)
- interpreter_.interpretFile (it->second, true);
- else
- interpreter_.interpretString (it->second, true);
+ listCmd ();
+ std::exit (0);
}
+ // Check
+ interpreter_.interpretString (commands_, true);
// Run !
- for (it = listOpts_.begin (); it != listOpts_.end (); it++)
- {
- if (it->first)
- interpreter_.interpretFile (it->second, false);
- else
- interpreter_.interpretString (it->second, false);
- }
+ interpreter_.interpretString (commands_, false);
+ // Post-run
postRun ();
}