aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-01-06 03:24:33 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-01-09 21:44:22 +0300
commit9e2b4fd3bbc0c61bf6c84540c52869ec7d830718 (patch)
tree550c9edd5b29b164d7c8c2ac13111a9491495022 /build2/test/script
parentc5d118cde064c09a416541a7f7e76d354552b2fd (diff)
Make use of operator<<(ostream, exception)
Diffstat (limited to 'build2/test/script')
-rw-r--r--build2/test/script/builtin.cxx25
-rw-r--r--build2/test/script/parser.cxx30
-rw-r--r--build2/test/script/runner.cxx36
3 files changed, 47 insertions, 44 deletions
diff --git a/build2/test/script/builtin.cxx b/build2/test/script/builtin.cxx
index 0b99e8f..d00a8a1 100644
--- a/build2/test/script/builtin.cxx
+++ b/build2/test/script/builtin.cxx
@@ -161,7 +161,7 @@ namespace build2
else
cerr << "'" << p << "'";
- cerr << ": " << e.what () << endl;
+ cerr << ": " << e << endl;
throw failed ();
}
@@ -179,7 +179,7 @@ namespace build2
catch (const io_error& e)
{
if (cerr.good ())
- cerr << "cat: " << e.what () << endl;
+ cerr << "cat: " << e << endl;
}
catch (const failed&)
{
@@ -222,7 +222,7 @@ namespace build2
}
catch (const std::exception& e)
{
- cerr << "echo: " << e.what () << endl;
+ cerr << "echo: " << e << endl;
}
cerr.close ();
@@ -338,7 +338,7 @@ namespace build2
catch (const system_error& e)
{
cerr << "mkdir: unable to create directory '" << p << "': "
- << e.what () << endl;
+ << e << endl;
throw failed ();
}
}
@@ -355,7 +355,7 @@ namespace build2
catch (const io_error& e)
{
if (cerr.good ())
- cerr << "mkdir: " << e.what () << endl;
+ cerr << "mkdir: " << e << endl;
}
catch (const failed&)
{
@@ -478,8 +478,7 @@ namespace build2
}
catch (const system_error& e)
{
- cerr << "rm: unable to remove '" << p << "': " << e.what ()
- << endl;
+ cerr << "rm: unable to remove '" << p << "': " << e << endl;
throw failed ();
}
}
@@ -496,7 +495,7 @@ namespace build2
catch (const io_error& e)
{
if (cerr.good ())
- cerr << "rm: " << e.what () << endl;
+ cerr << "rm: " << e << endl;
}
catch (const failed&)
{
@@ -578,8 +577,8 @@ namespace build2
}
catch (const io_error& e)
{
- cerr << "touch: cannot create file '" << p << "': "
- << e.what () << endl;
+ cerr << "touch: cannot create file '" << p << "': " << e
+ << endl;
throw failed ();
}
@@ -594,8 +593,8 @@ namespace build2
}
catch (const system_error& e)
{
- cerr << "touch: cannot create/update '" << p << "': "
- << e.what () << endl;
+ cerr << "touch: cannot create/update '" << p << "': " << e
+ << endl;
throw failed ();
}
}
@@ -612,7 +611,7 @@ namespace build2
catch (const io_error& e)
{
if (cerr.good ())
- cerr << "touch: " << e.what () << endl;
+ cerr << "touch: " << e << endl;
}
catch (const failed&)
{
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx
index f545896..e5f634c 100644
--- a/build2/test/script/parser.cxx
+++ b/build2/test/script/parser.cxx
@@ -3,7 +3,7 @@
// license : MIT; see accompanying LICENSE file
#include <sstream>
-#include <cstring> // strstr(), strchr()
+#include <cstring> // strstr()
#include <build2/test/script/parser>
@@ -26,20 +26,24 @@ namespace std
// resembles the following: 'regex_error(error_badrepeat): '. So we skip it.
//
static ostream&
- operator<< (ostream& os, const regex_error& e)
+ operator<< (ostream& o, const regex_error& e)
{
const char* d (e.what ());
- if (strchr (d, ' ') != nullptr)
- {
+
#if defined(_MSC_VER) && _MSC_VER <= 1910
- const char* s (strstr (d, "): "));
- if (s != nullptr)
- d = s + 3;
+ const char* rd (strstr (d, "): "));
+ if (rd != nullptr)
+ d = rd + 3;
#endif
- os << ": " << d;
- }
- return os;
+ ostringstream os;
+ os << runtime_error (d); // Purify the description.
+
+ string s (os.str ());
+ if (s.find (' ') != string::npos)
+ o << ": " << s;
+
+ return o;
}
}
@@ -77,8 +81,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail << "unable to read testscript " << p << ": " << e.what ()
- << endf;
+ fail << "unable to read testscript " << p << ": " << e << endf;
}
}
@@ -1054,8 +1057,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (dl) << "unable to read testscript " << p << ": "
- << e.what ();
+ fail (dl) << "unable to read testscript " << p << ": " << e;
}
}
};
diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx
index cbf0de0..64c6e87 100644
--- a/build2/test/script/runner.cxx
+++ b/build2/test/script/runner.cxx
@@ -41,7 +41,7 @@ namespace build2
// executed let's add the location anyway to ease the
// troubleshooting. And let's stick to that principle down the road.
//
- fail (ll) << "unable to read " << p << ": " << e.what () << endf;
+ fail (ll) << "unable to read " << p << ": " << e << endf;
}
}
@@ -91,7 +91,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to read " << p << ": " << e.what ();
+ fail (ll) << "unable to read " << p << ": " << e;
}
}
}
@@ -151,7 +151,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to write " << opp << ": " << e.what ();
+ fail (ll) << "unable to write " << opp << ": " << e;
}
auto output_info = [&what, &ll] (diag_record& d,
@@ -203,6 +203,9 @@ namespace build2
//
// ...: Invalid data.\r\r\n
//
+ // Note that our custom operator<<(ostream&, const exception&)
+ // removes this junk.
+ //
while (!s.empty () && s.back () == '\r')
s.pop_back ();
@@ -211,7 +214,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to read " << op << ": " << e.what ();
+ fail (ll) << "unable to read " << op << ": " << e;
}
if (regex_match (ls, rd.regex.regex)) // Doesn't throw.
@@ -263,7 +266,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to write " << ep << ": " << e.what ();
+ fail (ll) << "unable to write " << ep << ": " << e;
}
// Diff utility prints the differences to stdout. But for the
@@ -293,7 +296,7 @@ namespace build2
}
catch (const process_error& e)
{
- error (ll) << "unable to execute " << pp << ": " << e.what ();
+ error (ll) << "unable to execute " << pp << ": " << e;
if (e.child ())
exit (1);
@@ -506,7 +509,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to read " << isp << ": " << e.what ();
+ fail (ll) << "unable to read " << isp << ": " << e;
}
};
@@ -521,7 +524,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to duplicate stdin: " << e.what ();
+ fail (ll) << "unable to duplicate stdin: " << e;
}
break;
@@ -556,7 +559,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to write to null device: " << e.what ();
+ fail (ll) << "unable to write to null device: " << e;
}
break;
@@ -587,7 +590,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to write " << isp << ": " << e.what ();
+ fail (ll) << "unable to write " << isp << ": " << e;
}
open_stdin ();
@@ -639,8 +642,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to duplicate " << what << ": "
- << e.what ();
+ fail (ll) << "unable to duplicate " << what << ": " << e;
}
return dfd;
@@ -658,7 +660,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to write to null device: " << e.what ();
+ fail (ll) << "unable to write to null device: " << e;
}
return -2;
@@ -699,7 +701,7 @@ namespace build2
}
catch (const io_error& e)
{
- fail (ll) << "unable to write " << p << ": " << e.what ();
+ fail (ll) << "unable to write " << p << ": " << e;
}
return fd.get ();
@@ -729,7 +731,7 @@ namespace build2
catch (const io_error& e)
{
fail (ll) << "unable to duplicate " << (mo ? "stderr" : "stdout")
- << ": " << e.what ();
+ << ": " << e;
}
}
@@ -750,7 +752,7 @@ namespace build2
catch (const system_error& e)
{
fail (ll) << "unable to execute " << c.program << " builtin: "
- << e.what ();
+ << e;
}
}
else
@@ -788,7 +790,7 @@ namespace build2
}
catch (const process_error& e)
{
- error (ll) << "unable to execute " << pp << ": " << e.what ();
+ error (ll) << "unable to execute " << pp << ": " << e;
if (e.child ())
std::exit (1);