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.cc54
1 files changed, 36 insertions, 18 deletions
diff --git a/i/marvin/src/tester/tester.cc b/i/marvin/src/tester/tester.cc
index 2ded27f..58e62c8 100644
--- a/i/marvin/src/tester/tester.cc
+++ b/i/marvin/src/tester/tester.cc
@@ -27,8 +27,7 @@
#include <unistd.h> // getopt
#include <exception> // std::exception
#include <cstdlib> // std::exit
-#include <fstream> // std::ifstream
-#include <sstream> // std::stringstream
+#include <sstream> // std::ostringstream
/// Constructor.
Tester::Tester (int argc, char **argv)
@@ -40,14 +39,15 @@ Tester::Tester (int argc, char **argv)
/// Getopt command line.
/// Supported arguemnts :
-/// - -c "commands list"
+/// - -c 'commands list'
/// - -f <file>
+/// - -h : help
void
Tester::getOpt (int argc, char **argv)
{
- char *optstring = "c:f:";
+ char *optstring = "hc:f:";
int option;
- std::ifstream file;
+ std::string strTmp;
// Check number of args
if (argc < 2)
@@ -65,19 +65,17 @@ Tester::getOpt (int argc, char **argv)
switch (option)
{
case 'c':
- commands_.append (optarg);
+ // Check commands
+ strTmp = optarg;
+ listOpts_.push_back (Opt(false, strTmp));
break;
case 'f':
- file.open (optarg);
- if (file.is_open ())
- {
- std::stringstream buffer_tmp;
- buffer_tmp << file.rdbuf();
- commands_.append (buffer_tmp.str ());
- file.close ();
- }
- else
- throw std::runtime_error ("File not found : " + std::string (optarg));
+ strTmp = optarg;
+ listOpts_.push_back (Opt(true, strTmp));
+ break;
+ case 'h':
+ usage ();
+ std::exit (0);
break;
case '?':
default:
@@ -106,10 +104,30 @@ Tester::add (const std::string &s, Interpreter::Func *f)
interpreter_.add (s, f);
}
+/// Run commands.
void
Tester::run (void)
{
- // TODO called interpreter with the commands_, in check mode then in run
- // mode.
+ // Pre-run
+ preRun ();
+ // Run
+ ListOpts::const_iterator it;
+ // Check all, dry run
+ for (it = listOpts_.begin (); it != listOpts_.end (); it++)
+ {
+ if (it->first)
+ interpreter_.interpretFile (it->second, true);
+ else
+ interpreter_.interpretString (it->second, true);
+ }
+ // Run !
+ for (it = listOpts_.begin (); it != listOpts_.end (); it++)
+ {
+ if (it->first)
+ interpreter_.interpretFile (it->second, false);
+ else
+ interpreter_.interpretString (it->second, false);
+ }
+ postRun ();
}