Skip to content

Commit

Permalink
Update unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmxav committed Jul 9, 2024
1 parent e86e5c5 commit 2f9ab53
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Tests/GenIRTests/MultipleAppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class MultipleAppTests: XCTestCase {
let app = try XCTUnwrap(targets.first(where: { $0.name == "MultipleApp" }))
let copy = try XCTUnwrap(targets.first(where: { $0.name == "MultipleApp Copy" }))

XCTAssertEqual(app.commands.count, 3)
XCTAssertEqual(copy.commands.count, 3)
XCTAssertEqual(context.logParser.targetCommands[app.name]?.count, 3)
XCTAssertEqual(context.logParser.targetCommands[copy.name]?.count, 3)
}
}
2 changes: 1 addition & 1 deletion Tests/GenIRTests/TestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class TestContext {

/// Generate the Targets for this context
lazy var targets: [Target] = {
Target.targets(from: pifCache.targets, with: logParser.targetCommands)
pifCache.targets.map { Target(from: $0) }
}()

/// Generate the dependency graph for this context
Expand Down
8 changes: 4 additions & 4 deletions Tests/GenIRTests/UmbrellaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ final class UmbrellaTests: XCTestCase {
let scheme = "Umbrella"

let targetsToFiles = [
"Common.framework": ["OrgModel.bc"].sorted(),
"Networking.framework": ["Networking.bc"].sorted(),
"Pods_Umbrella.framework": [],
"Umbrella.framework": ["GetOrg.bc"].sorted()
"Common.framework": ["Common-dummy.bc", "Common_vers.bc", "OrgModel.bc"].sorted(),
"Networking.framework": ["Networking-dummy.bc", "Networking.bc", "Networking_vers.bc"].sorted(),
"Pods_Umbrella.framework": ["Pods-Umbrella-dummy.bc", "Pods_Umbrella_vers.bc"],
"Umbrella.framework": ["GetOrg.bc", "Umbrella_vers.bc"].sorted()
]

func testUmbrellaTargets() throws {
Expand Down
43 changes: 8 additions & 35 deletions Tests/GenIRTests/WorkspaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ final class WorkspaceTests: XCTestCase {
let scheme = "App"

static let appIRFiles: Set<String> = ["AppApp.bc", "ContentView.bc", "GeneratedAssetSymbols.bc"]
static let commonIRFiles: Set<String> = ["Model.bc"]
static let frameworkIRFiles: Set<String> = ["Framework.bc"]
static let commonIRFiles: Set<String> = ["Model.bc", "Common_vers.bc"]
static let frameworkIRFiles: Set<String> = ["Framework.bc", "Framework_vers.bc"]
static let sfSafeSymbolsIRFiles: Set<String> = [
"NSImageExtension.bc",
"SFSymbol+1.0.bc",
Expand Down Expand Up @@ -62,45 +62,18 @@ final class WorkspaceTests: XCTestCase {
dumpDependencyGraph: false
)

// Check dependencies made it to the right place
// Check dependencies made it to the right place. All dependencies should be statically
// linked and appear under the .app directory.
let appIRPath = context.archive.appending(path: "IR/App.app/")
let commonIRPath = context.archive.appending(path: "IR/Common.framework/")
let frameworkIRPath = context.archive.appending(path: "IR/Framework.framework/")
let sfSafeSymbolsIRPath = context.archive.appending(path: "IR/SFSafeSymbols.framework/")

let appIRPathContents = try FileManager.default.contentsOfDirectory(at: appIRPath, includingPropertiesForKeys: nil)
.reduce(into: Set<String>(), { $0.insert($1.lastPathComponent) })
let commonIRPathContents = try FileManager.default.contentsOfDirectory(at: commonIRPath, includingPropertiesForKeys: nil)
.reduce(into: Set<String>(), { $0.insert($1.lastPathComponent) })
let frameworkIRPathContents = try FileManager.default.contentsOfDirectory(at: frameworkIRPath, includingPropertiesForKeys: nil)
.reduce(into: Set<String>(), { $0.insert($1.lastPathComponent) })
let sfSafeSymbolsIRPathContents = try FileManager.default.contentsOfDirectory(at: sfSafeSymbolsIRPath, includingPropertiesForKeys: nil)
.reduce(into: Set<String>(), { $0.insert($1.lastPathComponent) })

let expectedAppIRFiles = Self.appIRFiles
let expectedIRFiles = Self.appIRFiles
.union(Self.commonIRFiles)
.union(Self.frameworkIRFiles)
.union(Self.sfSafeSymbolsIRFiles)
.reduce(into: Set<String>(), { $0.insert($1) })

let expectedFrameworkIRFiles = Self.frameworkIRFiles
.union(Self.commonIRFiles)
.union(Self.sfSafeSymbolsIRFiles)
.reduce(into: Set<String>(), { $0.insert($1) })

let expectedCommonIRFiles = Self.commonIRFiles
.reduce(into: Set<String>(), { $0.insert($1) })

let expectedSFSafeSymbolsIRFiles = Self.sfSafeSymbolsIRFiles
.reduce(into: Set<String>(), { $0.insert($1) })
let appIRPathContents = try FileManager.default.contentsOfDirectory(at: appIRPath, includingPropertiesForKeys: nil)
.reduce(into: Set<String>(), { $0.insert($1.lastPathComponent) })

XCTAssertEqual(expectedAppIRFiles, appIRPathContents, "App IR expected contents didn't equal actual: \(expectedAppIRFiles.symmetricDifference(appIRPathContents))")
XCTAssertEqual(expectedFrameworkIRFiles, frameworkIRPathContents, "Framework IR expected contents didn't equal actual \(expectedFrameworkIRFiles.symmetricDifference(frameworkIRPathContents))")
XCTAssertEqual(expectedCommonIRFiles, commonIRPathContents, "Common IR expected contents didn't equal actual \(expectedCommonIRFiles.symmetricDifference(commonIRPathContents))")
XCTAssertEqual(
expectedSFSafeSymbolsIRFiles,
sfSafeSymbolsIRPathContents,
"SFSafeSymbols IR expected contents didn't equal actual \(expectedSFSafeSymbolsIRFiles.symmetricDifference(sfSafeSymbolsIRPathContents))"
)
XCTAssertEqual(expectedIRFiles, appIRPathContents, "App IR expected contents didn't equal actual: \(expectedIRFiles.symmetricDifference(appIRPathContents))")
}
}

0 comments on commit 2f9ab53

Please sign in to comment.