| 1 |
#include <pbcopper/library/Bundle.h> |
| 2 |
#include <pbcopper/library/Info.h> |
| 3 |
|
| 4 |
#include <ostream> |
| 5 |
#include <sstream> |
| 6 |
|
| 7 |
#include <gtest/gtest.h> |
| 8 |
|
| 9 |
using namespace PacBio; |
| 10 |
|
| 11 |
namespace LibraryTests { |
| 12 |
|
| 13 |
void PrintLibraryInfo(std::ostream& out, const Library::Info& libInfo, |
| 14 |
const std::string indent = "") |
| 15 |
{ |
| 16 |
out << indent << "Name: " << libInfo.Name << '\n' |
| 17 |
<< indent << "Release: " << libInfo.Release << '\n'; |
| 18 |
if (!libInfo.GitSha1.empty()) { |
| 19 |
out << indent << "GitSHA1: " << libInfo.GitSha1 << '\n'; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
void PrintLibraryBundle(std::ostream& out, const Library::Bundle& bundle, |
| 24 |
const std::string indent = "") |
| 25 |
{ |
| 26 |
PrintLibraryInfo(out, bundle.Library, indent); |
| 27 |
if (!bundle.Dependencies.empty()) { |
| 28 |
out << indent << "Dependencies:\n\n"; |
| 29 |
for (const auto& dep : bundle.Dependencies) { |
| 30 |
PrintLibraryBundle(out, *dep.get(), indent + " "); |
| 31 |
out << '\n'; |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
Library::Info Dep_1_Info() { return {"dep_1", "4.2", ""}; } |
| 37 |
Library::Info Dep_2_Info() { return {"dep_2", "0.3", "deadbeef"}; } |
| 38 |
|
| 39 |
Library::Bundle Lib_1_Bundle() |
| 40 |
{ |
| 41 |
Library::Bundle bundle; |
| 42 |
bundle.Library = {"library_1", "2.0", "ba5eba11"}; |
| 43 |
bundle += Library::Info{"lib_dep", "beta", ""}; |
| 44 |
bundle += Library::Info{"lib_dep2", "14.11", "dea110c8"}; |
| 45 |
return bundle; |
| 46 |
} |
| 47 |
|
| 48 |
} // namespace LibraryTests |
| 49 |
|
| 50 |
TEST(Library_Info, can_create_bundle_with_layered_dependencies) |
| 51 |
{ |
| 52 |
Library::Bundle bundle{{"my_library", "1.6.0", "release-9.0.0-43-g3f2b583"}, {}}; |
| 53 |
bundle += LibraryTests::Dep_1_Info(); |
| 54 |
bundle += LibraryTests::Dep_2_Info(); |
| 55 |
bundle += LibraryTests::Lib_1_Bundle(); |
| 56 |
|
| 57 |
std::ostringstream out; |
| 58 |
LibraryTests::PrintLibraryBundle(out, bundle); |
| 59 |
|
| 60 |
const std::string expected{R"( |
| 61 |
Name: my_library |
| 62 |
Release: 1.6.0 |
| 63 |
GitSHA1: release-9.0.0-43-g3f2b583 |
| 64 |
Dependencies: |
| 65 |
|
| 66 |
Name: dep_1 |
| 67 |
Release: 4.2 |
| 68 |
|
| 69 |
Name: dep_2 |
| 70 |
Release: 0.3 |
| 71 |
GitSHA1: deadbeef |
| 72 |
|
| 73 |
Name: library_1 |
| 74 |
Release: 2.0 |
| 75 |
GitSHA1: ba5eba11 |
| 76 |
Dependencies: |
| 77 |
|
| 78 |
Name: lib_dep |
| 79 |
Release: beta |
| 80 |
|
| 81 |
Name: lib_dep2 |
| 82 |
Release: 14.11 |
| 83 |
GitSHA1: dea110c8 |
| 84 |
|
| 85 |
|
| 86 |
)"}; |
| 87 |
EXPECT_EQ(out.str(), expected.substr(1)); |
| 88 |
} |