From 76f9ceeafb41aa30cdeafa260cf1e42b63111610 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 24 May 2018 00:03:03 +0300 Subject: Adapt to inventing package_name type --- libbbot/manifest.cxx | 44 ++++++++++++++++++++++++++++++++++---------- libbbot/manifest.hxx | 13 +++++++------ tests/manifest/result.test | 2 +- tests/manifest/task.test | 2 +- 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/libbbot/manifest.cxx b/libbbot/manifest.cxx index 3a31f55..7da3dd4 100644 --- a/libbbot/manifest.cxx +++ b/libbbot/manifest.cxx @@ -455,10 +455,14 @@ namespace bbot if (!name.empty ()) bad_name ("task package name redefinition"); - if (v.empty ()) - bad_value ("empty task package name"); - - name = move (v); + try + { + name = package_name (move (v)); + } + catch (const invalid_argument& e) + { + bad_value (string ("invalid task package name: ") + e.what ()); + } } else if (n == "version") { @@ -584,7 +588,15 @@ namespace bbot // values are valid? // s.next ("", "1"); // Start of manifest. - s.next ("name", name); + + auto bad_value ([&s](const string& d) { + throw serialization (s.name (), d);}); + + if (name.empty ()) + bad_value ("empty task package name"); + + s.next ("name", name.string ()); + s.next ("version", version.string ()); s.next ("repository", repository.string ()); @@ -857,10 +869,14 @@ namespace bbot if (!name.empty ()) bad_name ("result package name redefinition"); - if (v.empty ()) - bad_value ("empty result package name"); - - name = move (v); + try + { + name = package_name (move (v)); + } + catch (const invalid_argument& e) + { + bad_value (string ("invalid result package name: ") + e.what ()); + } } else if (n == "version") { @@ -973,7 +989,15 @@ namespace bbot // values are valid? // s.next ("", "1"); // Start of manifest. - s.next ("name", name); + + auto bad_value ([&s](const string& d) { + throw serialization (s.name (), d);}); + + if (name.empty ()) + bad_value ("empty result package name"); + + s.next ("name", name.string ()); + s.next ("version", version.string ()); s.next ("status", to_string (status)); diff --git a/libbbot/manifest.hxx b/libbbot/manifest.hxx index fcb1056..163c75e 100644 --- a/libbbot/manifest.hxx +++ b/libbbot/manifest.hxx @@ -14,7 +14,8 @@ #include #include -#include // version, repository_location +#include // version, repository_location +#include #include #include @@ -107,8 +108,8 @@ namespace bbot public: // Package to build. // - std::string name; - bpkg::version version; + bpkg::package_name name; + bpkg::version version; bpkg::repository_location repository; // Remote or absolute. // The SHA256 repositories certificates fingerprints to trust. The special @@ -139,7 +140,7 @@ namespace bbot strings unquoted_warning_regex () const; - task_manifest (std::string nm, + task_manifest (bpkg::package_name nm, bpkg::version vr, bpkg::repository_location rl, strings tr, @@ -264,7 +265,7 @@ namespace bbot // by the worker to signal abnormal termination before being able to // obtain the package name/version. // - std::string name; + bpkg::package_name name; bpkg::version version; result_status status; @@ -275,7 +276,7 @@ namespace bbot // operation_results results; - result_manifest (std::string n, + result_manifest (bpkg::package_name n, bpkg::version v, result_status s, operation_results r) diff --git a/tests/manifest/result.test b/tests/manifest/result.test index 2735e53..54f60ed 100644 --- a/tests/manifest/result.test +++ b/tests/manifest/result.test @@ -114,7 +114,7 @@ test.options += -r { : name-empty : - $* <'stdin:2:6: error: empty result package name' == 1 + $* <'stdin:2:6: error: invalid result package name: length is less than two characters' == 1 : 1 name: EOI diff --git a/tests/manifest/task.test b/tests/manifest/task.test index c78ce19..a835918 100644 --- a/tests/manifest/task.test +++ b/tests/manifest/task.test @@ -142,7 +142,7 @@ test.options += -t { : name-empty : - $* <'stdin:2:6: error: empty task package name' == 1 + $* <'stdin:2:6: error: invalid task package name: length is less than two characters' == 1 : 1 name: EOI -- cgit v1.1