@@ -561,4 +561,156 @@ final class SwiftPMIntegrationTests: XCTestCase {
561
561
return location. range. lowerBound == Position ( line: 3 , utf16index: 4 )
562
562
}
563
563
}
564
+
565
+ func testChangePackageManifestFile( ) async throws {
566
+ let project = try await SwiftPMTestProject (
567
+ files: [
568
+ " Lib.swift " : """
569
+ #if MY_FLAG
570
+ #error( " MY_FLAG set " )
571
+ #else
572
+ #error( " MY_FLAG not set " )
573
+ #endif
574
+ """
575
+ ] ,
576
+ manifest: """
577
+ // swift-tools-version: 5.7
578
+ import PackageDescription
579
+ let package = Package(
580
+ name: " MyLibrary " ,
581
+ targets: [.target(name: " MyLibrary " )]
582
+ )
583
+ """
584
+ )
585
+
586
+ let ( uri, _) = try project. openDocument ( " Lib.swift " )
587
+ let initialDiagnostics = try await project. testClient. send (
588
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
589
+ )
590
+ XCTAssertEqual ( initialDiagnostics. fullReport? . items. map ( \. message) , [ " MY_FLAG not set " ] )
591
+
592
+ try await project. changeFileOnDisk (
593
+ " Package.swift " ,
594
+ newMarkedContents: """
595
+ // swift-tools-version: 5.7
596
+ import PackageDescription
597
+ let package = Package(
598
+ name: " MyLibrary " ,
599
+ targets: [.target(name: " MyLibrary " , swiftSettings: [.define( " MY_FLAG " )])]
600
+ )
601
+ """
602
+ )
603
+ try await repeatUntilExpectedResult {
604
+ let diagnosticsAfterUpdate = try await project. testClient. send (
605
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
606
+ )
607
+ return diagnosticsAfterUpdate. fullReport? . items. map ( \. message) == [ " MY_FLAG set " ]
608
+ }
609
+ }
610
+
611
+ func testChangeVersionSpecificPackageManifestFile( ) async throws {
612
+ let project = try await SwiftPMTestProject (
613
+ files: [
614
+ " Lib.swift " : """
615
+ #if MY_FLAG
616
+ #error( " MY_FLAG set " )
617
+ #elseif MY_OTHER_FLAG
618
+ #error( " MY_OTHER_FLAG set " )
619
+ #else
620
+ #error( " no flag set " )
621
+ #endif
622
+ """ ,
623
+
624
+ // swift-tools-version: 6.1
625
+ import PackageDescription
626
+ let package = Package(
627
+ name: " MyLibrary " ,
628
+ targets: [.target(name: " MyLibrary " , swiftSettings: [.define( " MY_FLAG " )])]
629
+ )
630
+ """ ,
631
+ ] ,
632
+ manifest: """
633
+ // swift-tools-version: 5.7
634
+ import PackageDescription
635
+ let package = Package(
636
+ name: " MyLibrary " ,
637
+ targets: [.target(name: " MyLibrary " )]
638
+ )
639
+ """
640
+ )
641
+
642
+ let ( uri, _) = try project. openDocument ( " Lib.swift " )
643
+ let initialDiagnostics = try await project. testClient. send (
644
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
645
+ )
646
+ XCTAssertEqual ( initialDiagnostics. fullReport? . items. map ( \. message) , [ " MY_FLAG set " ] )
647
+
648
+ try await project. changeFileOnDisk (
649
+
650
+ newMarkedContents: """
651
+ // swift-tools-version: 6.1
652
+ import PackageDescription
653
+ let package = Package(
654
+ name: " MyLibrary " ,
655
+ targets: [.target(name: " MyLibrary " , swiftSettings: [.define( " MY_OTHER_FLAG " )])]
656
+ )
657
+ """
658
+ )
659
+ try await repeatUntilExpectedResult {
660
+ let diagnosticsAfterUpdate = try await project. testClient. send (
661
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
662
+ )
663
+ return diagnosticsAfterUpdate. fullReport? . items. map ( \. message) == [ " MY_OTHER_FLAG set " ]
664
+ }
665
+ }
666
+
667
+ func testAddVersionSpecificPackageManifestFile( ) async throws {
668
+ let project = try await SwiftPMTestProject (
669
+ files: [
670
+ " Lib.swift " : """
671
+ #if MY_FLAG
672
+ #error( " MY_FLAG set " )
673
+ #else
674
+ #error( " MY_FLAG not set " )
675
+ #endif
676
+ """
677
+ ] ,
678
+ manifest: """
679
+ // swift-tools-version: 5.7
680
+ import PackageDescription
681
+ let package = Package(
682
+ name: " MyLibrary " ,
683
+ targets: [.target(name: " MyLibrary " )]
684
+ )
685
+ """
686
+ )
687
+
688
+ let ( uri, _) = try project. openDocument ( " Lib.swift " )
689
+ let initialDiagnostics = try await project. testClient. send (
690
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
691
+ )
692
+ XCTAssertEqual ( initialDiagnostics. fullReport? . items. map ( \. message) , [ " MY_FLAG not set " ] )
693
+
694
+ let versionSpecificManifestUrl = project
. scratchDirectory
. appending ( component
: " [email protected] " )
695
+ try await """
696
+ // swift-tools-version: 6.1
697
+ import PackageDescription
698
+ let package = Package(
699
+ name: " MyLibrary " ,
700
+ targets: [.target(name: " MyLibrary " , swiftSettings: [.define( " MY_FLAG " )])]
701
+ )
702
+ """ . writeWithRetry ( to: versionSpecificManifestUrl)
703
+
704
+ project. testClient. send (
705
+ DidChangeWatchedFilesNotification ( changes: [
706
+ FileEvent ( uri: DocumentURI ( versionSpecificManifestUrl) , type: . created)
707
+ ] )
708
+ )
709
+ try await repeatUntilExpectedResult {
710
+ let diagnosticsAfterUpdate = try await project. testClient. send (
711
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
712
+ )
713
+ return diagnosticsAfterUpdate. fullReport? . items. map ( \. message) == [ " MY_FLAG set " ]
714
+ }
715
+ }
564
716
}
0 commit comments