Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

6.3 KB
Raw Blame
import Foundation
@testable import Peel
@testable import PeelCore
import Testing

struct PluginTextTests {
    private func plugin(
        _ path: String, name: String, forAllUsers: Bool = false, category: Plugin.Category = .audioUnits
    ) -> Plugin {
        Plugin(
            url: URL(filePath: path, directoryHint: .isDirectory), name: name, bundleIdentifier: nil, version: nil,
            category: category, isInstalledForAllUsers: forAllUsers, size: 1, requiresPrivileges: forAllUsers,
            refusal: nil
        )
    }

    @Test func findsAPlugInByTheNameFinderShows() {
        let product = plugin("/Library/Audio/Plug-Ins/Components/Vendor Product.component", name: "Product")

        #expect(product.matches("Vendor"))
        #expect(product.matches("Product"))
    }

    @Test func tellsTheCopyForAllUsersOfAPlugInInBothLibraries() {
        let mine = plugin("/Users/org.example/Library/Audio/Plug-Ins/Components/Echo.component", name: "Echo")
        let everyones = plugin("/Library/Audio/Plug-Ins/Components/Echo.component", name: "Echo", forAllUsers: true)
        let alone = plugin("/Library/Audio/Plug-Ins/Components/Reverb.component", name: "Reverb", forAllUsers: true)

        #expect(Plugin.sayingForAllUsers([mine, everyones, alone]) == [everyones.id])
    }

    @Test func saysNothingLoadsADriverInTheHomesLibrary() {
        let inTheHome = "macOS loads plug-ins like this one only from /Library, so nothing loads this one and moving it changes nothing."
        let audio = plugin(
            "/Users/org.example/Library/Audio/Plug-Ins/HAL/Sound.driver", name: "Sound", category: .audioDrivers
        )
        let camera = plugin(
            "/Users/org.example/Library/CoreMediaIO/Plug-Ins/DAL/Camera.plugin", name: "Camera", category: .cameraPlugIns
        )
        let everyones = plugin(
            "/Library/Audio/Plug-Ins/HAL/Sound.driver", name: "Sound", forAllUsers: true, category: .audioDrivers
        )
        let midi = plugin(
            "/Users/org.example/Library/Audio/MIDI Drivers/Keys.plugin", name: "Keys", category: .midiDrivers
        )

        #expect(audio.whenMoved.map(\.key).contains(inTheHome))
        #expect(camera.whenMoved.map(\.key).contains(inTheHome))
        #expect(!everyones.whenMoved.map(\.key).contains(inTheHome))
        #expect(!midi.whenMoved.map(\.key).contains(inTheHome))
    }

    @Test func saysAMoveTakesAPlugInInLibraryFromEveryAccount() {
        let mine = plugin("/Users/org.example/Library/Audio/Plug-Ins/Components/Echo.component", name: "Echo")
        let everyones = plugin("/Library/Audio/Plug-Ins/Components/Echo.component", name: "Echo", forAllUsers: true)
        let everyAccount = String(localized: "Every account on this Mac has it, so moving it takes it from all of them.")

        #expect(mine.whenMoved.map { String(localized: $0) }.last != everyAccount)
        #expect(everyones.whenMoved.map { String(localized: $0) }.last == everyAccount)
    }

    @Test func saysMovingAPlugInNothingLoadsChangesNothing() {
        var generator = plugin(
            "/Users/org.example/Library/QuickLook/Markdown.qlgenerator", name: "Markdown", category: .quickLook
        )
        generator.noLongerLoaded = .quickLookGenerator
        var flash = plugin(
            "/Library/Internet Plug-Ins/Flash Player.plugin", name: "Flash Player", forAllUsers: true,
            category: .internetPlugIns
        )
        flash.noLongerLoaded = .internetPlugIn
        flash.staysInTheTrash = true
        let echo = plugin("/Users/org.example/Library/Audio/Plug-Ins/Components/Echo.component", name: "Echo")

        #expect(generator.whenMoved.map { String(localized: $0) } == [
            String(localized: "macOS no longer loads Quick Look generators like this one, so moving it changes nothing."),
        ])
        #expect(flash.whenMoved.map { String(localized: $0) } == [
            String(localized: "macOS and today’s browsers no longer load plug-ins like this one, so moving it changes nothing."),
            String(localized: "History can’t put it back, since Peel’s helper puts back into that folder only what is root’s alone, but you can drag it back out in Finder."),
            String(localized: "Every account on this Mac has it, so moving it takes it from all of them."),
        ])
        #expect(echo.whenMoved.map { String(localized: $0) } == [String(localized: "Apps that use it may stop working.")])
    }

    @Test func saysNothingLoadsAContextualMenuItem() {
        var menu = plugin(
            "/Library/Contextual Menu Items/Old Menu.plugin", name: "Old Menu", forAllUsers: true,
            category: .contextualMenuItems
        )
        menu.noLongerLoaded = .contextualMenuItem
        menu.staysInTheTrash = true

        #expect(menu.whenMoved.map { String(localized: $0) } == [
            String(localized: "macOS no longer loads contextual menu items like this one, so moving it changes nothing."),
            String(localized: "History can’t put it back, since Peel’s helper puts back into that folder only what is root’s alone, but you can drag it back out in Finder."),
            String(localized: "Every account on this Mac has it, so moving it takes it from all of them."),
        ])
    }

    @Test func saysWhenMacOSLoadsACameraPlugIn() {
        let camera = plugin(
            "/Library/CoreMediaIO/Plug-Ins/DAL/Lens.plugin", name: "Lens", forAllUsers: true, category: .cameraPlugIns
        )
        var stays = camera
        stays.staysInTheTrash = true
        let legacy = String(localized: "macOS loads plug-ins like this one only when legacy video device support has been restored in macOS Recovery. If it has, apps that use it may stop working.")
        let warning = String(localized: "System Settings > Privacy & Security > Camera shows a warning when that support has been restored.")
        let everyAccount = String(localized: "Every account on this Mac has it, so moving it takes it from all of them.")

        #expect(camera.whenMoved.map { String(localized: $0) } == [legacy, warning, everyAccount])
        #expect(stays.whenMoved.map { String(localized: $0) } == [
            legacy,
            warning,
            String(localized: "History can’t put it back, since Peel’s helper puts back into that folder only what is root’s alone, but you can drag it back out in Finder."),
            everyAccount,
        ])
    }
}