aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bdep/new.cxx18
-rw-r--r--tests/new.test50
2 files changed, 53 insertions, 15 deletions
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 1639b86..2892262 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -4,6 +4,8 @@
#include <bdep/new.hxx>
+#include <libbpkg/manifest.hxx> // validate_package_name()
+
#include <bdep/project.hxx>
#include <bdep/database.hxx>
#include <bdep/diagnostics.hxx>
@@ -57,7 +59,6 @@ namespace bdep
t == type::lib ? !t.lib_opt.no_tests () :
t == type::bare ? !t.bare_opt.no_tests () : false);
-
// Validate language options.
//
const lang& l (o.lang ());
@@ -89,7 +90,18 @@ namespace bdep
if (n.empty ())
fail << "project name argument expected";
- //@@ TODO: verify valid package name (put the helper in libbpkg).
+ // If the project type is not empty then the project name is also a package
+ // name, so let's validate it as such.
+ //
+ if (t != type::empty)
+ try
+ {
+ bpkg::validate_package_name (n);
+ }
+ catch (const invalid_argument& e)
+ {
+ fail << "invalid package name: " << e;
+ }
// Full name vs the name stem (e.g, 'hello' in 'libhello').
//
@@ -97,7 +109,7 @@ namespace bdep
// while the stem for modules, namespaces, etc.
//
string s;
- if (o.type () == type::lib)
+ if (t == type::lib)
{
if (n.compare (0, 3, "lib") != 0)
fail << "library name does not start with 'lib'";
diff --git a/tests/new.test b/tests/new.test
index 9a8c14f..99292b9 100644
--- a/tests/new.test
+++ b/tests/new.test
@@ -34,21 +34,47 @@ status += -d prj
: pkg
:
-: Test creating a library as a separate package in the project.
-:
{
- $* -t empty prj 2>>/"EOE" &prj/***;
- created new empty project prj in $~/prj/
- EOE
+ : add
+ :
+ : Test creating a library as a separate package in the project.
+ :
+ {
+ $* -t empty prj 2>>/"EOE" &prj/***;
+ created new empty project prj in $~/prj/
+ EOE
- $* --package -t lib libprj -d prj 2>>/"EOE";
- created new library package libprj in $~/prj/libprj/
- EOE
+ $* --package -t lib libprj -d prj 2>>/"EOE";
+ created new library package libprj in $~/prj/libprj/
+ EOE
- $build prj/libprj/ $cxx 2>>/~%EOE%
- %.{4}
- %ld prj/libprj/.+%{3}
- EOE
+ $build prj/libprj/ $cxx 2>>/~%EOE%
+ %.{4}
+ %ld prj/libprj/.+%{3}
+ EOE
+ }
+
+ : name
+ :
+ : Test that the package name is validated.
+ :
+ {
+ : project
+ :
+ $* x 2>'error: invalid package name: length is less than two characters' != 0
+
+ : separate
+ :
+ : Here we also test that the project name is not validated as a package.
+ :
+ {
+ $* -t empty x 2>>/"EOE" &x/***;
+ created new empty project x in $~/x/
+ EOE
+
+ $* --package y -d x 2>'error: invalid package name: length is less than two characters' != 0
+ }
+ }
}
: cfg