Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix: standalone tests never run
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahKamara committed Mar 5, 2024
1 parent 49ffe69 commit e767474
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
13 changes: 13 additions & 0 deletions Sources/XCTesting/Internal/Test+ID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ extension Test.ID {
)
}
}

extension Test.ID {
init(fileID: String, testName: String) {
let firstSlash = fileID.firstIndex(of: "/")!
let moduleName = String(fileID[..<firstSlash])

self.init(
moduleName: moduleName,
nameComponents: [testName],
sourceLocation: nil
)
}
}
38 changes: 14 additions & 24 deletions Sources/XCTesting/Public/TestScaffold.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,27 @@ public enum TestScaffold {
/// - suite: a type marked with @Suite
/// - testName: the name of a function containing a test
/// - testCase: The XCTestCase that will host the test
public static func run(suite: Any.Type? = nil, testName: String, hostedBy testCase: XCTestCase) async throws {
let config = makeConfiguration(suite: suite, testName: testName, testCase: testCase)
try await run(configuration: config, hostedBy: testCase)
}


/// Create a test configuration
/// - Parameters:
/// - suite: a type marked with @Suite
/// - test: the name of a function containing a test e.g. `testThis(arg1:)`
/// - testCase: The XCTestCase that will host the test
static func makeConfiguration(
suite: Any.Type?,
public static func run(
suite: Any.Type? = nil,
testName: String,
testCase: XCTestCase
) -> Configuration {
let id = if let suite {
hostedBy testCase: XCTestCase,
fileID: String = #fileID,
filePath: String = #filePath,
line: Int = #line,
column: Int = #column
) async throws {
let testID = if let suite {
Test.ID(suite: suite, testName: testName)
} else {
Test.ID(
moduleName: "",
nameComponents: [testName],
sourceLocation: nil
)
Test.ID(fileID: fileID, testName: testName)
}

var config = Configuration()
config.isParallelizationEnabled = false
config.testFilter = .init(including: [id])

return config
// Set Filter so that run only contains our test
config.testFilter = .init(including: [testID])

try await run(configuration: config, hostedBy: testCase)
}


Expand Down
24 changes: 24 additions & 0 deletions Tests/XCTestingTests/FunctionTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
import XCTesting
import Foundation


@XCTesting
@Test
func AATest() {
withKnownIssue {
#expect(Bool(false))
}
print("HI")
#expect(Bool(false))
print("ENVIRONMENT")
ProcessInfo.processInfo.environment.forEach { (key, value) in
print(" "+key, value)
}

print("\n\n")
ProcessInfo.processInfo.arguments.forEach { value in
print(" "+value)
}

print(ProcessInfo.processInfo.processIdentifier, ProcessInfo.processInfo.globallyUniqueString)
}


@XCTesting
@Test
Expand Down
7 changes: 7 additions & 0 deletions Tests/XCTestingTests/SuiteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ struct SuiteTests {
#expect(Bool(false))
}

@Test
func withKnownIssues() {
withKnownIssue {
#expect(Bool(false))
}
}

@Test
func basic() {
#expect(Bool(true))
Expand Down

0 comments on commit e767474

Please sign in to comment.