11
11
//===----------------------------------------------------------------------===//
12
12
13
13
import _InternalTestSupport
14
+ import struct Basics. AbsolutePath
15
+ import var Basics. localFileSystem
14
16
@testable
15
17
import Commands
18
+ import class PackageModel. UserToolchain
16
19
import XCTest
17
20
18
21
final class FixItCommandTests : CommandsTestCase {
@@ -22,4 +25,58 @@ final class FixItCommandTests: CommandsTestCase {
22
25
XCTAssert ( stdout. contains ( " USAGE: swift fixit " ) , stdout)
23
26
XCTAssert ( stdout. contains ( " -h, -help, --help " ) , stdout)
24
27
}
28
+
29
+ func testApplyFixIts( ) async throws {
30
+ try await fixture ( name: " SwiftFixIt/SwiftFixItPackage " ) { fixturePath in
31
+ let sourcePaths : [ AbsolutePath ]
32
+ let fixedSourcePaths : [ AbsolutePath ]
33
+ do {
34
+ let sourcesPath = fixturePath. appending ( components: " Sources " )
35
+ let fixedSourcesPath = sourcesPath. appending ( " Fixed " )
36
+
37
+ sourcePaths = try localFileSystem. getDirectoryContents ( sourcesPath) . filter { filename in
38
+ filename. hasSuffix ( " .swift " )
39
+ } . sorted ( ) . map { filename in
40
+ sourcesPath. appending ( filename)
41
+ }
42
+ fixedSourcePaths = try localFileSystem. getDirectoryContents ( fixedSourcesPath) . filter { filename in
43
+ filename. hasSuffix ( " .swift " )
44
+ } . sorted ( ) . map { filename in
45
+ fixedSourcesPath. appending ( filename)
46
+ }
47
+ }
48
+
49
+ XCTAssertEqual ( sourcePaths. count, fixedSourcePaths. count)
50
+
51
+ let targetName = " Diagnostics "
52
+
53
+ _ = try ? await executeSwiftBuild ( fixturePath, extraArgs: [ " --target " , targetName] )
54
+
55
+ do {
56
+ let artifactsPath = try fixturePath. appending (
57
+ components: " .build " ,
58
+ UserToolchain . default. targetTriple. platformBuildPathComponent,
59
+ " debug " ,
60
+ " \( targetName) .build "
61
+ )
62
+ let diaFilePaths = try localFileSystem. getDirectoryContents ( artifactsPath) . filter { filename in
63
+ // Ignore "*.emit-module.dia".
64
+ filename. split ( " . " ) . 1 == " dia "
65
+ } . map { filename in
66
+ artifactsPath. appending ( component: filename) . pathString
67
+ }
68
+
69
+ XCTAssertEqual ( sourcePaths. count, diaFilePaths. count)
70
+
71
+ _ = try await SwiftPM . fixit. execute ( diaFilePaths)
72
+ }
73
+
74
+ for (sourcePath, fixedSourcePath) in zip ( sourcePaths, fixedSourcePaths) {
75
+ try XCTAssertEqual (
76
+ localFileSystem. readFileContents ( sourcePath) ,
77
+ localFileSystem. readFileContents ( fixedSourcePath)
78
+ )
79
+ }
80
+ }
81
+ }
25
82
}
0 commit comments