@@ -8,19 +8,20 @@ internal class DocumentationTestHarness {
88 /// Project root directory calculated from the current file location
99 private static let projectRoot : URL = {
1010 let currentFileURL = URL ( fileURLWithPath: #filePath)
11- return currentFileURL
11+ return
12+ currentFileURL
1213 . deletingLastPathComponent ( ) // Tests/SyntaxDocTests
1314 . deletingLastPathComponent ( ) // Tests
1415 . deletingLastPathComponent ( ) // Project root
1516 } ( )
16-
17+
1718 /// Document paths to search for documentation files
1819 private static let docPaths = [
1920 " Sources/SyntaxKit/Documentation.docc " ,
2021 " README.md " ,
2122 " Examples " ,
2223 ]
23-
24+
2425 /// Default file extensions for documentation files
2526 private static let defaultPathExtensions = [ " md " ]
2627 /// Validates all code examples in all documentation files
@@ -37,17 +38,17 @@ internal class DocumentationTestHarness {
3738 }
3839
3940 /// Validates code examples in a specific file
40- internal func validateExamplesInFile( _ filePath : String ) async throws -> [ ValidationResult ] {
41- let fullPath = try resolveFilePath ( filePath)
42- let content = try String ( contentsOf: URL ( fileURLWithPath : fullPath ) )
41+ internal func validateExamplesInFile( _ fileURL : URL ) async throws -> [ ValidationResult ] {
42+ // let fullPath = try resolveFilePath(filePath)
43+ let content = try String ( contentsOf: fileURL )
4344
4445 let codeBlocks = extractSwiftCodeBlocks ( from: content)
4546 var results : [ ValidationResult ] = [ ]
4647
4748 for (index, codeBlock) in codeBlocks. enumerated ( ) {
4849 let result = await validateCodeBlock (
4950 code: codeBlock. code,
50- filePath : filePath ,
51+ fileURL : fileURL ,
5152 blockIndex: index,
5253 lineNumber: codeBlock. lineNumber,
5354 blockType: codeBlock. blockType
@@ -122,10 +123,10 @@ internal class DocumentationTestHarness {
122123
123124 /// Determines the type of code block based on context
124125 private func determineBlockType( from line: String ) -> CodeBlockType {
125- // Look for type hints in the markdown
126- if line . contains ( " Package.swift " ) {
127- return . packageManifest
128- } else if line. contains ( " bash " ) || line. contains ( " shell " ) {
126+ // if line.contains("Package.swift") {
127+ // return .packageManifest
128+ // }
129+ if line. contains ( " bash " ) || line. contains ( " shell " ) {
129130 return . shellCommand
130131 } else {
131132 return . example
@@ -135,28 +136,28 @@ internal class DocumentationTestHarness {
135136 /// Validates a single code block
136137 private func validateCodeBlock(
137138 code: String ,
138- filePath : String ,
139+ fileURL : URL ,
139140 blockIndex: Int ,
140141 lineNumber: Int ,
141142 blockType: CodeBlockType
142143 ) async -> ValidationResult ? {
143144 switch blockType {
144145 case . example:
145146 // Test compilation and basic execution
146- return await validateSwiftExample ( code, filePath : filePath , lineNumber: lineNumber)
147+ return await validateSwiftExample ( code, fileURL : fileURL , lineNumber: lineNumber)
147148
148149 case . packageManifest:
149150 #if canImport(Foundation) && (os(macOS) || os(Linux))
150151 // Package.swift files need special handling
151- return await validatePackageManifest ( code, filePath : filePath , lineNumber: lineNumber)
152+ return await validatePackageManifest ( code, fileURL : fileURL , lineNumber: lineNumber)
152153 #else
153154 return nil
154155 #endif
155156 case . shellCommand:
156157 // Skip shell commands for now
157158 return ValidationResult (
158159 success: true ,
159- filePath : filePath ,
160+ fileURL : fileURL ,
160161 lineNumber: lineNumber,
161162 testType: . skipped,
162163 error: nil
@@ -167,7 +168,7 @@ internal class DocumentationTestHarness {
167168 /// Validates a Swift code example
168169 private func validateSwiftExample(
169170 _ code: String ,
170- filePath : String ,
171+ fileURL : URL ,
171172 lineNumber: Int
172173 ) async -> ValidationResult {
173174 do {
@@ -181,7 +182,7 @@ internal class DocumentationTestHarness {
181182 if !compileResult. success {
182183 return ValidationResult (
183184 success: false ,
184- filePath : filePath ,
185+ fileURL : fileURL ,
185186 lineNumber: lineNumber,
186187 testType: . compilation,
187188 error: " Compilation failed: \( compileResult. error ?? " Unknown error " ) "
@@ -193,7 +194,7 @@ internal class DocumentationTestHarness {
193194 // let executeResult = try await executeCompiledSwift(tempFile)
194195 return ValidationResult (
195196 success: true ,
196- filePath : filePath ,
197+ fileURL : fileURL ,
197198 lineNumber: lineNumber,
198199 testType: . execution,
199200 error: nil
@@ -202,7 +203,7 @@ internal class DocumentationTestHarness {
202203 // Just compilation test for non-runnable code
203204 return ValidationResult (
204205 success: true ,
205- filePath : filePath ,
206+ fileURL : fileURL ,
206207 lineNumber: lineNumber,
207208 testType: . compilation,
208209 error: nil
@@ -211,7 +212,7 @@ internal class DocumentationTestHarness {
211212 } catch {
212213 return ValidationResult (
213214 success: false ,
214- filePath : filePath ,
215+ fileURL : fileURL ,
215216 lineNumber: lineNumber,
216217 testType: . compilation,
217218 error: " Test setup failed: \( error. localizedDescription) "
@@ -223,7 +224,7 @@ internal class DocumentationTestHarness {
223224 /// Validates a Package.swift manifest
224225 private func validatePackageManifest(
225226 _ code: String ,
226- filePath : String ,
227+ fileURL : URL ,
227228 lineNumber: Int
228229 ) async -> ValidationResult {
229230 do {
@@ -255,15 +256,15 @@ internal class DocumentationTestHarness {
255256
256257 return ValidationResult (
257258 success: success,
258- filePath : filePath ,
259+ fileURL : fileURL ,
259260 lineNumber: lineNumber,
260261 testType: . compilation,
261262 error: error
262263 )
263264 } catch {
264265 return ValidationResult (
265266 success: false ,
266- filePath : filePath ,
267+ fileURL : fileURL ,
267268 lineNumber: lineNumber,
268269 testType: . compilation,
269270 error: " Package validation setup failed: \( error. localizedDescription) "
@@ -380,22 +381,26 @@ internal class DocumentationTestHarness {
380381 #endif
381382
382383 /// Finds all documentation files containing code examples
383- @available ( * , deprecated, message: " Use findDocumentationFiles(in:relativeTo:pathExtensions:) instead " )
384- private static func findDocumentationFiles( ) throws -> [ String ] {
385- try FileManager . default. findDocumentationFiles ( in: Self . docPaths, relativeTo: Self . projectRoot, pathExtensions: Self . defaultPathExtensions)
384+ @available ( * , deprecated, message: " Use findDocumentationFiles(in:pathExtensions:) instead " )
385+ private static func findDocumentationFiles( ) throws -> [ URL ] {
386+ try Self . docPaths. flatMap { docPath in
387+ let absolutePath = Self . projectRoot. appendingPathComponent ( docPath)
388+ return try FileManager . default. findDocumentationFiles (
389+ in: absolutePath, pathExtensions: Self . defaultPathExtensions)
390+ }
386391 }
387392
388393 /// Resolves a relative file path to absolute path (public for use by test methods)
389- internal func resolveRelativePath( _ filePath: String ) throws -> String {
394+ internal func resolveRelativePath( _ filePath: String ) throws -> URL {
390395 try resolveFilePath ( filePath)
391396 }
392397
393398 /// Resolves a relative file path to absolute path
394- private func resolveFilePath( _ filePath: String ) throws -> String {
399+ private func resolveFilePath( _ filePath: String ) throws -> URL {
395400 if filePath. hasPrefix ( " / " ) {
396- return filePath
401+ return . init ( filePath: filePath )
397402 } else {
398- return Self . projectRoot. appendingPathComponent ( filePath) . path
403+ return Self . projectRoot. appendingPathComponent ( filePath)
399404 }
400405 }
401406}
0 commit comments