@@ -47,40 +47,44 @@ struct TestSupport {
4747}
4848
4949func assertSwiftPackage( fixturePackage: String , _ trailingArguments: [ String ] ) throws -> String {
50- guard let config = TestSupport . Configuration. default else {
51- throw XCTSkip ( " Please create 'Tests/default.json' " )
52- }
53- let swiftExecutable = config. hostSwiftExecutablePath
54- let packagePath = URL ( fileURLWithPath: #filePath)
55- . deletingLastPathComponent ( )
56- . appendingPathComponent ( " Fixtures " )
57- . appendingPathComponent ( fixturePackage)
58-
59- return try TestSupport . withTemporaryDirectory { buildDir in
60- var arguments = [ " package " , " --package-path " , packagePath. path, " --scratch-path " , buildDir]
61- if let sdkRootPath = config. hostSdkRootPath {
62- arguments += [ " --sdk " , sdkRootPath]
50+ #if os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
51+ throw XCTSkip ( " WITExtractor does not support platforms where Foundation.Process is unavailable " )
52+ #else
53+ guard let config = TestSupport . Configuration. default else {
54+ throw XCTSkip ( " Please create 'Tests/default.json' " )
6355 }
64- arguments += trailingArguments
65- let stdoutPipe = Pipe ( )
66- let process = Process ( )
67- process. executableURL = URL ( fileURLWithPath: swiftExecutable. path)
68- process. arguments = arguments
69- process. standardOutput = stdoutPipe
70- try process. run ( )
71- process. waitUntilExit ( )
56+ let swiftExecutable = config. hostSwiftExecutablePath
57+ let packagePath = URL ( fileURLWithPath: #filePath)
58+ . deletingLastPathComponent ( )
59+ . appendingPathComponent ( " Fixtures " )
60+ . appendingPathComponent ( fixturePackage)
7261
73- guard process. terminationStatus == 0 else {
74- throw TestSupport . Error (
75- description: " Failed to execute \( ( [ swiftExecutable. path] + arguments) . joined ( separator: " " ) ) "
76- )
77- }
78- guard let stdoutBytes = try stdoutPipe. fileHandleForReading. readToEnd ( ) else { return " " }
79- struct Output : Codable {
80- let witOutputPath : String
81- let swiftOutputPath : String
62+ return try TestSupport . withTemporaryDirectory { buildDir in
63+ var arguments = [ " package " , " --package-path " , packagePath. path, " --scratch-path " , buildDir]
64+ if let sdkRootPath = config. hostSdkRootPath {
65+ arguments += [ " --sdk " , sdkRootPath]
66+ }
67+ arguments += trailingArguments
68+ let stdoutPipe = Pipe ( )
69+ let process = Process ( )
70+ process. executableURL = URL ( fileURLWithPath: swiftExecutable. path)
71+ process. arguments = arguments
72+ process. standardOutput = stdoutPipe
73+ try process. run ( )
74+ process. waitUntilExit ( )
75+
76+ guard process. terminationStatus == 0 else {
77+ throw TestSupport . Error (
78+ description: " Failed to execute \( ( [ swiftExecutable. path] + arguments) . joined ( separator: " " ) ) "
79+ )
80+ }
81+ guard let stdoutBytes = try stdoutPipe. fileHandleForReading. readToEnd ( ) else { return " " }
82+ struct Output : Codable {
83+ let witOutputPath : String
84+ let swiftOutputPath : String
85+ }
86+ let jsonOutput = try JSONDecoder ( ) . decode ( Output . self, from: stdoutBytes)
87+ return try String ( contentsOfFile: jsonOutput. witOutputPath)
8288 }
83- let jsonOutput = try JSONDecoder ( ) . decode ( Output . self, from: stdoutBytes)
84- return try String ( contentsOfFile: jsonOutput. witOutputPath)
85- }
89+ #endif
8690}
0 commit comments