// file : bpkg/system-package-manager.test.hxx -*- C++ -*- // license : MIT; see accompanying LICENSE file #ifndef BPKG_SYSTEM_PACKAGE_MANAGER_TEST_HXX #define BPKG_SYSTEM_PACKAGE_MANAGER_TEST_HXX #include #include // sort() #include #include #include #include #include namespace bpkg { // Parse the manifest as if it comes from a git repository with a single // package and make an available package out of it. // inline pair, lazy_shared_ptr> make_available_from_manifest (const string& n, const string& f) { using butl::manifest_parser; using butl::manifest_parsing; try { ifdstream ifs (f); manifest_parser mp (ifs, f); package_manifest m (mp, false /* ignore_unknown */, true /* complete_values */); assert (m.name.string () == n); m.alt_naming = false; m.bootstrap_build = "project = " + n + '\n'; shared_ptr ap ( make_shared (move (m))); lazy_shared_ptr af ( make_shared ( repository_location ("https://example.com/" + n, repository_type::git))); ap->locations.push_back (package_location {af, current_dir}); return make_pair (move (ap), move (af)); } catch (const manifest_parsing& e) { fail (e.name, e.line, e.column) << e.description << endf; } catch (const io_error& e) { fail << "unable to read from " << f << ": " << e << endf; } } // Make an available stub package as if it comes from git repository with // a single package. // inline pair, lazy_shared_ptr> make_available_stub (const string& n) { shared_ptr ap ( make_shared (package_name (n))); lazy_shared_ptr af ( make_shared ( repository_location ("https://example.com/" + n, repository_type::git))); ap->locations.push_back (package_location {af, current_dir}); return make_pair (move (ap), move (af)); } // Sort available packages in the version descending order. // inline void sort_available (available_packages& aps) { using element_type = pair, lazy_shared_ptr>; std::sort (aps.begin (), aps.end (), [] (const element_type& x, const element_type& y) { return x.first->version > y.first->version; }); } } #endif // BPKG_SYSTEM_PACKAGE_MANAGER_TEST_HXX