diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-12-21 18:16:16 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-12-28 17:34:22 +0300 |
commit | 87392531922fa91f05672eb4806735745b195588 (patch) | |
tree | c08f9a25d7062e39ad16d85021533ef5b1e68a47 /tests/repository-location/driver.cxx | |
parent | a54a89072f6cfb6df2dcfbe4c34001656757e9e1 (diff) |
Add support for git repository locations
Diffstat (limited to 'tests/repository-location/driver.cxx')
-rw-r--r-- | tests/repository-location/driver.cxx | 1156 |
1 files changed, 626 insertions, 530 deletions
diff --git a/tests/repository-location/driver.cxx b/tests/repository-location/driver.cxx index a12adad..0f7cfb1 100644 --- a/tests/repository-location/driver.cxx +++ b/tests/repository-location/driver.cxx @@ -6,10 +6,8 @@ #include <cassert> #include <sstream> #include <iostream> -#include <exception> -#include <stdexcept> // invalid_argument +#include <stdexcept> // invalid_argument, logic_error -#include <libbutl/utility.mxx> // operator<<(ostream, exception) #include <libbutl/optional.mxx> #include <libbutl/manifest-parser.mxx> @@ -22,12 +20,30 @@ namespace bpkg { using butl::optional; - static bool - bad_location (const string& l) + inline static repository_location + loc () + { + return repository_location (); + } + + inline static repository_location + loc (const string& l, repository_type t = repository_type::bpkg) + { + return repository_location (repository_url (l), t); + } + + inline static repository_location + loc (const string& l, const repository_location& b) + { + return repository_location (repository_url (l), b); + } + + inline static bool + bad_loc (const string& l, repository_type t = repository_type::bpkg) { try { - repository_location bl (l); + repository_location bl (repository_url (l), t); return false; } catch (const invalid_argument&) @@ -36,12 +52,12 @@ namespace bpkg } } - static bool - bad_location (const string& l, const repository_location& b) + inline static bool + bad_loc (const string& l, const repository_location& b) { try { - repository_location bl (l, b); + repository_location bl (repository_url (l), b); return false; } catch (const invalid_argument&) @@ -62,7 +78,7 @@ namespace bpkg return *u; } - static bool + inline static bool bad_url (const string& l, const repository_location& r) { try @@ -82,7 +98,7 @@ namespace bpkg int main (int argc, char* argv[]) { - using protocol = repository_location::protocol; + using proto = repository_protocol; if (argc != 1) { @@ -90,553 +106,633 @@ namespace bpkg return 1; } - try - { - // Test invalid locations. - // - // Invalid host. - // - assert (bad_location ("http:///aa/bb")); - assert (bad_location ("http://1/aa/bb")); - assert (bad_location ("http:///1/aa/bb")); - assert (bad_location ("http://1a/aa/bb")); - assert (bad_location ("http://a..a/aa/bb")); - assert (bad_location ("http://.a.a/aa/bb")); - assert (bad_location ("http://a.a./aa/bb")); - assert (bad_location ("http://a.1a/aa/bb")); - assert (bad_location ("http://a.1a.a/aa/bb")); - assert (bad_location ("http://a.-ab/aa/bb")); - assert (bad_location ("http://a.-ab.a/aa/bb")); - assert (bad_location ("http://a.ab-/aa/bb")); - assert (bad_location ("http://a.ab-.a/aa/bb")); - assert (bad_location ("http://a.ab-:80/aa/bb")); - assert (bad_location ("http://a.ab.:80/aa/bb")); - assert (bad_location ("http://1.1.1.1.r/1/b")); - assert (bad_location ("http://www./aa/1/bb")); - - assert ( - bad_location ("http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaa.org/1/b/")); - - // Invalid port. - // - assert (bad_location ("http://a:/aa/bb")); - assert (bad_location ("http://a:1b/aa/bb")); - assert (bad_location ("http://c.ru:8a80/1/b")); - assert (bad_location ("http://c.ru:8:80/1/b")); - assert (bad_location ("http://a:0/aa/bb")); - assert (bad_location ("http://c.ru:65536/1/b")); - - // Invalid path. - // - assert ( - bad_location ("", - repository_location ( - "http://stable.cppget.org/1/misc"))); - - assert (bad_location ("1")); - assert (bad_location ("1/")); - assert (bad_location ("1/..")); - assert (bad_location ("bbb")); - assert (bad_location ("aaa/bbb")); - assert (bad_location ("http://aa")); - assert (bad_location ("https://aa")); - assert (bad_location ("http://aa/")); - assert (bad_location ("http://aa/b/..")); - assert (bad_location ("http://aa/.")); - assert (bad_location ("http://aa/bb")); - assert (bad_location ("http://a.com/../c/1/aa")); - assert (bad_location ("http://a.com/a/b/../../../c/1/aa")); + // Test invalid locations. + // + // Invalid host. + // + assert (bad_loc ("http:///aa/1/bb")); + assert (bad_loc ("http:///1/aa/bb")); + assert (bad_loc ("http://www./aa/1/bb")); + assert (bad_loc ("http://b|2.org/aa/1/bb")); + assert (bad_loc ("file://abc/")); + + // Invalid port. + // + assert (bad_loc ("http://a:/aa/bb")); + assert (bad_loc ("http://a:1b/aa/bb")); + assert (bad_loc ("http://c.ru:8a80/1/b")); + assert (bad_loc ("http://c.ru:8:80/1/b")); + assert (bad_loc ("http://a:0/aa/bb")); + assert (bad_loc ("http://c.ru:65536/1/b")); + + // Invalid path. + // + assert (bad_loc ("", loc ("http://stable.cppget.org/1/misc"))); + assert (bad_loc ("1")); + assert (bad_loc ("1/")); + assert (bad_loc ("1/..")); + assert (bad_loc ("bbb")); + assert (bad_loc ("aaa/bbb")); + assert (bad_loc ("http://")); + assert (bad_loc ("http://aa")); + assert (bad_loc ("https://aa")); + assert (bad_loc ("http://aa/")); + assert (bad_loc ("http://aa/b/..")); + assert (bad_loc ("http://aa/.")); + assert (bad_loc ("http://aa/bb")); + assert (bad_loc ("http://a.com/../c/1/aa")); + assert (bad_loc ("http://a.com/a/b/../../../c/1/aa")); + assert (bad_loc ("file://")); #ifndef _WIN32 - assert (bad_location ("/aaa/bbb")); + assert (bad_loc ("/aaa/bbb")); #else - assert (bad_location ("c:\\aaa\\bbb")); + assert (bad_loc ("c:\\aaa\\bbb")); #endif - // Invalid version. - // - assert (bad_location ("3/aaa/bbb")); + // No URL fragment. + // +#ifndef _WIN32 + assert (bad_loc ("file://localhost/", repository_type::git)); +#else + assert (bad_loc ("file://localhost/c:/", repository_type::git)); +#endif - // Invalid prerequisite repository location. - // - assert (bad_location ("a/c/1/bb")); + // Invalid version. + // + assert (bad_loc ("3/aaa/bbb")); - assert (bad_location ("a/c/1/bb", - repository_location ("./var/1/stable", - repository_location ()))); + // Invalid prerequisite repository location. + // + assert (bad_loc ("a/c/1/bb")); - assert (bad_location ("../../../1/math", - repository_location ( - "http://stable.cppget.org/1/misc"))); + assert (bad_loc ("a/c/1/bb", loc ("./var/1/stable", loc ()))); + assert (bad_loc ("../../../1/math", + loc ("http://stable.cppget.org/1/misc"))); - assert (bad_location ("../..", - repository_location ( - "http://stable.cppget.org/1/misc"))); + assert (bad_loc ("../..", loc ("http://stable.cppget.org/1/misc"))); - // Invalid web interface URL. - // - assert (bad_url (".a/..", - repository_location ( - "http://stable.cppget.org/1/misc"))); + assert (bad_loc ("http:/abc")); + assert (bad_loc ("http:///abc")); + assert (bad_loc ("http://1.1.1.1")); + assert (bad_loc ("http://[123]")); - assert (bad_url ("../a/..", - repository_location ( - "http://stable.cppget.org/1/misc"))); - - assert (bad_url ("../.a", - repository_location ( - "http://stable.cppget.org/1/misc"))); #ifndef _WIN32 - assert (bad_url ("../../..", - repository_location ( - "/var/1/misc"))); - - assert (bad_url ("../../..", - repository_location ( - "/var/pkg/1/misc"))); + assert (bad_loc ("file:////abc", repository_type::git)); + assert (bad_loc ("zzz:/abc", repository_type::git)); #else - assert (bad_url ("..\\..\\..", - repository_location ( - "c:\\var\\1\\misc"))); + assert (bad_loc ("file:/abc", repository_type::git)); +#endif - assert (bad_url ("..\\..\\..", - repository_location ( - "c:\\var\\pkg\\1\\misc"))); + // Invalid web interface URL. + // + assert (bad_url (".a/..", loc ("http://stable.cppget.org/1/misc"))); + assert (bad_url ("../a/..", loc ("http://stable.cppget.org/1/misc"))); + assert (bad_url ("../.a", loc ("http://stable.cppget.org/1/misc"))); +#ifndef _WIN32 + assert (bad_url ("../../..", loc ("/var/1/misc"))); + assert (bad_url ("../../..", loc ("/var/pkg/1/misc"))); +#else + assert (bad_url ("..\\..\\..", loc ("c:\\var\\1\\misc"))); + assert (bad_url ("..\\..\\..", loc ("c:\\var\\pkg\\1\\misc"))); #endif - assert (bad_url ("../../..", repository_location ())); + assert (bad_url ("../../..", loc ())); + + assert (bad_url ("../../../../..", + loc ("http://pkg.stable.cppget.org/foo/pkg/1/misc"))); - assert (bad_url ("../../../../..", - repository_location ( - "http://pkg.stable.cppget.org/foo/pkg/1/misc"))); + assert (bad_url ("../../../../../abc", + loc ("http://stable.cppget.org/foo/1/misc"))); - assert (bad_url ("../../../../../abc", - repository_location ( - "http://stable.cppget.org/foo/1/misc"))); + // Test valid locations. + // + { + repository_location l (loc ("")); + assert (l.string ().empty ()); + assert (l.canonical_name ().empty ()); + } + { + repository_location l (loc ("1/aa/bb", loc ())); + assert (l.string () == "1/aa/bb"); - // Test valid locations. + // Relative locations have no canonical name. // - { - repository_location l (""); - assert (l.string ().empty ()); - assert (l.canonical_name ().empty ()); - } - { - repository_location l ("1/aa/bb", repository_location ()); - assert (l.string () == "1/aa/bb"); - - // Relative locations have no canonical name. - // - assert (l.canonical_name ().empty ()); - } - { - repository_location l ("bpkg/1/aa/bb", repository_location ()); - assert (l.string () == "bpkg/1/aa/bb"); - assert (l.canonical_name ().empty ()); - } - { - repository_location l ("b/pkg/1/aa/bb", repository_location ()); - assert (l.string () == "b/pkg/1/aa/bb"); - assert (l.canonical_name ().empty ()); - } - { - repository_location l ("aa/..", repository_location ()); - assert (l.string () == "."); - assert (l.canonical_name ().empty ()); - } + assert (l.canonical_name ().empty ()); + } + { + repository_location l (loc ("bpkg/1/aa/bb", loc ())); + assert (l.string () == "bpkg/1/aa/bb"); + assert (l.canonical_name ().empty ()); + } + { + repository_location l (loc ("b/pkg/1/aa/bb", loc ())); + assert (l.string () == "b/pkg/1/aa/bb"); + assert (l.canonical_name ().empty ()); + } + { + repository_location l (loc ("aa/..", loc ())); + assert (l.string () == "."); + assert (l.canonical_name ().empty ()); + } + #ifndef _WIN32 - { - repository_location l ("/1/aa/bb", repository_location ()); - assert (l.string () == "/1/aa/bb"); - assert (l.canonical_name () == "/aa/bb"); - } - { - repository_location l ("/pkg/1/aa/bb", repository_location ()); - assert (l.string () == "/pkg/1/aa/bb"); - assert (l.canonical_name () == "aa/bb"); - } - { - repository_location l ("/var/bpkg/1", repository_location ()); - assert (l.string () == "/var/bpkg/1"); - assert (l.canonical_name () == "/var/bpkg"); - } - { - repository_location l ("/1", repository_location ()); - assert (l.string () == "/1"); - assert (l.canonical_name () == "/"); - } - { - repository_location l ("/var/pkg/1/example.org/math/testing", - repository_location ()); - assert (l.string () == "/var/pkg/1/example.org/math/testing"); - assert (l.canonical_name () == "example.org/math/testing"); - } - { - repository_location l ("/var/pkg/example.org/1/math/testing", - repository_location ()); - assert (l.string () == "/var/pkg/example.org/1/math/testing"); - assert (l.canonical_name () == "/var/pkg/example.org/math/testing"); - } - { - repository_location l ("/a/b/../c/1/aa/../bb", repository_location ()); - assert (l.string () == "/a/c/1/bb"); - assert (l.canonical_name () == "/a/c/bb"); - } - { - repository_location l ("/a/b/../c/pkg/1/aa/../bb", - repository_location ()); - assert (l.string () == "/a/c/pkg/1/bb"); - assert (l.canonical_name () == "bb"); - } + { + repository_location l (loc ("/1/aa/bb", loc ())); + assert (l.string () == "/1/aa/bb"); + assert (l.canonical_name () == "/aa/bb"); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("/pkg/1/aa/bb", loc ())); + assert (l.string () == "/pkg/1/aa/bb"); + assert (l.canonical_name () == "aa/bb"); + } + { + repository_location l (loc ("/var/bpkg/1", loc ())); + assert (l.string () == "/var/bpkg/1"); + assert (l.canonical_name () == "/var/bpkg"); + } + { + repository_location l (loc ("/1", loc ())); + assert (l.string () == "/1"); + assert (l.canonical_name () == "/"); + } + { + repository_location l (loc ("/var/pkg/1/example.org/math/testing", + loc ())); + assert (l.string () == "/var/pkg/1/example.org/math/testing"); + assert (l.canonical_name () == "example.org/math/testing"); + } + { + repository_location l (loc ("/var/pkg/example.org/1/math/testing", + loc ())); + assert (l.string () == "/var/pkg/example.org/1/math/testing"); + assert (l.canonical_name () == "/var/pkg/example.org/math/testing"); + } + { + repository_location l (loc ("/a/b/../c/1/aa/../bb", loc ())); + assert (l.string () == "/a/c/1/bb"); + assert (l.canonical_name () == "/a/c/bb"); + } + { + repository_location l (loc ("/a/b/../c/pkg/1/aa/../bb", loc ())); + assert (l.string () == "/a/c/pkg/1/bb"); + assert (l.canonical_name () == "bb"); + } + { + repository_location l (loc ("file:///repo/1/path")); + assert (l.url () == loc ("file:/repo/1/path").url ()); + assert (l.url () == loc ("/repo/1/path").url ()); + assert (l.string () == "/repo/1/path"); + assert (l.canonical_name () == "/repo/path"); + } + { + repository_location l (loc ("file:/git/repo#branch", + repository_type::git)); + assert (l.string () == "file:/git/repo#branch"); + assert (l.canonical_name () == "/git/repo"); + } + { + repository_location l (loc ("file://localhost/#master", + repository_type::git)); + assert (l.string () == "file:/#master"); + assert (l.canonical_name () == "/"); + } #else - { - repository_location l ("c:\\1\\aa\\bb", repository_location ()); - assert (l.string () == "c:\\1\\aa\\bb"); - assert (l.canonical_name () == "c:\\aa\\bb"); - } - { - repository_location l ("c:/1/aa/bb", repository_location ()); - assert (l.string () == "c:\\1\\aa\\bb"); - assert (l.canonical_name () == "c:\\aa\\bb"); - } - { - repository_location l ("c:\\pkg\\1\\aa\\bb", repository_location ()); - assert (l.string () == "c:\\pkg\\1\\aa\\bb"); - assert (l.canonical_name () == "aa/bb"); - } - { - repository_location l ("c:\\var\\pkg\\1\\example.org\\math\\testing", - repository_location ()); - assert (l.string () == "c:\\var\\pkg\\1\\example.org\\math\\testing"); - assert (l.canonical_name () == "example.org/math/testing"); - } - { - repository_location l ("c:\\var\\pkg\\example.org\\1\\math\\testing", - repository_location ()); - assert (l.string () == "c:\\var\\pkg\\example.org\\1\\math\\testing"); - - assert (l.canonical_name () == - "c:\\var\\pkg\\example.org\\math\\testing"); - } - { - repository_location l ("c:/a/b/../c/1/aa/../bb", - repository_location ()); - - assert (l.string () == "c:\\a\\c\\1\\bb"); - assert (l.canonical_name () == "c:\\a\\c\\bb"); - } - { - repository_location l ("c:/a/b/../c/pkg/1/aa/../bb", - repository_location ()); - assert (l.string () == "c:\\a\\c\\pkg\\1\\bb"); - assert (l.canonical_name () == "bb"); - } + { + repository_location l (loc ("c:\\1\\aa\\bb", loc ())); + assert (l.string () == "c:\\1\\aa\\bb"); + assert (l.canonical_name () == "c:\\aa\\bb"); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("c:/1/aa/bb", loc ())); + assert (l.string () == "c:\\1\\aa\\bb"); + assert (l.canonical_name () == "c:\\aa\\bb"); + } + { + repository_location l (loc ("c:\\pkg\\1\\aa\\bb", loc ())); + assert (l.string () == "c:\\pkg\\1\\aa\\bb"); + assert (l.canonical_name () == "aa/bb"); + } + { + repository_location l (loc ("c:\\var\\pkg\\1\\example.org\\math\\tst", + loc ())); + assert (l.string () == "c:\\var\\pkg\\1\\example.org\\math\\tst"); + assert (l.canonical_name () == "example.org/math/tst"); + } + { + repository_location l (loc ("c:\\var\\pkg\\example.org\\1\\math\\tst", + loc ())); + assert (l.string () == "c:\\var\\pkg\\example.org\\1\\math\\tst"); + + assert (l.canonical_name () == "c:\\var\\pkg\\example.org\\math\\tst"); + } + { + repository_location l (loc ("c:/a/b/../c/1/aa/../bb", loc ())); + + assert (l.string () == "c:\\a\\c\\1\\bb"); + assert (l.canonical_name () == "c:\\a\\c\\bb"); + } + { + repository_location l (loc ("c:/a/b/../c/pkg/1/aa/../bb", loc ())); + assert (l.string () == "c:\\a\\c\\pkg\\1\\bb"); + assert (l.canonical_name () == "bb"); + } + { + repository_location l (loc ("file:///c:/repo/1/path")); + assert (l.url () == loc ("file:/c:/repo/1/path").url ()); + assert (l.url () == loc ("c:/repo/1/path").url ()); + assert (l.string () == "c:\\repo\\1\\path"); + assert (l.canonical_name () == "c:\\repo\\path"); + } + { + repository_location l (loc ("file:/c:/git/repo#branch", + repository_type::git)); + assert (l.string () == "file:/c:/git/repo#branch"); + assert (l.canonical_name () == "c:\\git\\repo"); + } + { + repository_location l (loc ("file://localhost/c:/#master", + repository_type::git)); + assert (l.string () == "file:/c:#master"); + assert (l.canonical_name () == "c:"); + } #endif - { - repository_location l ("../c/../c/./1/aa/../bb", - repository_location ()); - assert (l.string () == "../c/1/bb"); - assert (l.canonical_name ().empty ()); - } - { - repository_location l ("http://www.a.com:80/1/aa/bb"); - assert (l.string () == "http://www.a.com:80/1/aa/bb"); - assert (l.canonical_name () == "a.com/aa/bb"); - assert (l.proto () == protocol::http); - } - { - repository_location l ("https://www.a.com:443/1/aa/bb"); - assert (l.string () == "https://www.a.com:443/1/aa/bb"); - assert (l.canonical_name () == "a.com/aa/bb"); - assert (l.proto () == protocol::https); - } - { - repository_location l ("http://www.a.com:8080/dd/1/aa/bb"); - assert (l.string () == "http://www.a.com:8080/dd/1/aa/bb"); - assert (l.canonical_name () == "a.com:8080/dd/aa/bb"); - assert (l.proto () == protocol::http); - } - { - repository_location l ("http://www.a.com:8080/dd/pkg/1/aa/bb"); - assert (l.string () == "http://www.a.com:8080/dd/pkg/1/aa/bb"); - assert (l.canonical_name () == "a.com:8080/dd/aa/bb"); - assert (l.proto () == protocol::http); - } - { - repository_location l ("http://www.a.com:8080/bpkg/dd/1/aa/bb"); - assert (l.string () == "http://www.a.com:8080/bpkg/dd/1/aa/bb"); - assert (l.canonical_name () == "a.com:8080/bpkg/dd/aa/bb"); - assert (l.proto () == protocol::http); - } - { - repository_location l ("https://www.a.com:444/dd/1/aa/bb"); - assert (l.string () == "https://www.a.com:444/dd/1/aa/bb"); - assert (l.canonical_name () == "a.com:444/dd/aa/bb"); - assert (l.proto () == protocol::https); - } - { - repository_location l ("http://a.com/a/b/../c/1/aa/../bb"); - assert (l.string () == "http://a.com/a/c/1/bb"); - assert (l.canonical_name () == "a.com/a/c/bb"); - } - { - repository_location l ("https://a.com/a/b/../c/1/aa/../bb"); - assert (l.string () == "https://a.com/a/c/1/bb"); - assert (l.canonical_name () == "a.com/a/c/bb"); - } - { - repository_location l ("http://www.CPPget.org/qw/1/a/b/"); - assert (l.string () == "http://www.cppget.org/qw/1/a/b"); - assert (l.canonical_name () == "cppget.org/qw/a/b"); - } - { - repository_location l ("http://pkg.CPPget.org/qw/1/a/b/"); - assert (l.string () == "http://pkg.cppget.org/qw/1/a/b"); - assert (l.canonical_name () == "cppget.org/qw/a/b"); - } - { - repository_location l ("http://bpkg.CPPget.org/qw/1/a/b/"); - assert (l.string () == "http://bpkg.cppget.org/qw/1/a/b"); - assert (l.canonical_name () == "cppget.org/qw/a/b"); - } - { - repository_location l ("http://abc.cppget.org/qw/1/a/b/"); - assert (l.string () == "http://abc.cppget.org/qw/1/a/b"); - assert (l.canonical_name () == "abc.cppget.org/qw/a/b"); - } - { - repository_location l ("http://pkg.www.cppget.org/qw/1/a/b/"); - assert (l.string () == "http://pkg.www.cppget.org/qw/1/a/b"); - assert (l.canonical_name () == "www.cppget.org/qw/a/b"); - } - { - repository_location l ("http://bpkg.www.cppget.org/qw/1/a/b/"); - assert (l.string () == "http://bpkg.www.cppget.org/qw/1/a/b"); - assert (l.canonical_name () == "www.cppget.org/qw/a/b"); - } - { - repository_location l ("http://cppget.org/qw//1/a//b/"); - assert (l.string () == "http://cppget.org/qw/1/a/b"); - assert (l.canonical_name () == "cppget.org/qw/a/b"); - } - { - repository_location l ("http://stable.cppget.org/1/"); - assert (l.canonical_name () == "stable.cppget.org"); - } - { - repository_location l1 ("http://stable.cppget.org/1/misc"); - repository_location l2 ("../../1/math", l1); - assert (l2.string () == "http://stable.cppget.org/1/math"); - assert (l2.canonical_name () == "stable.cppget.org/math"); - } - { - repository_location l1 ("http://stable.cppget.org/1/misc"); - repository_location l2 ("../../pkg/1/math", l1); - assert (l2.string () == "http://stable.cppget.org/pkg/1/math"); - assert (l2.canonical_name () == "stable.cppget.org/math"); - } - { - repository_location l1 ("https://stable.cppget.org/1/misc"); - repository_location l2 ("../../1/math", l1); - assert (l2.string () == "https://stable.cppget.org/1/math"); - assert (l2.canonical_name () == "stable.cppget.org/math"); - } - { - repository_location l1 ("http://stable.cppget.org/1/misc"); - repository_location l2 ("../math", l1); - assert (l2.string () == "http://stable.cppget.org/1/math"); - assert (l2.canonical_name () == "stable.cppget.org/math"); - } - { - repository_location l1 ("http://stable.cppget.org/1/misc"); - repository_location l2 ("math/..", l1); - assert (l2.string () == "http://stable.cppget.org/1/misc"); - assert (l2.canonical_name () == "stable.cppget.org/misc"); - } - { - repository_location l1 ("http://stable.cppget.org/1/misc"); - repository_location l2 (".", l1); - assert (l2.string () == "http://stable.cppget.org/1/misc"); - assert (l2.canonical_name () == "stable.cppget.org/misc"); - } - { - repository_location l1 ("http://www.stable.cppget.org:8080/1"); - repository_location l2 ("../1/math", l1); - assert (l2.string () == "http://www.stable.cppget.org:8080/1/math"); - assert (l2.canonical_name () == "stable.cppget.org:8080/math"); - assert (l2.proto () == protocol::http); - } - { - repository_location l1 ("https://www.stable.cppget.org:444/1"); - repository_location l2 ("../1/math", l1); - assert (l2.string () == "https://www.stable.cppget.org:444/1/math"); - assert (l2.canonical_name () == "stable.cppget.org:444/math"); - assert (l2.proto () == protocol::https); - } + { + repository_location l (loc ("../c/../c/./1/aa/../bb", loc ())); + assert (l.string () == "../c/1/bb"); + assert (l.canonical_name ().empty ()); + } + { + repository_location l (loc ("http://www.a.com:80/1/aa/bb")); + assert (l.string () == "http://www.a.com:80/1/aa/bb"); + assert (l.canonical_name () == "a.com/aa/bb"); + assert (l.proto () == proto::http); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("https://www.a.com:443/1/aa/bb")); + assert (l.string () == "https://www.a.com:443/1/aa/bb"); + assert (l.canonical_name () == "a.com/aa/bb"); + assert (l.proto () == proto::https); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("http://www.a.com:8080/dd/1/aa/bb")); + assert (l.string () == "http://www.a.com:8080/dd/1/aa/bb"); + assert (l.canonical_name () == "a.com:8080/dd/aa/bb"); + assert (l.proto () == proto::http); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("http://www.a.com:8080/dd/pkg/1/aa/bb")); + assert (l.string () == "http://www.a.com:8080/dd/pkg/1/aa/bb"); + assert (l.canonical_name () == "a.com:8080/dd/aa/bb"); + assert (l.proto () == proto::http); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("http://www.a.com:8080/bpkg/dd/1/aa/bb")); + assert (l.string () == "http://www.a.com:8080/bpkg/dd/1/aa/bb"); + assert (l.canonical_name () == "a.com:8080/bpkg/dd/aa/bb"); + assert (l.proto () == proto::http); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("https://www.a.com:444/dd/1/aa/bb")); + assert (l.string () == "https://www.a.com:444/dd/1/aa/bb"); + assert (l.canonical_name () == "a.com:444/dd/aa/bb"); + assert (l.proto () == proto::https); + assert (l.type () == repository_type::bpkg); + } + { + repository_location l (loc ("git://github.com/test#master", + repository_type::git)); + assert (l.string () == "git://github.com/test#master"); + assert (l.canonical_name () == "github.com/test"); + assert (l.proto () == proto::git); + assert (l.type () == repository_type::git); + } + { + repository_location l (loc ("http://github.com/test.git#master", + repository_type::git)); + assert (l.string () == "http://github.com/test.git#master"); + assert (l.canonical_name () == "github.com/test"); + assert (l.proto () == proto::http); + } + { + repository_location l (loc ("https://github.com/test.git#master", + repository_type::git)); + assert (l.string () == "https://github.com/test.git#master"); + assert (l.canonical_name () == "github.com/test"); + assert (l.proto () == proto::https); + assert (l.type () == repository_type::git); + } + { + repository_location l (loc ("http://git.example.com#master", + repository_type::git)); + assert (l.string () == "http://git.example.com/#master"); + assert (l.canonical_name () == "example.com"); + } + { + repository_location l (loc ("http://a.com/a/b/../c/1/aa/../bb")); + assert (l.string () == "http://a.com/a/c/1/bb"); + assert (l.canonical_name () == "a.com/a/c/bb"); + } + { + repository_location l (loc ("https://a.com/a/b/../c/1/aa/../bb")); + assert (l.string () == "https://a.com/a/c/1/bb"); + assert (l.canonical_name () == "a.com/a/c/bb"); + } + { + repository_location l (loc ("http://www.CPPget.org/qw/1/a/b/")); + assert (l.string () == "http://www.cppget.org/qw/1/a/b"); + assert (l.canonical_name () == "cppget.org/qw/a/b"); + } + { + repository_location l (loc ("http://pkg.CPPget.org/qw/1/a/b/")); + assert (l.string () == "http://pkg.cppget.org/qw/1/a/b"); + assert (l.canonical_name () == "cppget.org/qw/a/b"); + } + { + repository_location l (loc ("http://bpkg.CPPget.org/qw/1/a/b/")); + assert (l.string () == "http://bpkg.cppget.org/qw/1/a/b"); + assert (l.canonical_name () == "cppget.org/qw/a/b"); + } + { + repository_location l (loc ("http://abc.cppget.org/qw/1/a/b/")); + assert (l.string () == "http://abc.cppget.org/qw/1/a/b"); + assert (l.canonical_name () == "abc.cppget.org/qw/a/b"); + } + { + repository_location l (loc ("http://pkg.www.cppget.org/qw/1/a/b/")); + assert (l.string () == "http://pkg.www.cppget.org/qw/1/a/b"); + assert (l.canonical_name () == "www.cppget.org/qw/a/b"); + } + { + repository_location l (loc ("http://bpkg.www.cppget.org/qw/1/a/b/")); + assert (l.string () == "http://bpkg.www.cppget.org/qw/1/a/b"); + assert (l.canonical_name () == "www.cppget.org/qw/a/b"); + } + { + repository_location l (loc ("https://git.github.com/test.git#master", + repository_type::git)); + assert (l.string () == "https://git.github.com/test.git#master"); + assert (l.canonical_name () == "github.com/test"); + } + { + repository_location l (loc ("https://scm.github.com/test.git#master", + repository_type::git)); + assert (l.string () == "https://scm.github.com/test.git#master"); + assert (l.canonical_name () == "github.com/test"); + } + { + repository_location l (loc ("https://www.github.com/test.git#master", + repository_type::git)); + assert (l.string () == "https://www.github.com/test.git#master"); + assert (l.canonical_name () == "github.com/test"); + } + { + repository_location l (loc ("http://cppget.org/qw//1/a//b/")); + assert (l.string () == "http://cppget.org/qw/1/a/b"); + assert (l.canonical_name () == "cppget.org/qw/a/b"); + } + { + repository_location l (loc ("http://stable.cppget.org/1/")); + assert (l.canonical_name () == "stable.cppget.org"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/misc")); + repository_location l2 (loc ("../../1/math", l1)); + assert (l2.string () == "http://stable.cppget.org/1/math"); + assert (l2.canonical_name () == "stable.cppget.org/math"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/misc")); + repository_location l2 (loc ("../../pkg/1/math", l1)); + assert (l2.string () == "http://stable.cppget.org/pkg/1/math"); + assert (l2.canonical_name () == "stable.cppget.org/math"); + } + { + repository_location l1 (loc ("https://stable.cppget.org/1/misc")); + repository_location l2 (loc ("../../1/math", l1)); + assert (l2.string () == "https://stable.cppget.org/1/math"); + assert (l2.canonical_name () == "stable.cppget.org/math"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/misc")); + repository_location l2 (loc ("../math", l1)); + assert (l2.string () == "http://stable.cppget.org/1/math"); + assert (l2.canonical_name () == "stable.cppget.org/math"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/misc")); + repository_location l2 (loc ("math/..", l1)); + assert (l2.string () == "http://stable.cppget.org/1/misc"); + assert (l2.canonical_name () == "stable.cppget.org/misc"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/misc")); + repository_location l2 (loc (".", l1)); + assert (l2.string () == "http://stable.cppget.org/1/misc"); + assert (l2.canonical_name () == "stable.cppget.org/misc"); + } + { + repository_location l1 (loc ("http://www.stable.cppget.org:8080/1")); + + repository_location l2 (loc ("../1/math", l1)); + assert (l2.string () == "http://www.stable.cppget.org:8080/1/math"); + assert (l2.canonical_name () == "stable.cppget.org:8080/math"); + assert (l2.proto () == proto::http); + } + { + repository_location l1 (loc ("https://www.stable.cppget.org:444/1")); + repository_location l2 (loc ("../1/math", l1)); + assert (l2.string () == "https://www.stable.cppget.org:444/1/math"); + assert (l2.canonical_name () == "stable.cppget.org:444/math"); + assert (l2.proto () == proto::https); + } #ifndef _WIN32 - { - repository_location l1 ("/var/r1/1/misc"); - repository_location l2 ("../../../r2/1/math", l1); - assert (l2.string () == "/var/r2/1/math"); - assert (l2.canonical_name () == "/var/r2/math"); - } - { - repository_location l1 ("/var/1/misc"); - repository_location l2 ("../math", l1); - assert (l2.string () == "/var/1/math"); - assert (l2.canonical_name () == "/var/math"); - } - { - repository_location l1 ("/var/1/stable"); - repository_location l2 ("/var/1/test", l1); - assert (l2.string () == "/var/1/test"); - assert (l2.canonical_name () == "/var/test"); - } - { - repository_location l1 ("http://stable.cppget.org/1/misc"); - repository_location l2 ("/var/1/test", l1); - assert (l2.string () == "/var/1/test"); - assert (l2.canonical_name () == "/var/test"); - } - { - repository_location l1 ("/var/1/stable"); - repository_location l2 ("/var/1/stable", repository_location ()); - assert (l1.string () == l2.string ()); - assert (l1.canonical_name () == l2.canonical_name ()); - } + { + repository_location l1 (loc ("/var/r1/1/misc")); + repository_location l2 (loc ("../../../r2/1/math", l1)); + assert (l2.string () == "/var/r2/1/math"); + assert (l2.canonical_name () == "/var/r2/math"); + } + { + repository_location l1 (loc ("/var/1/misc")); + repository_location l2 (loc ("../math", l1)); + assert (l2.string () == "/var/1/math"); + assert (l2.canonical_name () == "/var/math"); + } + { + repository_location l1 (loc ("/var/1/stable")); + repository_location l2 (loc ("/var/1/test", l1)); + assert (l2.string () == "/var/1/test"); + assert (l2.canonical_name () == "/var/test"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/misc")); + repository_location l2 (loc ("/var/1/test", l1)); + assert (l2.string () == "/var/1/test"); + assert (l2.canonical_name () == "/var/test"); + } + { + repository_location l1 (loc ("/var/1/stable")); + repository_location l2 (loc ("/var/1/stable", loc ())); + assert (l1.string () == l2.string ()); + assert (l1.canonical_name () == l2.canonical_name ()); + } #else - { - repository_location l1 ("c:/var/r1/1/misc"); - repository_location l2 ("../../../r2/1/math", l1); - assert (l2.string () == "c:\\var\\r2\\1\\math"); - assert (l2.canonical_name () == "c:\\var\\r2\\math"); - } - { - repository_location l1 ("c:/var/1/misc"); - repository_location l2 ("../math", l1); - assert (l2.string () == "c:\\var\\1\\math"); - assert (l2.canonical_name () == "c:\\var\\math"); - } - { - repository_location l1 ("c:/var/1/stable"); - repository_location l2 ("c:\\var\\1\\test", l1); - assert (l2.string () == "c:\\var\\1\\test"); - assert (l2.canonical_name () == "c:\\var\\test"); - } - { - repository_location l1 ("http://stable.cppget.org/1/misc"); - repository_location l2 ("c:/var/1/test", l1); - assert (l2.string () == "c:\\var\\1\\test"); - assert (l2.canonical_name () == "c:\\var\\test"); - } - { - repository_location l1 ("c:/var/1/stable"); - repository_location l2 ("c:/var/1/stable", repository_location ()); - assert (l1.string () == l2.string ()); - assert (l1.canonical_name () == l2.canonical_name ()); - } + { + repository_location l1 (loc ("c:/var/r1/1/misc")); + repository_location l2 (loc ("../../../r2/1/math", l1)); + assert (l2.string () == "c:\\var\\r2\\1\\math"); + assert (l2.canonical_name () == "c:\\var\\r2\\math"); + } + { + repository_location l1 (loc ("c:/var/1/misc")); + repository_location l2 (loc ("../math", l1)); + assert (l2.string () == "c:\\var\\1\\math"); + assert (l2.canonical_name () == "c:\\var\\math"); + } + { + repository_location l1 (loc ("c:/var/1/stable")); + repository_location l2 (loc ("c:\\var\\1\\test", l1)); + assert (l2.string () == "c:\\var\\1\\test"); + assert (l2.canonical_name () == "c:\\var\\test"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/misc")); + repository_location l2 (loc ("c:/var/1/test", l1)); + assert (l2.string () == "c:\\var\\1\\test"); + assert (l2.canonical_name () == "c:\\var\\test"); + } + { + repository_location l1 (loc ("c:/var/1/stable")); + repository_location l2 (loc ("c:/var/1/stable", loc ())); + assert (l1.string () == l2.string ()); + assert (l1.canonical_name () == l2.canonical_name ()); + } #endif - { - repository_location l1 ("http://www.cppget.org/1/stable"); - repository_location l2 ("http://abc.com/1/test", l1); - assert (l2.string () == "http://abc.com/1/test"); - assert (l2.canonical_name () == "abc.com/test"); - } - { - repository_location l1 ("http://stable.cppget.org/1/"); - repository_location l2 ("http://stable.cppget.org/1/", - repository_location ()); - assert (l1.string () == l2.string ()); - assert (l1.canonical_name () == l2.canonical_name ()); - } - - // Test valid web interface locations. - // - { - repository_location l ("http://cppget.org/1/misc"); - assert (effective_url ("http://cppget.org/pkg", l) == - "http://cppget.org/pkg"); - } - { - repository_location l ("http://cppget.org/1/misc"); - assert (effective_url ("https://cppget.org/pkg", l) == - "https://cppget.org/pkg"); - } - { - repository_location l ("http://pkg.cppget.org/foo/pkg/1/misc/stable"); - assert (effective_url ("./.", l) == - "http://pkg.cppget.org/foo/pkg/misc/stable"); - } - { - repository_location l ("http://cppget.org/foo/1/misc/stable"); - assert (effective_url ("./.", l) == - "http://cppget.org/foo/misc/stable"); - } - { - repository_location l ("http://pkg.cppget.org/foo/pkg/1/misc/stable"); - assert (effective_url ("././..", l) == - "http://pkg.cppget.org/foo/pkg/misc"); - } - { - repository_location l ("http://pkg.cppget.org/foo/pkg/1/misc"); - assert (effective_url ("././../../..", l) == "http://pkg.cppget.org"); - } - { - repository_location l ("https://pkg.cppget.org/foo/pkg/1/misc/stable"); - assert (effective_url ("../.", l) == - "https://cppget.org/foo/pkg/misc/stable"); - } - { - repository_location l ("https://pkg.cppget.org/foo/pkg/1/misc/stable"); - assert (effective_url (".././..", l) == - "https://cppget.org/foo/pkg/misc"); - } - { - repository_location l ( - "https://bpkg.cppget.org/foo/bpkg/1/misc/stable"); - - assert (effective_url ("./..", l) == - "https://bpkg.cppget.org/foo/misc/stable"); - } - { - repository_location l ( - "https://bpkg.cppget.org/foo/bpkg/1/misc/stable"); - - assert (effective_url ("./../..", l) == - "https://bpkg.cppget.org/foo/misc"); - } - { - repository_location l ("http://www.cppget.org/foo/bpkg/1/misc/stable"); - assert (effective_url ("../..", l) == - "http://cppget.org/foo/misc/stable"); - } - { - repository_location l ("http://cppget.org/pkg/foo/1/misc/stable"); - assert (effective_url ("../..", l) == - "http://cppget.org/pkg/foo/misc/stable"); - } - { - repository_location l ("http://www.cppget.org/foo/bpkg/1/misc/stable"); - assert (effective_url ("../../..", l) == - "http://cppget.org/foo/misc"); - } - { - repository_location l ("http://pkg.cppget.org/foo/pkg/1/misc"); - assert (effective_url ("../../../..", l) == "http://cppget.org"); - } - { - repository_location l ("http://www.cppget.org/foo/bpkg/1/misc/stable"); - assert (effective_url ("../../../abc", l) == - "http://cppget.org/foo/misc/abc"); - } - } - catch (const exception& e) - { - cerr << e << endl; - return 1; + { + repository_location l1 (loc ("http://www.cppget.org/1/stable")); + repository_location l2 (loc ("http://abc.com/1/test", l1)); + assert (l2.string () == "http://abc.com/1/test"); + assert (l2.canonical_name () == "abc.com/test"); + } + { + repository_location l1 (loc ("http://stable.cppget.org/1/")); + repository_location l2 (loc ("http://stable.cppget.org/1/", loc ())); + assert (l1.string () == l2.string ()); + assert (l1.canonical_name () == l2.canonical_name ()); + } + + // Test valid web interface locations. + // + { + repository_location l (loc ("http://cppget.org/1/misc")); + assert (effective_url ("http://cppget.org/pkg", l) == + "http://cppget.org/pkg"); } + { + repository_location l (loc ("http://cppget.org/1/misc")); + assert (effective_url ("https://cppget.org/pkg", l) == + "https://cppget.org/pkg"); + } + { + repository_location l ( + loc ("http://pkg.cppget.org/foo/pkg/1/misc/stable")); + + assert (effective_url ("./.", l) == + "http://pkg.cppget.org/foo/pkg/misc/stable"); + } + { + repository_location l (loc ("http://cppget.org/foo/1/misc/stable")); + assert (effective_url ("./.", l) == + "http://cppget.org/foo/misc/stable"); + } + { + repository_location l ( + loc ("http://pkg.cppget.org/foo/pkg/1/misc/stable")); + + assert (effective_url ("././..", l) == + "http://pkg.cppget.org/foo/pkg/misc"); + } + { + repository_location l (loc ("http://pkg.cppget.org/foo/pkg/1/misc")); + assert (effective_url ("././../../..", l) == "http://pkg.cppget.org"); + } + { + repository_location l ( + loc ("https://pkg.cppget.org/foo/pkg/1/misc/stable")); + + assert (effective_url ("../.", l) == + "https://cppget.org/foo/pkg/misc/stable"); + } + { + repository_location l ( + loc ("https://pkg.cppget.org/foo/pkg/1/misc/stable")); + + assert (effective_url (".././..", l) == + "https://cppget.org/foo/pkg/misc"); + } + { + repository_location l ( + loc ("https://bpkg.cppget.org/foo/bpkg/1/misc/stable")); + + assert (effective_url ("./..", l) == + "https://bpkg.cppget.org/foo/misc/stable"); + } + { + repository_location l ( + loc ("https://bpkg.cppget.org/foo/bpkg/1/misc/stable")); + + assert (effective_url ("./../..", l) == + "https://bpkg.cppget.org/foo/misc"); + } + { + repository_location l ( + loc ("http://www.cppget.org/foo/bpkg/1/misc/stable")); + + assert (effective_url ("../..", l) == + "http://cppget.org/foo/misc/stable"); + } + { + repository_location l ( + loc ("http://cppget.org/pkg/foo/1/misc/stable")); + + assert (effective_url ("../..", l) == + "http://cppget.org/pkg/foo/misc/stable"); + } + { + repository_location l ( + loc ("http://www.cppget.org/foo/bpkg/1/misc/stable")); + + assert (effective_url ("../../..", l) == + "http://cppget.org/foo/misc"); + } + { + repository_location l (loc ("http://pkg.cppget.org/foo/pkg/1/misc")); + assert (effective_url ("../../../..", l) == "http://cppget.org"); + } + { + repository_location l ( + loc ("http://www.cppget.org/foo/bpkg/1/misc/stable")); + + assert (effective_url ("../../../abc", l) == + "http://cppget.org/foo/misc/abc"); + } + + // repository_url + // + assert (repository_url ("git://example.com/test.git") == + repository_url (proto::git, + repository_url::host_type ("example.com"), + dir_path ("test.git"))); return 0; } |