Commit a5b51aab authored by Davis King's avatar Davis King

- Made the regression test's main() return the number of failed tests.

- Added the -q option that lets you tell the program to not print stuff to standard out.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403366
parent ac84063f
...@@ -29,6 +29,7 @@ int main (int argc, char** argv) ...@@ -29,6 +29,7 @@ int main (int argc, char** argv)
parser.add_option("d","log debugging statements to file debug.txt."); parser.add_option("d","log debugging statements to file debug.txt.");
parser.add_option("l","Set the logging level (all, trace, debug, info, warn, error, or fatal), the default is all.",1); parser.add_option("l","Set the logging level (all, trace, debug, info, warn, error, or fatal), the default is all.",1);
parser.add_option("a","Append debugging messsages to debug.txt rather than clearning the file at program startup."); parser.add_option("a","Append debugging messsages to debug.txt rather than clearning the file at program startup.");
parser.add_option("q","Be quiet. Don't print the testing progress or results to standard out.");
unsigned long num = 1; unsigned long num = 1;
...@@ -43,7 +44,7 @@ int main (int argc, char** argv) ...@@ -43,7 +44,7 @@ int main (int argc, char** argv)
parser.parse(argc,argv); parser.parse(argc,argv);
parser.check_option_arg_range("n",1,1000000000); parser.check_option_arg_range("n",1,1000000000);
const char* singles[] = {"d","l","a","n","h","runall"}; const char* singles[] = {"d","l","a","n","h","runall","q"};
parser.check_one_time_options(singles); parser.check_one_time_options(singles);
const char* d_sub[] = {"l","a"}; const char* d_sub[] = {"l","a"};
const char* l_args[] = {"all", "trace", "debug", "info", "warn", "error", "fatal"}; const char* l_args[] = {"all", "trace", "debug", "info", "warn", "error", "fatal"};
...@@ -56,6 +57,11 @@ int main (int argc, char** argv) ...@@ -56,6 +57,11 @@ int main (int argc, char** argv)
num = string_cast<unsigned long>(parser.option("n").argument()); num = string_cast<unsigned long>(parser.option("n").argument());
} }
if (parser.option("q"))
{
be_verbose = false;
}
if (parser.option("h")) if (parser.option("h"))
{ {
cout << "Usage: test [options]\n"; cout << "Usage: test [options]\n";
...@@ -117,7 +123,9 @@ int main (int argc, char** argv) ...@@ -117,7 +123,9 @@ int main (int argc, char** argv)
if (test.num_of_args() > 0 && j == opt.count()) if (test.num_of_args() > 0 && j == opt.count())
break; break;
cout << "Running " << test.cmd_line_switch() << " " << flush; if (be_verbose)
cout << "Running " << test.cmd_line_switch() << " " << flush;
dlog << LINFO << "Running " << test.cmd_line_switch(); dlog << LINFO << "Running " << test.cmd_line_switch();
try try
{ {
...@@ -139,17 +147,22 @@ int main (int argc, char** argv) ...@@ -139,17 +147,22 @@ int main (int argc, char** argv)
<< " arguments but only 2 are supported."; << " arguments but only 2 are supported.";
break; break;
} }
cout << "\r \r"; if (be_verbose)
cout << "\r \r";
++num_of_passed_tests; ++num_of_passed_tests;
} }
catch (std::exception& e) catch (std::exception& e)
{ {
cout << "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; if (be_verbose)
cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TEST FAILED: " << test.cmd_line_switch() {
<< " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; cout << "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
cout << "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"; cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TEST FAILED: " << test.cmd_line_switch()
cout << "Failure message from test: " << e.what() << endl; << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
cout << "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n";
cout << "Failure message from test: " << e.what() << endl;
}
dlog << LERROR << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; dlog << LERROR << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
...@@ -170,18 +183,26 @@ int main (int argc, char** argv) ...@@ -170,18 +183,26 @@ int main (int argc, char** argv)
} }
else if (num_of_failed_tests == 0) else if (num_of_failed_tests == 0)
{ {
cout << "\n\nTesting Finished\n"; if (be_verbose)
cout << "All tests completed successfully\n\n"; {
cout << "\n\nTesting Finished\n";
cout << "All tests completed successfully\n\n";
}
dlog << LINFO << "All tests completed successfully"; dlog << LINFO << "All tests completed successfully";
} }
else else
{ {
cout << "\n\nTesting Finished\n"; if (be_verbose)
cout << "Number of failed tests: " << num_of_failed_tests << "\n"; {
cout << "Number of passed tests: " << num_of_passed_tests << "\n\n"; cout << "\n\nTesting Finished\n";
cout << "Number of failed tests: " << num_of_failed_tests << "\n";
cout << "Number of passed tests: " << num_of_passed_tests << "\n\n";
}
dlog << LWARN << "Number of failed tests: " << num_of_failed_tests; dlog << LWARN << "Number of failed tests: " << num_of_failed_tests;
dlog << LWARN << "Number of passed tests: " << num_of_passed_tests; dlog << LWARN << "Number of passed tests: " << num_of_passed_tests;
} }
return num_of_failed_tests;
} }
catch (exception& e) catch (exception& e)
{ {
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
namespace test namespace test
{ {
// -----------------------------------------------------------------------------
bool be_verbose = true;
// -----------------------------------------------------------------------------
static dlib::mutex spinner_mutex; static dlib::mutex spinner_mutex;
...@@ -122,19 +127,22 @@ namespace test ...@@ -122,19 +127,22 @@ namespace test
void print_spinner ( void print_spinner (
) )
{ {
using namespace std; if (be_verbose)
dlib::auto_mutex M(spinner_mutex);
static int i = 0;
cout << "\b\b";
switch (i)
{ {
case 0: cout << '|'; break; using namespace std;
case 1: cout << '/'; break; dlib::auto_mutex M(spinner_mutex);
case 2: cout << '-'; break; static int i = 0;
case 3: cout << '\\'; break; cout << "\b\b";
switch (i)
{
case 0: cout << '|'; break;
case 1: cout << '/'; break;
case 2: cout << '-'; break;
case 3: cout << '\\'; break;
}
cout << " " << flush;
i = (i+1)%4;
} }
cout << " " << flush;
i = (i+1)%4;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -47,6 +47,12 @@ namespace test ...@@ -47,6 +47,12 @@ namespace test
const char* _exp_str const char* _exp_str
); );
// -----------------------------------------------------------------------------
// This bool controls any cout statements in this program. Only print to
// standard out if we should be verbose. The default is true
extern bool be_verbose;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void print_spinner ( void print_spinner (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment