@@ -508,25 +508,38 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
508
508
}
509
509
}
510
510
511
- func testFileURLsWithHostnames ( ) throws {
511
+ func testFileURLErrors ( ) throws {
512
512
enum ExpectedError {
513
+ case invalidAbsolutePath
513
514
case relativePath
514
515
case unsupportedHostname
515
516
516
- var manifestError : ManifestParseError {
517
+ var manifestError : ManifestParseError ? {
517
518
switch self {
519
+ case . invalidAbsolutePath:
520
+ return nil
518
521
case . relativePath:
519
522
return . invalidManifestFormat( " file:// URLs cannot be relative, did you mean to use '.package(path:)'? " , diagnosticFile: nil )
520
523
case . unsupportedHostname:
521
524
return . invalidManifestFormat( " file:// URLs with hostnames are not supported, are you missing a '/'? " , diagnosticFile: nil )
522
525
}
523
526
}
527
+
528
+ var pathError : TSCBasic . PathValidationError ? {
529
+ switch self {
530
+ case . invalidAbsolutePath:
531
+ return . invalidAbsolutePath( " " )
532
+ default :
533
+ return nil
534
+ }
535
+ }
524
536
}
525
537
526
538
let urls : [ ( String , ExpectedError ) ] = [
527
539
( " file://../best " , . relativePath) , // Possible attempt at a relative path.
528
540
( " file://somehost/bar " , . unsupportedHostname) , // Obviously non-local.
529
541
( " file://localhost/bar " , . unsupportedHostname) , // Local but non-trivial (e.g. on Windows, this is a UNC path).
542
+ ( " file:// " , . invalidAbsolutePath) // Invalid path.
530
543
]
531
544
for (url, expectedError) in urls {
532
545
let content = """
@@ -546,7 +559,14 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
546
559
547
560
let observability = ObservabilitySystem . makeForTesting ( )
548
561
XCTAssertThrowsError ( try loadAndValidateManifest ( content, observabilityScope: observability. topScope) , " expected error " ) { error in
549
- XCTAssertEqual ( error as? ManifestParseError , expectedError. manifestError)
562
+ switch error {
563
+ case is ManifestParseError :
564
+ XCTAssertEqual ( error as? ManifestParseError , expectedError. manifestError)
565
+ case is TSCBasic . PathValidationError :
566
+ XCTAssertEqual ( error. localizedDescription, expectedError. pathError? . localizedDescription)
567
+ default :
568
+ XCTFail ( " unhandled error type: \( error) " )
569
+ }
550
570
}
551
571
}
552
572
}
0 commit comments