@@ -2226,6 +2226,55 @@ final class SwiftDriverTests: XCTestCase {
22262226 }
22272227 }
22282228
2229+ func testModuleAliasingWithImplicitBuild( ) throws {
2230+ var driver = try Driver ( args: [
2231+ " swiftc " , " foo.swift " , " -module-name " , " Foo " , " -module-alias " , " Car=Bar " ,
2232+ " -emit-module " , " -emit-module-path " , " /tmp/dir/Foo.swiftmodule " ,
2233+ ] )
2234+ let plannedJobs = try driver. planBuild ( )
2235+ XCTAssertTrue ( plannedJobs. contains { job in
2236+ job. commandLine. contains ( . flag( " -module-alias " ) ) &&
2237+ job. commandLine. contains ( . flag( " Car=Bar " ) ) &&
2238+ job. outputs [ 0 ] . file. absolutePath? . pathString == " /tmp/dir/Foo.swiftmodule "
2239+ } )
2240+ XCTAssertEqual ( driver. moduleOutputInfo. name, " Foo " )
2241+ XCTAssertNotNil ( driver. moduleOutputInfo. aliases)
2242+ XCTAssertEqual ( driver. moduleOutputInfo. aliases!. count, 1 )
2243+ XCTAssertEqual ( driver. moduleOutputInfo. aliases![ " Car " ] , " Bar " )
2244+ }
2245+
2246+ func testInvalidModuleAliasing( ) throws {
2247+ try assertDriverDiagnostics (
2248+ args: [ " swiftc " , " foo.swift " , " -module-name " , " Foo " , " -module-alias " , " CarBar " , " -emit-module " , " -emit-module-path " , " /tmp/dir/Foo.swiftmodule " ]
2249+ ) {
2250+ $1. expect ( . error( " invalid format \" CarBar \" ; use the format '-module-alias alias_name=underlying_name' " ) )
2251+ }
2252+
2253+ try assertDriverDiagnostics (
2254+ args: [ " swiftc " , " foo.swift " , " -module-name " , " Foo " , " -module-alias " , " Foo=Bar " , " -emit-module " , " -emit-module-path " , " /tmp/dir/Foo.swiftmodule " ]
2255+ ) {
2256+ $1. expect ( . error( " module alias \" Foo \" should be different from the module name \" Foo \" " ) )
2257+ }
2258+
2259+ try assertDriverDiagnostics (
2260+ args: [ " swiftc " , " foo.swift " , " -module-name " , " Foo " , " -module-alias " , " C-ar=Bar " , " -emit-module " , " -emit-module-path " , " /tmp/dir/Foo.swiftmodule " ]
2261+ ) {
2262+ $1. expect ( . error( " module name \" C-ar \" is not a valid identifier " ) )
2263+ }
2264+
2265+ try assertDriverDiagnostics (
2266+ args: [ " swiftc " , " foo.swift " , " -module-name " , " Foo " , " -module-alias " , " Car=Bar " , " -module-alias " , " Train=Car " , " -emit-module " , " -emit-module-path " , " /tmp/dir/Foo.swiftmodule " ]
2267+ ) {
2268+ $1. expect ( . error( " the name \" Car \" is already used for a module alias or an underlying name " ) )
2269+ }
2270+
2271+ try assertDriverDiagnostics (
2272+ args: [ " swiftc " , " foo.swift " , " -module-name " , " Foo " , " -module-alias " , " Car=Bar " , " -module-alias " , " Car=Bus " , " -emit-module " , " -emit-module-path " , " /tmp/dir/Foo.swiftmodule " ]
2273+ ) {
2274+ $1. expect ( . error( " the name \" Car \" is already used for a module alias or an underlying name " ) )
2275+ }
2276+ }
2277+
22292278 func testWholeModuleOptimizationUsingSupplementaryOutputFileMap( ) throws {
22302279 var driver1 = try Driver ( args: [
22312280 " swiftc " , " -whole-module-optimization " , " foo.swift " , " bar.swift " , " wibble.swift " , " -module-name " , " Test " ,
0 commit comments