commit 751f468ae9df49d2cabc28b2201398aadb9da87a
parent 9c6e336562f64267a8c3fb5ad8492d4504c9117a
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 12 Jul 2016 23:55:47 -0400
enhance a few error messages
Diffstat:
6 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/src/source.cpp b/src/source.cpp
@@ -45,7 +45,6 @@ Package::Type Source::type() const
return Package::UnknownType;
}
-
const string &Source::file() const
{
if(!m_file.empty())
@@ -54,7 +53,7 @@ const string &Source::file() const
if(const Package *pkg = package())
return pkg->name();
else
- throw reapack_error("empty file name and no package");
+ throw reapack_error("empty source file name and no package");
}
string Source::fullName() const
diff --git a/src/version.cpp b/src/version.cpp
@@ -25,6 +25,7 @@
#include <cctype>
#include <regex>
+using boost::format;
using namespace std;
Version::Version()
@@ -67,7 +68,7 @@ void Version::parse(const string &str)
if(first >= 'a' || first >= 'z') {
if(segments.empty()) // got leading letters
- throw reapack_error("invalid version name");
+ throw reapack_error(format("invalid version name '%1%'") % str);
segments.push_back(match);
letters++;
@@ -77,13 +78,13 @@ void Version::parse(const string &str)
segments.push_back(boost::lexical_cast<Numeric>(match));
}
catch(const boost::bad_lexical_cast &) {
- throw reapack_error("version segment overflow");
+ throw reapack_error(format("version segment overflow in '%1%'") % str);
}
}
}
if(segments.empty()) // version doesn't have any numbers
- throw reapack_error("invalid version name");
+ throw reapack_error(format("invalid version name '%1%'") % str);
m_name = str;
swap(m_segments, segments);
@@ -132,11 +133,6 @@ bool Version::addSource(const Source *source)
return true;
}
-void Version::setChangelog(const string &changelog)
-{
- m_changelog = changelog;
-}
-
const Source *Version::source(const size_t index) const
{
auto it = m_sources.begin();
diff --git a/src/version.hpp b/src/version.hpp
@@ -58,7 +58,7 @@ public:
void setTime(const Time &time) { if(time) m_time = time; }
const Time &time() const { return m_time; }
- void setChangelog(const std::string &);
+ void setChangelog(const std::string &cl) { m_changelog = cl; }
const std::string &changelog() const { return m_changelog; }
bool addSource(const Source *source);
diff --git a/test/index_v1.cpp b/test/index_v1.cpp
@@ -105,7 +105,7 @@ TEST_CASE("null package version", M) {
FAIL();
}
catch(const reapack_error &e) {
- REQUIRE(string(e.what()) == "invalid version name");
+ REQUIRE(string(e.what()) == "invalid version name ''");
}
}
diff --git a/test/source.cpp b/test/source.cpp
@@ -41,7 +41,7 @@ TEST_CASE("source type from package", M) {
REQUIRE(src.type() == Package::ScriptType);
}
-TEST_CASE("empty file name and no package", M) {
+TEST_CASE("empty source file name and no package", M) {
const Source source({}, "url");
try {
@@ -49,7 +49,7 @@ TEST_CASE("empty file name and no package", M) {
FAIL();
}
catch(const reapack_error &e) {
- REQUIRE(string(e.what()) == "empty file name and no package");
+ REQUIRE(string(e.what()) == "empty source file name and no package");
}
}
@@ -84,7 +84,7 @@ TEST_CASE("full name without version", M) {
FAIL();
}
catch(const reapack_error &e) {
- REQUIRE(string(e.what()) == "empty file name and no package");
+ REQUIRE(string(e.what()) == "empty source file name and no package");
}
}
}
diff --git a/test/version.cpp b/test/version.cpp
@@ -58,26 +58,23 @@ TEST_CASE("parse valid versions", M) {
TEST_CASE("parse invalid versions", M) {
Version ver;
+ string name;
- try {
- SECTION("only letters") {
- ver.parse("hello");
- FAIL();
- }
+ SECTION("only letters")
+ name = "hello";
- SECTION("leading letter") {
- ver.parse("v1.0");
- FAIL();
- }
+ SECTION("leading letter")
+ name = "v1.0";
- SECTION("empty") {
- ver.parse("");
- FAIL();
- }
+ SECTION("empty")
+ name = {};
+ try {
+ ver.parse(name);
+ FAIL(string("'") + name + "' was accepted");
}
catch(const reapack_error &e) {
- REQUIRE(string(e.what()) == "invalid version name");
+ REQUIRE(string(e.what()) == string("invalid version name '") + name + "'");
}
REQUIRE(ver.name().empty());
@@ -121,7 +118,7 @@ TEST_CASE("version segment overflow", M) {
FAIL();
}
catch(const reapack_error &e) {
- REQUIRE(string(e.what()) == "version segment overflow");
+ REQUIRE(string(e.what()) == "version segment overflow in '9999999999999999999999'");
}
}