From e538ed619e3f2c0880782ab6581d2c73a3d2787d Mon Sep 17 00:00:00 2001 From: BlackAngelTV Date: Thu, 27 Aug 2026 19:29:35 +0200 Subject: [PATCH] test: add unit tests for pacman manager parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cover the pacman -Q output parser: simple lines, hyphenated names, empty lines and empty input. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- tests/pacman-manager.test.cpp | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/pacman-manager.test.cpp diff --git a/tests/pacman-manager.test.cpp b/tests/pacman-manager.test.cpp new file mode 100644 index 0000000..f8f4804 --- /dev/null +++ b/tests/pacman-manager.test.cpp @@ -0,0 +1,47 @@ +#include "pacman-manager.h" +#include +#include + +static void testParseInstalledOutput_parsesSimpleLines() { + std::string output = "firefox 128.0\nvim 9.1.0000\n"; + auto pkgs = PacmanManager::parseInstalledOutput(output); + + assert(pkgs.size() == 2); + assert(pkgs[0].name == "firefox"); + assert(pkgs[0].version == "128.0"); + assert(pkgs[0].installed); + assert(pkgs[1].name == "vim"); + assert(pkgs[1].version == "9.1.0000"); +} + +static void testParseInstalledOutput_keepsHyphensInNames() { + // Hyphenated package names must not be split on the dash (python-pip, not python) + std::string output = "python-pip 24.0-1\n"; + auto pkgs = PacmanManager::parseInstalledOutput(output); + + assert(pkgs.size() == 1); + assert(pkgs[0].name == "python-pip"); + assert(pkgs[0].version == "24.0-1"); +} + +static void testParseInstalledOutput_skipsEmptyLines() { + std::string output = "firefox 128.0\n\nvim 9.1.0000\n"; + auto pkgs = PacmanManager::parseInstalledOutput(output); + + assert(pkgs.size() == 2); +} + +static void testParseInstalledOutput_emptyInput() { + auto pkgs = PacmanManager::parseInstalledOutput(""); + assert(pkgs.empty()); +} + +int main() { + testParseInstalledOutput_parsesSimpleLines(); + testParseInstalledOutput_keepsHyphensInNames(); + testParseInstalledOutput_skipsEmptyLines(); + testParseInstalledOutput_emptyInput(); + + std::cout << "All pacman-manager tests passed." << std::endl; + return 0; +}