-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDocumentationExampleTests.swift
More file actions
70 lines (61 loc) · 2.54 KB
/
DocumentationExampleTests.swift
File metadata and controls
70 lines (61 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import DocumentationHarness
import Foundation
import Testing
/// Integration tests that validate all code examples in DocC documentation
@Suite("Documentation Code Examples")
internal struct DocumentationExampleTests {
private let testHarness = DocumentationValidator()
/// Test harness that extracts and validates Swift code examples from documentation
@Test("All documentation code examples compile and execute correctly")
internal func validateAllDocumentationExamples() throws {
let results = try testHarness.validate(
relativePaths: Settings.docPaths,
atProjectRoot: Settings.projectRoot
)
// Report any failures
let failures = results.filter { !$0.isSuccess && !$0.isSkipped }
if !failures.isEmpty {
let failureReport = failures.map { result in
let path: String
if #available(iOS 16.0, watchOS 9.0, tvOS 16.0, macCatalyst 16.0, *) {
path = result.fileURL.path()
} else {
path = result.fileURL.path
}
return
"\(path):\(result.lineNumber) - \(result.error?.localizedDescription ?? "Unknown error")"
}
.joined(separator: "\n")
throw DocumentationTestError.exampleValidationFailed(
"Code examples failed validation:\n\(failureReport)"
)
}
// Log success summary
print("✅ Validated \(results.count) code examples from documentation")
}
@Test("Quick Start Guide examples work correctly")
internal func validateQuickStartGuideExamples() throws {
let quickStartFile = try Settings.resolveFilePath(
"Documentation.docc/Tutorials/Quick-Start-Guide.md"
)
let results = try testHarness.validateFile(at: quickStartFile)
// Specific validation for Quick Start examples
#expect(!results.isEmpty, "Quick Start Guide should contain code examples")
#expect(
results.allSatisfy { $0.isSuccess || $0.isSkipped },
"All Quick Start examples should compile successfully"
)
}
@Test("Creating Macros tutorial examples work correctly")
internal func validateMacroTutorialExamples() throws {
let macroTutorialFile = try Settings.resolveFilePath(
"Documentation.docc/Tutorials/Creating-Macros-with-SyntaxKit.md"
)
let results = try testHarness.validateFile(at: macroTutorialFile)
// Macro examples should compile (though they may not execute without full macro setup)
let compileResults = results.filter { $0.testType == .parsing }
#expect(
compileResults.allSatisfy { $0.isSuccess || $0.isSkipped },
"All macro examples should compile successfully")
}
}