Commit 6964bae8 authored by Roman Alifanov's avatar Roman Alifanov

Fix simulate parser for ALT format with 'replaced' field

parent a4d55307
......@@ -153,7 +153,8 @@ pub fn parse_simulate_output(output: &str) -> Result<PackageChanges> {
let mut changes = PackageChanges::default();
// Regex for statistics line: "N upgraded, N newly installed, N removed and N not upgraded."
let stats_re = Regex::new(r"(\d+)\s+upgraded,\s+(\d+)\s+newly installed,\s+(\d+)\s+removed\s+and\s+(\d+)\s+not upgraded")
// Also handles ALT format: "N upgraded, N newly installed, N replaced, N removed ..."
let stats_re = Regex::new(r"(\d+)\s+upgraded,\s+(\d+)\s+newly installed,\s+(?:(\d+)\s+replaced,\s+)?(\d+)\s+removed")
.unwrap();
// Regex for Inst lines: "Inst package [old_version] (new_version repo)" or "Inst package (new_version repo)"
......@@ -246,7 +247,7 @@ pub fn parse_simulate_output(output: &str) -> Result<PackageChanges> {
if let Some(caps) = stats_re.captures(line) {
changes.upgraded_count = caps.get(1).and_then(|m| m.as_str().parse().ok()).unwrap_or(0);
changes.installed_count = caps.get(2).and_then(|m| m.as_str().parse().ok()).unwrap_or(0);
changes.removed_count = caps.get(3).and_then(|m| m.as_str().parse().ok()).unwrap_or(0);
changes.removed_count = caps.get(4).and_then(|m| m.as_str().parse().ok()).unwrap_or(0);
current_section = "";
continue;
}
......@@ -694,6 +695,22 @@ Conf htop (3.4.1-alt1 Sisyphus)
}
#[test]
fn test_parse_simulate_with_replaced() {
let output = r#"The following packages will be upgraded:
pkg1 pkg2
The following NEW packages will be installed:
pkg3
1208 upgraded, 55 newly installed, 8 replaced, 1 removed and 5 not upgraded.
"#;
let changes = parse_simulate_output(output).unwrap();
assert_eq!(changes.upgraded_count, 1208);
assert_eq!(changes.installed_count, 55);
assert_eq!(changes.removed_count, 1);
assert_eq!(changes.upgrade.len(), 2);
assert_eq!(changes.install.len(), 1);
}
#[test]
fn test_parse_kernel_update_already_installed() {
let output = r#"Running kernel: kernel-image-6.18-6.18.3-alt1
Checking for available 6.18 kernel packages...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment