Skip to content

Commit

Permalink
feat: the first test case (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
clement2026 authored Aug 9, 2024
1 parent 903c12c commit 9a5e004
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 28 deletions.
41 changes: 39 additions & 2 deletions approf.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
EBBB83272C60E4D6002F2892 /* NameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBB83262C60E4D6002F2892 /* NameView.swift */; };
EBBB83292C60E673002F2892 /* NameFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBB83282C60E673002F2892 /* NameFeature.swift */; };
EBBB832B2C60EC3A002F2892 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBB832A2C60EC3A002F2892 /* Date.swift */; };
EBBC581A2C668A0F00A72918 /* TestDropFiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBC58192C668A0F00A72918 /* TestDropFiles.swift */; };
EBBC581B2C668A0F00A72918 /* Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBC58172C668A0F00A72918 /* Dummy.swift */; };
EBBC581C2C668A0F00A72918 /* b.pb in Resources */ = {isa = PBXBuildFile; fileRef = EBBC58162C668A0F00A72918 /* b.pb */; };
EBBC581D2C668A0F00A72918 /* a.pb.gz in Resources */ = {isa = PBXBuildFile; fileRef = EBBC58152C668A0F00A72918 /* a.pb.gz */; };
EBBC581F2C669A8100A72918 /* TestDropFilesUsingSwiftTesting.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBC581E2C669A8100A72918 /* TestDropFilesUsingSwiftTesting.swift */; };
EBD20FBD2C42D06300EE88D7 /* LightsOff.metal in Sources */ = {isa = PBXBuildFile; fileRef = EBD20FBC2C42D06300EE88D7 /* LightsOff.metal */; };
EBD292B42C430F8000FFB285 /* ShortcutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBD292B32C430F8000FFB285 /* ShortcutView.swift */; };
EBD292BA2C430F9700FFB285 /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = EBD292B92C430F9700FFB285 /* KeyboardShortcuts */; };
Expand Down Expand Up @@ -192,6 +197,12 @@
EBBB83262C60E4D6002F2892 /* NameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NameView.swift; sourceTree = "<group>"; };
EBBB83282C60E673002F2892 /* NameFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NameFeature.swift; sourceTree = "<group>"; };
EBBB832A2C60EC3A002F2892 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
EBBC58152C668A0F00A72918 /* a.pb.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = a.pb.gz; sourceTree = "<group>"; };
EBBC58162C668A0F00A72918 /* b.pb */ = {isa = PBXFileReference; lastKnownFileType = file; path = b.pb; sourceTree = "<group>"; };
EBBC58172C668A0F00A72918 /* Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dummy.swift; sourceTree = "<group>"; };
EBBC58192C668A0F00A72918 /* TestDropFiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDropFiles.swift; sourceTree = "<group>"; };
EBBC581E2C669A8100A72918 /* TestDropFilesUsingSwiftTesting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDropFilesUsingSwiftTesting.swift; sourceTree = "<group>"; };
EBBC58202C669B0500A72918 /* TestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = TestPlan.xctestplan; path = approfTests/TestPlan.xctestplan; sourceTree = "<group>"; };
EBD20FBC2C42D06300EE88D7 /* LightsOff.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = LightsOff.metal; sourceTree = "<group>"; };
EBD292B32C430F8000FFB285 /* ShortcutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutView.swift; sourceTree = "<group>"; };
EBD292BB2C43116400FFB285 /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -376,6 +387,9 @@
EB94443A2C42F7050050F0D1 /* approfTests */ = {
isa = PBXGroup;
children = (
EBBC58182C668A0F00A72918 /* Files */,
EBBC58192C668A0F00A72918 /* TestDropFiles.swift */,
EBBC581E2C669A8100A72918 /* TestDropFilesUsingSwiftTesting.swift */,
EB9444392C42F7050050F0D1 /* pprofTests.swift */,
);
path = approfTests;
Expand Down Expand Up @@ -409,6 +423,16 @@
path = UnderTheHood;
sourceTree = "<group>";
};
EBBC58182C668A0F00A72918 /* Files */ = {
isa = PBXGroup;
children = (
EBBC58152C668A0F00A72918 /* a.pb.gz */,
EBBC58162C668A0F00A72918 /* b.pb */,
EBBC58172C668A0F00A72918 /* Dummy.swift */,
);
path = Files;
sourceTree = "<group>";
};
EBD292B22C430E8B00FFB285 /* Process */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -464,6 +488,7 @@
EBEF3A152C3B255A0003477D = {
isa = PBXGroup;
children = (
EBBC58202C669B0500A72918 /* TestPlan.xctestplan */,
EB7D79402C65635200CCD4F3 /* .github */,
EB9444292C42F6E50050F0D1 /* approf */,
EB94443A2C42F7050050F0D1 /* approfTests */,
Expand Down Expand Up @@ -570,6 +595,7 @@
};
EBEF3A2E2C3B255B0003477D = {
CreatedOnToolsVersion = 16.0;
TestTargetID = EBEF3A1D2C3B255A0003477D;
};
EBEF3A382C3B255B0003477D = {
CreatedOnToolsVersion = 16.0;
Expand Down Expand Up @@ -619,6 +645,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EBBC581C2C668A0F00A72918 /* b.pb in Resources */,
EBBC581D2C668A0F00A72918 /* a.pb.gz in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -714,6 +742,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EBBC581A2C668A0F00A72918 /* TestDropFiles.swift in Sources */,
EBBC581B2C668A0F00A72918 /* Dummy.swift in Sources */,
EBBC581F2C669A8100A72918 /* TestDropFilesUsingSwiftTesting.swift in Sources */,
EB94443B2C42F7050050F0D1 /* pprofTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -935,32 +966,36 @@
EBEF3A472C3B255B0003477D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 46PN73H4K6;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = the.future.app.pprof.pprofTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/approf.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/approf";
};
name = Debug;
};
EBEF3A482C3B255B0003477D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 46PN73H4K6;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = the.future.app.pprof.pprofTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/approf.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/approf";
};
name = Release;
};
Expand All @@ -971,6 +1006,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 46PN73H4K6;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = the.future.app.pprof.pprofUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -987,6 +1023,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 46PN73H4K6;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = the.future.app.pprof.pprofUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
106 changes: 106 additions & 0 deletions approf.xcodeproj/xcshareddata/xcschemes/approf.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EBEF3A1D2C3B255A0003477D"
BuildableName = "approf.app"
BlueprintName = "approf"
ReferencedContainer = "container:approf.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:approfTests/TestPlan.xctestplan">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EBEF3A2E2C3B255B0003477D"
BuildableName = "approfTests.xctest"
BlueprintName = "approfTests"
ReferencedContainer = "container:approf.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EBEF3A382C3B255B0003477D"
BuildableName = "approfUITests.xctest"
BlueprintName = "approfUITests"
ReferencedContainer = "container:approf.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EBEF3A1D2C3B255A0003477D"
BuildableName = "approf.app"
BlueprintName = "approf"
ReferencedContainer = "container:approf.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EBEF3A1D2C3B255A0003477D"
BuildableName = "approf.app"
BlueprintName = "approf"
ReferencedContainer = "container:approf.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
24 changes: 16 additions & 8 deletions approf/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ struct MacOS15App: App {

var body: some Scene {
Window("approf", id: "main") {
ContentView(store: DateSource.store)
.toolbar(removing: .title)
.toolbarBackgroundVisibility(.hidden, for: .windowToolbar)
.containerBackground(asm.materialType.actualMaterial, for: .window)
.preferredColorScheme(asm.computedColorScheme)
if isTesting {
EmptyView()
} else {
ContentView(store: DateSource.store)
.toolbar(removing: .title)
.toolbarBackgroundVisibility(.hidden, for: .windowToolbar)
.containerBackground(asm.materialType.actualMaterial, for: .window)
.preferredColorScheme(asm.computedColorScheme)
}
}
.defaultWindowPlacement { _, context in
let displayBounds = context.defaultDisplay.visibleRect
Expand All @@ -34,7 +38,7 @@ struct MacOS15App: App {
CMD()
}

Settings{
Settings {
SettingsView()
.toolbar(removing: .title)
.toolbarBackgroundVisibility(.hidden, for: .windowToolbar)
Expand Down Expand Up @@ -62,8 +66,12 @@ struct MacOS14App: App {

var body: some Scene {
Window("approf", id: "main") {
ContentView(store: DateSource.store)
.preferredColorScheme(asm.computedColorScheme)
if isTesting {
EmptyView()
} else {
ContentView(store: DateSource.store)
.preferredColorScheme(asm.computedColorScheme)
}
}
.handlesExternalEvents(matching: ["*"])
.commands {
Expand Down
1 change: 1 addition & 0 deletions approf/App/AppDataSource.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ComposableArchitecture

struct DateSource{
@MainActor
static let store = Store(initialState: AppFeature.State()) {
AppFeature()
// ._printChanges()
Expand Down
2 changes: 1 addition & 1 deletion approf/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AppKit
import CoreSpotlight
import Logging

var log = Logger(label: "mac-pprof")
var log = Logger(label: "approf")

class AppDelegate: NSObject, NSApplicationDelegate {
var windowController: CustomWindowController?
Expand Down
5 changes: 4 additions & 1 deletion approf/Preview/PerviewData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import Foundation
extension UnderTheHood {
static var mock = Store(initialState:
UnderTheHood.State(basic:
Shared(PProfBasic(urls: [
Shared(PProfBasic(
uuid: UUID(),
urls: [
URL(fileURLWithPath: "/Library/Application\\ Support/Apple/ParentasdlControls/ALRHelperJobs/pprof.etcd.alloc_objects.alloc_space.inuse_objects.inuse_space.002.pb.gz"),
URL(fileURLWithPath: "/Library/Application\\ Support/Apple/ParesdfntalControls/ALRHelperJobs/pprof.etcd.alloc_objects.alloc_space.inuse_objects.inuse_space.002.pb.gz"),
URL(fileURLWithPath: "/Library/Application\\ Support/Apple/ParentalControls/ALRHelperJobs/pprof.etcd.alloc_objects.alloc_space.inuse_object3s.inuse_space.002.pb.gz"),
Expand All @@ -14,6 +16,7 @@ extension UnderTheHood {
URL(fileURLWithPath: "/Users/clement/Documents/example.txt"),
URL(fileURLWithPath: "/Users/username/Documents/example.txt")
],
createdAt: Date(),
presentation: .dft))))
{
UnderTheHood()
Expand Down
20 changes: 11 additions & 9 deletions approf/Types/PProfBasic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ struct PProfBasic: Equatable, Identifiable, Codable {
var terminalOutput: [TerminalRecord]
var finalCommandArgs: [CommandLine.CommandArg]

init(filePaths: [String], presentation: PProfPresentation = .dft, httpDetectLog: [HTTPResult] = [], terminalOutput: [TerminalRecord] = [], finalCommandArgs: [CommandLine.CommandArg] = []) {
self.id = UUID()
init(uuid: UUID, filePaths: [String], createdAt: Date, presentation: PProfPresentation = .dft, httpDetectLog: [HTTPResult] = [], terminalOutput: [TerminalRecord] = [], finalCommandArgs: [CommandLine.CommandArg] = []) {
self.id = uuid
self.name = ""
self.filePaths = filePaths
self.createdAt = Date()
self.createdAt = createdAt
self.presentation = presentation
self.httpDetectLog = httpDetectLog
self.terminalOutput = terminalOutput
self.finalCommandArgs = finalCommandArgs
}

init(urls: [URL], presentation: PProfPresentation = .dft) {
init(uuid: UUID, urls: [URL], createdAt: Date, presentation: PProfPresentation = .dft) {
let filePaths = urls.map { $0.path(percentEncoded: false) }
self.init(filePaths: filePaths, presentation: presentation)
self.init(uuid: uuid, filePaths: filePaths, createdAt: createdAt, presentation: presentation)
}

// Custom encoding
Expand Down Expand Up @@ -62,7 +62,9 @@ struct PProfBasic: Equatable, Identifiable, Codable {

extension PProfBasic {
static let mock = PProfBasic(
uuid: UUID(),
filePaths: ["/Users/mark/projects/mark/pprof"],
createdAt: Date(),
httpDetectLog: [
HTTPResult.http(code: 200, html: "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>"),
HTTPResult.http(code: 403, html: "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"),
Expand All @@ -77,8 +79,8 @@ extension PProfBasic {

extension PProfBasic {
var computedName: String {
if !name.isEmpty {
return name
if !self.name.isEmpty {
return self.name
}

guard let firstFile = self.filePaths.first else {
Expand All @@ -90,9 +92,9 @@ extension PProfBasic {
}
return firstFileName
}

func equalsSnapshot(_ snapshot: Self) -> Bool {
snapshot.filePaths == filePaths && snapshot.presentation == presentation
snapshot.filePaths == self.filePaths && snapshot.presentation == self.presentation
}
}

Expand Down
Loading

0 comments on commit 9a5e004

Please sign in to comment.