Skip to content

Commit 6834a90

Browse files
committed
Update test case
1 parent c3a83a3 commit 6834a90

19 files changed

+127
-99
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,38 +158,47 @@ let openGraphShimsTarget = Target.target(
158158
cSettings: sharedCSettings,
159159
swiftSettings: sharedSwiftSettings
160160
)
161+
let openGraphTestsSupportTarget = Target.target(
162+
name: "OpenGraphTestsSupport",
163+
cSettings: sharedCSettings,
164+
swiftSettings: sharedSwiftSettings
165+
)
161166

162167
// MARK: - Test Targets
163168

164-
let openGraphTestTarget = Target.testTarget(
169+
let openGraphTestsTarget = Target.testTarget(
165170
name: "OpenGraphTests",
166171
dependencies: [
167172
"OpenGraph",
173+
"OpenGraphTestsSupport",
168174
],
169175
exclude: ["README.md"],
170176
cSettings: sharedCSettings,
171177
swiftSettings: sharedSwiftSettings
172178
)
173-
let openGraphSPITestTarget = Target.testTarget(
179+
let openGraphCxxTestsTarget = Target.testTarget(
174180
name: "OpenGraphCxxTests",
175181
dependencies: [
176182
"OpenGraphCxx",
183+
"OpenGraphTestsSupport",
177184
],
178185
exclude: ["README.md"],
179186
swiftSettings: sharedSwiftSettings + [.interoperabilityMode(.Cxx)]
180187
)
181-
let openGraphShimsTestTarget = Target.testTarget(
188+
let openGraphShimsTestsTarget = Target.testTarget(
182189
name: "OpenGraphShimsTests",
183190
dependencies: [
184191
"OpenGraphShims",
192+
"OpenGraphTestsSupport",
185193
],
186194
exclude: ["README.md"],
187195
cSettings: sharedCSettings,
188196
swiftSettings: sharedSwiftSettings
189197
)
190-
let openGraphCompatibilityTestTarget = Target.testTarget(
198+
let openGraphCompatibilityTestsTarget = Target.testTarget(
191199
name: "OpenGraphCompatibilityTests",
192200
dependencies: [
201+
"OpenGraphTestsSupport",
193202
.product(name: "Numerics", package: "swift-numerics"),
194203
],
195204
exclude: ["README.md"],
@@ -212,11 +221,12 @@ let package = Package(
212221
openGraphTarget,
213222
openGraphSPITarget,
214223
openGraphShimsTarget,
215-
216-
openGraphTestTarget,
217-
openGraphSPITestTarget,
218-
openGraphShimsTestTarget,
219-
openGraphCompatibilityTestTarget,
224+
openGraphTestsSupportTarget,
225+
226+
openGraphTestsTarget,
227+
openGraphCxxTestsTarget,
228+
openGraphShimsTestsTarget,
229+
openGraphCompatibilityTestsTarget,
220230
],
221231
cxxLanguageStandard: .cxx20
222232
)
@@ -268,9 +278,11 @@ if attributeGraphCondition {
268278

269279
let compatibilityTestCondition = envEnable("OPENGRAPH_COMPATIBILITY_TEST")
270280
if compatibilityTestCondition && attributeGraphCondition {
271-
openGraphCompatibilityTestTarget.addCompatibilitySettings()
281+
openGraphTestsSupportTarget.addCompatibilitySettings()
282+
openGraphCompatibilityTestsTarget.addCompatibilitySettings()
272283
} else {
273-
openGraphCompatibilityTestTarget.dependencies.append("OpenGraph")
284+
openGraphTestsSupportTarget.dependencies.append("OpenGraph")
285+
openGraphCompatibilityTestsTarget.dependencies.append("OpenGraph")
274286
}
275287

276288
extension [Platform] {

Tests/OpenGraphCompatibilityTests/Helper/AsyncSemaphore.swift renamed to Sources/OpenGraphTestsSupport/AsyncSemaphore.swift

File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// DataHelper.swift
3+
// OpenGraphTestsSupport
4+
5+
public struct Tuple<A, B> {
6+
public var first: A
7+
public var second: B
8+
9+
public init(first: A, second: B) {
10+
self.first = first
11+
self.second = second
12+
}
13+
}
14+
15+
public struct Triple<A, B, C> {
16+
public var first: A
17+
public var second: B
18+
public var third: C
19+
20+
public init(first: A, second: B, third: C) {
21+
self.first = first
22+
self.second = second
23+
self.third = third
24+
}
25+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// GraphEnvironmentTrait.swift
3+
// OpenGraphTestsSupport
4+
5+
public import Testing
6+
7+
#if OPENGRAPH_COMPATIBILITY_TEST
8+
@_exported public import AttributeGraph
9+
#else
10+
@_exported import OpenGraph
11+
#endif
12+
13+
public struct GraphEnvironmentTrait: TestTrait, TestScoping, SuiteTrait {
14+
private static let sharedGraph = Graph()
15+
private static let semaphore = AsyncSemaphore(value: 1)
16+
17+
@MainActor
18+
public func provideScope(for test: Test, testCase: Test.Case?, performing function: @Sendable () async throws -> Void) async throws {
19+
await Self.semaphore.wait()
20+
defer { Self.semaphore.signal() }
21+
let graph = Graph(shared: Self.sharedGraph)
22+
let subgraph = Subgraph(graph: graph)
23+
let oldSubgraph = Subgraph.current
24+
25+
Subgraph.current = subgraph
26+
try await function()
27+
Subgraph.current = oldSubgraph
28+
}
29+
30+
public var isRecursive: Bool {
31+
true
32+
}
33+
}
34+
35+
extension Trait where Self == GraphEnvironmentTrait {
36+
public static var graphScope: Self {
37+
GraphEnvironmentTrait()
38+
}
39+
}

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// OpenGraphCompatibilityTests
44

55
import Testing
6+
import OpenGraphTestsSupport
67

78
// *** Program crashed: Bad pointer dereference at 0x0000000ffff9400a ***
89
// swift-testing framework will crash here on Linux
910
// Report to upstream for investigation when we bump to 5.10
1011
#if canImport(Darwin)
11-
//@Suite(.disabled(if: !compatibilityTestEnabled, "Attribute is not implemented"))
12-
@Suite(.disabled("Skip flaky CI tests after #154 temporary, See more info on #157"))
13-
final class AnyAttributeCompatibilityTests: AttributeTestBase {
12+
//@Suite(.disabled(if: !compatibilityTestEnabled, "Attribute is not implemented"), .graphScope)
13+
@Suite(.disabled("Skip flaky CI tests after #154 temporary, See more info on #157"), .graphScope)
14+
struct AnyAttributeCompatibilityTests {
1415
@Test
1516
func constantValue() throws {
1617
let attributeNil = AnyAttribute.nil

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AttributeCompatibilityTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// OpenGraphCompatibilityTests
44

55
import Testing
6+
import OpenGraphTestsSupport
67

78
#if canImport(Darwin)
89
@MainActor

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/ExternalCompatibilityTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
// OpenGraphCompatibilityTests
44

55
import Testing
6+
import OpenGraphTestsSupport
67

78
// *** Program crashed: Bad pointer dereference at 0x0000000ffff9400a ***
89
// swift-testing framework will crash here on Linux
910
// Report to upstream for investigation when we bump to 5.10
1011
#if canImport(Darwin)
11-
@Suite(.disabled(if: !compatibilityTestEnabled, "Attribute is not implemented"))
12-
final class ExternalCompatibilityTests: AttributeTestBase {
12+
@MainActor
13+
@Suite(.disabled(if: !compatibilityTestEnabled, "Attribute is not implemented"), .graphScope)
14+
struct ExternalCompatibilityTests {
1315
@Test
1416
func example() throws {
1517
let type = External<Int>.self

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/FocusCompatibilityTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
// OpenGraphCompatibilityTests
44

55
import Testing
6+
import OpenGraphTestsSupport
67

78
#if canImport(Darwin)
8-
@Suite(.disabled(if: !compatibilityTestEnabled, "Attribute is not implemented"))
9-
final class FocusCompatibilityTests: AttributeTestBase {
9+
@MainActor
10+
@Suite(.disabled(if: !compatibilityTestEnabled, "Attribute is not implemented"), .graphScope)
11+
struct FocusCompatibilityTests {
1012
struct Demo {
1113
var a: Int
1214
var b: Double

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/PointerOffsetCompatibilityTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import RealModule
66
import Testing
7+
import OpenGraphTestsSupport
78

89
struct PointerOffsetCompatibilityTests {
910
@Test

0 commit comments

Comments
 (0)