Avatar
Avatar
omochimetaru
@swift-6.2 + testing import Testing struct MyRecursiveSuiteTrait: SuiteTrait & TestTrait & TestScoping { var isRecursive: Bool { true } func scopeProvider(for test: Test, testCase: Test.Case?) -> MyRecursiveSuiteTrait? { print("scopeProvider called", test.name, testCase == nil ? "suite" : "test") return self } func provideScope( for test: Test, testCase: Test.Case?, performing function: () async throws -> Void ) async throws { print("enter provideScope", test.name, testCase == nil ? "suite" : "test") defer { print("leave provideScope", test.name, testCase == nil ? "suite" : "test") } try await function() } } extension Trait where Self == MyRecursiveSuiteTrait { static var mySuperSuite: Self { Self() } } // a. ここで Suite trait として1回呼ばれる @Suite(.mySuperSuite) struct MyTest { // b. ここで Suite trait として1回呼ばれる // c. ここで Test trait として1回呼ばれる @Test func foo() { print("foo") } // d. ここで Suite trait として1回呼ばれる // e. ここで Test trait として1回呼ばれる @Test func bar() { print("bar") } } (edited)
scopeProvider called MyTest suite enter provideScope MyTest suite scopeProvider called bar() suite enter provideScope bar() suite scopeProvider called foo() suite enter provideScope foo() suite scopeProvider called bar() test enter provideScope bar() test bar leave provideScope bar() test scopeProvider called foo() test enter provideScope foo() test leave provideScope bar() suite foo leave provideScope foo() test leave provideScope foo() suite leave provideScope MyTest suite◇ Test run started. ↳ Testing Library Version: 6.2 (3fdabe5392108d8) ↳ Target Platform: aarch64-unknown-linux-gnu ◇ Suite MyTest started. ◇ Test bar() started. ◇ Test foo() started. ✔ Test bar() passed after 0.001 seconds. ✔ Test foo() passed after 0.001 seconds. ✔ Suite MyTest passed after 0.001 seconds. ✔ Test run with 2 tests in 1 suite passed after 0.001 seconds. (edited)