BrewBar/BrewBarTests/BrewBarTests.swift
maxsoch 9131c88a64 detect running apps: skip their casks on upgrade, name them in the dialog
RunningApps maps installed casks to their .app bundles via the
Caskroom copy (no brew process needed) and checks them against
NSWorkspace's running applications. Two settings in a new "Running
apps" section: auto-upgrade skips running casks (on by default —
that flow has no dialog to warn anyone), manual bulk upgrades can opt
in. The auto-upgrade filter runs before the trigger decision so a
permanently running app cannot start an upgrade cycle that would skip
it anyway. The confirmation dialog now names the apps actually
running instead of a blanket warning, and stays silent when none are.
Single-package upgrades from the Outdated menu always proceed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 17:52:56 +02:00

82 lines
2.6 KiB
Swift

@testable import BrewBar
import XCTest
final class RunningAppsTests: XCTestCase {
func testCaskroomURL_appleSilicon() {
let url = RunningApps.caskroomURL(brewPath: "/opt/homebrew/bin/brew")
XCTAssertEqual(url.path, "/opt/homebrew/Caskroom")
}
func testCaskroomURL_intel() {
let url = RunningApps.caskroomURL(brewPath: "/usr/local/bin/brew")
XCTAssertEqual(url.path, "/usr/local/Caskroom")
}
}
final class BrewParserTests: XCTestCase {
// MARK: - parseOutdatedJSON
func testParseOutdatedJSON_formulaeAndCasks() {
let output = """
{
"formulae": [
{
"name": "wget",
"installed_versions": ["1.21.3"],
"current_version": "1.21.4",
"pinned": false,
"pinned_version": null
}
],
"casks": [
{
"name": "tailscale-app",
"installed_versions": ["1.98.5"],
"current_version": "1.98.8",
"pinned": false,
"pinned_version": null
}
]
}
"""
let result = BrewParser.parseOutdatedJSON(output)
XCTAssertEqual(result.formulae.map(\.name), ["wget"])
XCTAssertEqual(result.casks.map(\.name), ["tailscale-app"])
XCTAssertEqual(result.count, 2)
XCTAssertFalse(result.isEmpty)
XCTAssertEqual(result.all.map(\.name), ["wget", "tailscale-app"])
}
func testParseOutdatedJSON_nothingOutdated() {
let result = BrewParser.parseOutdatedJSON("{\"formulae\": [], \"casks\": []}")
XCTAssertTrue(result.isEmpty)
XCTAssertEqual(result.count, 0)
}
func testParseOutdatedJSON_invalidInputReturnsNone() {
XCTAssertEqual(BrewParser.parseOutdatedJSON(""), .none)
XCTAssertEqual(BrewParser.parseOutdatedJSON("Error: some brew failure"), .none)
}
func testParseOutdatedJSON_packageLabel() {
let package = OutdatedPackage(name: "wget", installedVersions: ["1.21.3"], currentVersion: "1.21.4")
XCTAssertEqual(package.label, "wget 1.21.3 → 1.21.4")
}
// MARK: - parseVersion
func testParseVersion_picksFirstLine() {
let output = "Homebrew 4.3.0\nHomebrew/homebrew-core (git revision abc123)\n"
XCTAssertEqual(BrewParser.parseVersion(output), "Homebrew 4.3.0")
}
func testParseVersion_emptyOutput() {
XCTAssertEqual(BrewParser.parseVersion(""), "Unknown")
}
func testParseVersion_singleLine() {
XCTAssertEqual(BrewParser.parseVersion("Homebrew 4.3.0"), "Homebrew 4.3.0")
}
}