@@ -329,6 +329,50 @@ struct PathTests {
329
329
}
330
330
}
331
331
332
+ @Test (
333
+ arguments: [
334
+ ( path: " / " , expected: ( windows ? #"\"# : " / " ) ) ,
335
+ ( path: " /. " , expected: ( windows ? #"\"# : " / " ) ) ,
336
+ ( path: " /.. " , expected: ( windows ? #"\"# : " / " ) ) ,
337
+ ( path: " /bar/ " , expected: ( windows ? #"\bar"# : " /bar " ) ) ,
338
+ ] , [
339
+ " " ,
340
+ " " ,
341
+ " \t " ,
342
+ " \t \t " ,
343
+ " \n " ,
344
+ " \n \n " ,
345
+ " \t " ,
346
+ " \t " ,
347
+ " \n \t " ,
348
+ " \n \t " ,
349
+ ] ,
350
+ )
351
+ func absolutePathValidationWithPathContainsLeadingAndTrailingWhitespaces(
352
+ data: ( String , String ) ,
353
+ whitespaces: String ,
354
+ ) throws {
355
+ let path = data. 0
356
+ let expected = data. 1
357
+ do {
358
+ // Leading whitespaces
359
+ let actual = try AbsolutePath ( validating: " \( whitespaces) \( path) " ) . pathString
360
+ #expect( actual == expected, " Actual is not as expected. Path is: ' \( path) ' " )
361
+ }
362
+
363
+ do {
364
+ // Training whitespaces
365
+ let actual = try AbsolutePath ( validating: " \( path) \( whitespaces) " ) . pathString
366
+ #expect( actual == expected, " Actual is not as expected. Path is: ' \( path) ' " )
367
+ }
368
+
369
+ do {
370
+ // Leading and trailing whitespaces
371
+ let actual = try AbsolutePath ( validating: " \( whitespaces) \( path) \( whitespaces) " ) . pathString
372
+ #expect( actual == expected, " Actual is not as expected. Path is: ' \( path) ' " )
373
+ }
374
+ }
375
+
332
376
@Test
333
377
func comparison( ) {
334
378
#expect( AbsolutePath ( " / " ) <= AbsolutePath ( " / " ) ) ;
@@ -628,7 +672,7 @@ struct PathTests {
628
672
try RelativePath ( validating: " a/b/c/d " )
629
673
}
630
674
631
- withKnownIssue {
675
+ withKnownIssue ( " https://github.com/swiftlang/swift-package-manager/issues/8511: \\ " ) {
632
676
#expect { try RelativePath ( validating: " /a/b/d " ) } throws: { error in
633
677
( " \( error) " == " invalid relative path '/a/b/d'; relative path should not begin with '/' " )
634
678
}
@@ -637,6 +681,86 @@ struct PathTests {
637
681
}
638
682
}
639
683
684
+ struct relativePathValidationWithPathContainsLeadingAndTrailingWhitespacesReturnsExpectedValue {
685
+ func testImplementation(
686
+ data: ( String , String ) ,
687
+ whitespaces: String ,
688
+ ) async throws {
689
+ let path = data. 0
690
+ let expected = data. 1
691
+ do {
692
+ // Leading whitespaces
693
+ let actual = try RelativePath ( validating: " \( whitespaces) \( path) " ) . pathString
694
+ #expect( actual == expected, " Actual is not as expected. Path is: ' \( path) ' " )
695
+ }
696
+
697
+ do {
698
+ // Training whitespaces
699
+ let actual = try RelativePath ( validating: " \( path) \( whitespaces) " ) . pathString
700
+ #expect( actual == expected, " Actual is not as expected. Path is: ' \( path) ' " )
701
+ }
702
+
703
+ do {
704
+ // Leading and trailing whitespaces
705
+ let actual = try RelativePath ( validating: " \( whitespaces) \( path) \( whitespaces) " ) . pathString
706
+ #expect( actual == expected, " Actual is not as expected. Path is: ' \( path) ' " )
707
+ }
708
+ }
709
+
710
+ @Test (
711
+ arguments: [
712
+ ( path: " . " , expected: " . " ) ,
713
+ ( path: " bar/ " , expected: ( windows ? #"bar\"# : " bar " ) ) ,
714
+ ( path: " bar/baz " , expected: ( windows ? #"bar\baz"# : " bar/baz " ) ) ,
715
+ ] , [
716
+ " " ,
717
+ " " ,
718
+ " \t " ,
719
+ " \t \t " ,
720
+ " \n " ,
721
+ " \n \n " ,
722
+ " \t " ,
723
+ " \t " ,
724
+ " \n \t " ,
725
+ " \n \t " ,
726
+ ] ,
727
+ )
728
+ func relativePathValidationWithPathContainsLeadingAndTrailingWhitespaces(
729
+ data: ( String , String ) ,
730
+ whitespaces: String ,
731
+ ) async throws {
732
+ try await testImplementation ( data: data, whitespaces: whitespaces)
733
+ }
734
+
735
+
736
+ @Test (
737
+ arguments: [
738
+ ( path: " bar/ " , expected: " bar " ) ,
739
+ ] as [ ( String , String ) ] , [
740
+ " " ,
741
+ " " ,
742
+ " \t " ,
743
+ " \t \t " ,
744
+ " \n " ,
745
+ " \n \n " ,
746
+ " \t " ,
747
+ " \t " ,
748
+ " \n \t " ,
749
+ " \n \t " ,
750
+ ] ,
751
+ )
752
+ func relativePathValidationWithPathContainsLeadingAndTrailingWhitespacesFailsOnWindows(
753
+ data: ( String , String ) ,
754
+ whitespaces: String ,
755
+ ) async throws {
756
+ try await withKnownIssue ( " https://github.com/swiftlang/swift-package-manager/issues/8511: Path \( data. 0 ) is not properly " ) {
757
+ try await testImplementation ( data: data, whitespaces: whitespaces)
758
+ } when: {
759
+ ProcessInfo . hostOperatingSystem == . windows
760
+ }
761
+ }
762
+ }
763
+
640
764
}
641
765
642
766
@Test
0 commit comments