2026-07-06 19:17:26 +00:00
|
|
|
@testable import BrewBar
|
|
|
|
|
import XCTest
|
|
|
|
|
|
2026-07-14 15:52:56 +00:00
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-06 19:17:26 +00:00
|
|
|
final class BrewParserTests: XCTestCase {
|
2026-07-06 20:26:12 +00:00
|
|
|
// 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")
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 16:02:46 +00:00
|
|
|
func testParseOutdatedJSON_packageLabel_stripsBuildIdAfterComma() {
|
|
|
|
|
let package = OutdatedPackage(
|
|
|
|
|
name: "claude",
|
|
|
|
|
installedVersions: ["1.20185.0,5e8f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f"],
|
|
|
|
|
currentVersion: "1.20186.9,69f150a4c9316d5c8cd7b9f130ed583d15c0383e"
|
|
|
|
|
)
|
|
|
|
|
XCTAssertEqual(package.label, "claude 1.20185.0 → 1.20186.9")
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-06 19:17:26 +00:00
|
|
|
// 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")
|
|
|
|
|
}
|
|
|
|
|
}
|