reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 317f243800bff836142dd4ed728754e95a995a74
parent 02b46ddcab51c07b38f995a53aa19f872acf79fc
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Wed,  7 Nov 2018 21:34:37 -0500

receipt: annotate installation type and previous version

Diffstat:
Msrc/receipt.cpp | 30+++++++++++++++++++++++++++---
Msrc/receipt.hpp | 10+++++++++-
Mtest/receipt.cpp | 19+++++++++++++------
3 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/src/receipt.cpp b/src/receipt.cpp @@ -92,12 +92,23 @@ void ReceiptPage::setTitle(const char *title) } InstallTicket::InstallTicket(const Version *ver, const Registry::Entry &previous) - : m_version(ver), m_previous(previous.version) + : m_version(ver), m_previous(previous.version), m_type(deduceType(previous)) { - m_isUpdate = previous && previous.version < ver->name(); m_index = ver->package()->category()->index()->shared_from_this(); } +InstallTicket::Type InstallTicket::deduceType(const Registry::Entry &previous) const +{ + if(!previous) + return Install; + else if(previous.version < m_version->name()) + return Update; + else if(previous.version > m_version->name()) + return Downgrade; + else + return Reinstall; +} + bool InstallTicket::operator<(const InstallTicket &o) const { string l = m_version->package()->displayName(), @@ -116,7 +127,20 @@ ostream &operator<<(ostream &os, const InstallTicket &t) os << t.m_version->package()->fullName(); - if(t.m_isUpdate) { + switch(t.m_type) { + case InstallTicket::Install: + os << " [new]"; + break; + case InstallTicket::Reinstall: + os << " [reinstalled]"; + break; + case InstallTicket::Update: + case InstallTicket::Downgrade: + os << " [v" << t.m_previous.toString() << " -> v" << t.m_version->name().toString() << ']'; + break; + } + + if(t.m_type == InstallTicket::Update) { const auto &versions = t.m_version->package()->versions(); for(const Version *ver : versions | boost::adaptors::reversed) { diff --git a/src/receipt.hpp b/src/receipt.hpp @@ -110,16 +110,24 @@ private: class InstallTicket { public: + enum Type { + Install, + Reinstall, + Update, + Downgrade, + }; + InstallTicket(const Version *ver, const Registry::Entry &previousEntry); bool operator<(const InstallTicket &) const; private: friend std::ostream &operator<<(std::ostream &, const InstallTicket &); + Type deduceType(const Registry::Entry &) const; const Version *m_version; VersionName m_previous; - bool m_isUpdate; + Type m_type; IndexPtr m_index; // to keep it alive long enough }; diff --git a/test/receipt.cpp b/test/receipt.cpp @@ -179,23 +179,30 @@ TEST_CASE("format install ticket", M) { SECTION("installed from scratch") { stream << InstallTicket{v2, {}}; - REQUIRE_THAT(stream.str(), - !Contains("v1.0") && Contains("v2.0") && !Contains("v3.0")); + REQUIRE_THAT(stream.str(), Contains("[new]") && + !Contains("v1.0\r\n") && Contains("v2.0\r\n") && !Contains("v3.0\r\n")); + } + + SECTION("reinstalled") { + entry.version = VersionName("2.0"); + stream << InstallTicket{v2, entry}; + REQUIRE_THAT(stream.str(), Contains("[reinstalled]") && + !Contains("v1.0\r\n") && Contains("v2.0\r\n") && !Contains("v3.0\r\n")); } SECTION("update") { entry.version = VersionName("1.0"); stream << InstallTicket{v3, entry}; - REQUIRE_THAT(stream.str(), - !Contains("v1.0") && Contains("\r\nv3.0\r\n No changelog\r\nv2.0")); + REQUIRE_THAT(stream.str(), Contains("[v1.0 -> v3.0]") && + !Contains("v1.0\r\n") && Contains("\r\nv3.0\r\n No changelog\r\nv2.0")); REQUIRE_THAT(stream.str(), !EndsWith("\r\n")); } SECTION("downgrade") { entry.version = VersionName("3.0"); stream << InstallTicket{v1, entry}; - REQUIRE_THAT(stream.str(), - Contains("v1.0") && !Contains("v2.0") && !Contains("v3.0")); + REQUIRE_THAT(stream.str(), Contains("[v3.0 -> v1.0]") && + Contains("v1.0\r\n") && !Contains("v2.0\r\n") && !Contains("v3.0\r\n")); } }