Skip to content

Commit

Permalink
Tests: simplify some expectations (NFCI)
Browse files Browse the repository at this point in the history
These expectations and requirements are unnecessary. The expectations
are provably tautological. Simply remove them to reduce clutter and
warnings from the compiler.
  • Loading branch information
compnerd committed Feb 3, 2025
1 parent 74bc85d commit ce1349c
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 54 deletions.
1 change: 0 additions & 1 deletion Tests/SWBCorePerfTests/SerializationPerfTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ fileprivate struct SerializationPerfTests: CoreBasedTests, PerfTests {

for _ in 0..<numberOfTargets {
let sz = self.serializeMacroEvaluationScope(scope)
#expect(sz != nil)
accumulatedBytes += Float64(sz.byteString.count)
}

Expand Down
3 changes: 1 addition & 2 deletions Tests/SWBCoreTests/BuildRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ import SWBMacro
let scope = MacroEvaluationScope(table: table)

// Match the rules against the rule set.
let hAction = ruleSet.match(hFile, scope)
#expect(hAction != nil)
let _ = ruleSet.match(hFile, scope)
let cAction = ruleSet.match(cFile, scope)
#expect(cAction.action != nil)
#expect(cAction.diagnostics.isEmpty)
Expand Down
8 changes: 4 additions & 4 deletions Tests/SWBCoreTests/PIFLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1365,10 +1365,10 @@ private final class ProjectModelItemClass: ProjectModelItem {

// Check that the build files and the target dependency resolved.
#expect(appTarget!.dependencies.map { $0.guid } == [frameworkTarget!.guid])
#expect(((appTarget!.buildPhases[0] as! SourcesBuildPhase).buildFiles[0] === classOneFileRef!) != nil)
#expect(((appTarget!.buildPhases[1] as! FrameworksBuildPhase).buildFiles[0] === cocoaFwkFileRef!) != nil)
#expect(((frameworkTarget!.buildPhases[0] as! SourcesBuildPhase).buildFiles[0] === classTwoFileRef!) != nil)
#expect(((frameworkTarget!.buildPhases[1] as! FrameworksBuildPhase).buildFiles[0] === classTwoFileRef!) != nil)
#expect((appTarget!.buildPhases[0] as! SourcesBuildPhase).buildFiles[0] === classOneFileRef!)
#expect((appTarget!.buildPhases[1] as! FrameworksBuildPhase).buildFiles[0] === cocoaFwkFileRef!)
#expect((frameworkTarget!.buildPhases[0] as! SourcesBuildPhase).buildFiles[0] === classTwoFileRef!)
#expect((frameworkTarget!.buildPhases[1] as! FrameworksBuildPhase).buildFiles[0] === classTwoFileRef!)
#expect(appTarget?.productReference.target == appTarget)
#expect(frameworkTarget?.productReference.target == frameworkTarget)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SWBCoreTests/SettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4236,7 +4236,7 @@ import SWBMacro

let parameters = BuildParameters(action: .build, configuration: "Debug")
for (target, version) in expectations {
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: try #require(testWorkspace.target(for: target.guid)))
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testWorkspace.target(for: target.guid))
let effectiveSwiftVersion = settings.globalScope.evaluate(BuiltinMacros.EFFECTIVE_SWIFT_VERSION)
#expect(effectiveSwiftVersion == version)
}
Expand Down
22 changes: 2 additions & 20 deletions Tests/SWBMacroTests/MacroBasicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ import SWBMacro
let namespace = MacroNamespace(debugDescription: "test")

let firstBoolDecl = try namespace.declareBooleanMacro("SomeBooleanMacro")
#expect(firstBoolDecl != nil)
#expect(firstBoolDecl.type == .boolean)

let repeatedBoolDecl = try namespace.declareBooleanMacro("SomeBooleanMacro")
#expect(repeatedBoolDecl != nil)
#expect(repeatedBoolDecl.type == .boolean)
#expect(repeatedBoolDecl === firstBoolDecl)

var didCatchExpectedException: Bool = false
do {
let collidingStringDecl = try namespace.declareStringMacro("SomeBooleanMacro")
#expect(collidingStringDecl == nil)
}
catch {
_ = try namespace.declareStringMacro("SomeBooleanMacro")
} catch {
didCatchExpectedException = true
}
#expect(didCatchExpectedException)
Expand All @@ -48,27 +44,21 @@ import SWBMacro
let namespace = MacroNamespace(debugDescription: "test")

let booleanDecl = try namespace.declareBooleanMacro("BooleanMacro")
#expect(booleanDecl != nil)
#expect(booleanDecl.type == .boolean)

let stringDecl = try namespace.declareStringMacro("StringMacro")
#expect(stringDecl != nil)
#expect(stringDecl.type == .string)

let stringListDecl = try namespace.declareStringListMacro("StringListMacro")
#expect(stringListDecl != nil)
#expect(stringListDecl.type == .stringList)

let userDefinedDecl = try namespace.declareUserDefinedMacro("UserDefinedMacro")
#expect(userDefinedDecl != nil)
#expect(userDefinedDecl.type == .userDefined)

let pathDecl = try namespace.declarePathMacro("PathMacro")
#expect(pathDecl != nil)
#expect(pathDecl.type == .path)

let pathListDecl = try namespace.declarePathListMacro("PathListMacro")
#expect(pathListDecl != nil)
#expect(pathListDecl.type == .pathList)

var diags1 = Array<MacroExpressionDiagnostic>()
Expand Down Expand Up @@ -116,19 +106,16 @@ import SWBMacro

// Declarate a string macro in the lower namespace.
let lowerStringDecl = try lowerNamespace.declareStringMacro("StringMacro")
#expect(lowerStringDecl != nil)
#expect(lowerStringDecl.type == .string)

// Create the middle of the three namespaces, and make sure we can see the string macro declaration from the lower namespace.
let middleNamespace = MacroNamespace(parent: lowerNamespace, debugDescription: "middle")
let middleStringDecl = try middleNamespace.declareStringMacro("StringMacro")
#expect(middleStringDecl != nil)
#expect(middleStringDecl.type == .string)
#expect(middleStringDecl === lowerStringDecl)

// Also declare a string list macro in the middle namespace.
let middleStringListDecl = try middleNamespace.declareStringListMacro("StringListMacro")
#expect(middleStringListDecl != nil)
#expect(middleStringListDecl.type == .stringList)

// Make sure we cannot reach the middle-namespace string list macro declaration if we do the lookup from the lower namespace.
Expand All @@ -138,19 +125,16 @@ import SWBMacro
// Create the upper of the three namespaces, and make sure we can see the string macro declaration from the lower namespace.
let upperNamespace = MacroNamespace(parent: middleNamespace, debugDescription: "upper")
let upperStringDecl = try upperNamespace.declareStringMacro("StringMacro")
#expect(upperStringDecl != nil)
#expect(upperStringDecl.type == .string)
#expect(upperStringDecl === lowerStringDecl)

// Make sure we can also see the string list macro declaration from the middle namespace.
let upperStringListDecl = try upperNamespace.declareStringListMacro("StringListMacro")
#expect(upperStringListDecl != nil)
#expect(upperStringListDecl.type == .stringList)
#expect(upperStringListDecl === middleStringListDecl)

// Make sure we can also declare a boolean macro in the upper namespace.
let upperBooleanDecl = try upperNamespace.declareBooleanMacro("BooleanMacro")
#expect(upperBooleanDecl != nil)
#expect(upperBooleanDecl.type == .boolean)

// Make sure we cannot reach the upper-namespace boolean macro declaration if we do the lookup from either the lower or the middle namespace.
Expand All @@ -161,7 +145,6 @@ import SWBMacro

// Make sure we can also declare a path macro in the upper namespace.
let upperPathDecl = try upperNamespace.declarePathMacro("PathMacro")
#expect(upperPathDecl != nil)
#expect(upperPathDecl.type == .path)

// Make sure we cannot reach the upper-namespace path macro declaration if we do the lookup from either the lower or the middle namespace.
Expand All @@ -173,7 +156,6 @@ import SWBMacro

// Make sure we can also declare a path macro in the upper namespace.
let upperPathListDecl = try upperNamespace.declarePathListMacro("PathListMacro")
#expect(upperPathListDecl != nil)
#expect(upperPathListDecl.type == .pathList)

// Make sure we cannot reach the upper-namespace path list macro declaration if we do the lookup from either the lower or the middle namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ fileprivate struct HeadermapTaskConstructionTests: CoreBasedTests {
}
}
}
#expect(hmapContents != nil)
}

@Test(.requireSDKs(.macOS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ fileprivate struct SwiftModuleOnlyTaskConstructionTests: CoreBasedTests {
if tpc.isZippered {
try checkPlatform(
tpc.secondaryPlatform,
deploymentTarget: try #require(tpc.zipperedModuleOnlyDeploymentTarget))
deploymentTarget: tpc.zipperedModuleOnlyDeploymentTarget)
}
}
}
Expand Down
Loading

0 comments on commit ce1349c

Please sign in to comment.