Skip to content

Commit

Permalink
Add module aliasing fixtures and functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elsh committed Feb 8, 2022
1 parent 2d6657e commit 954bb2b
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 1 deletion.
32 changes: 32 additions & 0 deletions Fixtures/Miscellaneous/ModuleAliasing/Simple/appPkg/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// swift-tools-version:999.0
import PackageDescription

let package = Package(
name: "appPkg",

This comment has been minimized.

Copy link
@tomerd

tomerd Feb 8, 2022

Contributor

nit: we dont normally use camel case. so this would more naturally be AppPkg

platforms: [
.macOS(.v10_12),
.iOS(.v10),
.tvOS(.v11),
.watchOS(.v5)
],
dependencies: [
.package(url: "../gamePkg", from: "1.0.0"),

This comment has been minimized.

Copy link
@tomerd

tomerd Feb 8, 2022

Contributor

nit: we dont normally use camel case. so this would more naturally be GamePkg - both the names and paths

],
targets: [
.executableTarget(
name: "App",
dependencies: [
"Utils",
.product(name: "Utils",
package: "gamePkg",
moduleAliases: ["Utils": "GameUtils"])
],
path: "./Sources/App"),
.target(
name: "Utils",
dependencies: [],
path: "./Sources/Utils"
)
]
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Utils
import GameUtils

This comment has been minimized.

Copy link
@tomerd

tomerd Feb 8, 2022

Contributor

nice!


Utils.echoModule()

let level = LevelDetector.detect(for: "TestUser")
print(level)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

public func echoModule() {
print("Utils")
}
14 changes: 14 additions & 0 deletions Fixtures/Miscellaneous/ModuleAliasing/Simple/gamePkg/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version:4.2

This comment has been minimized.

Copy link
@tomerd

tomerd Feb 8, 2022

Contributor

probably better to use more recent version, eg 5.5

import PackageDescription

let package = Package(
name: "gamePkg",

This comment has been minimized.

Copy link
@tomerd

tomerd Feb 8, 2022

Contributor

same comment re camel case (ie use GamePkg)

products: [
.library(name: "Game", targets: ["Game"]),
.library(name: "Utils", targets: ["Utils"]),
],
targets: [
.target(name: "Game", dependencies: ["Utils"]),
.target(name: "Utils", dependencies: []),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Utils

public struct Game: Equatable {
public var levels: [LevelDetector]

public static func startGame(for user: String) -> Int {
if user.isEmpty {
return -1
}
return LevelDetector.detect(for: user)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

public struct LevelDetector: Equatable {
public static func detect(for user: String) -> Int {
return user.count
}
}
2 changes: 1 addition & 1 deletion Tests/FunctionalTests/DependencyResolutionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SPMTestSupport
import TSCBasic
import Workspace
import XCTest

This comment has been minimized.

Copy link
@tomerd

tomerd Feb 8, 2022

Contributor

kill extra space

class DependencyResolutionTests: XCTestCase {
func testInternalSimple() {
fixture(name: "DependencyResolution/Internal/Simple") { prefix in
Expand Down
32 changes: 32 additions & 0 deletions Tests/FunctionalTests/ModuleAliasingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Commands
import PackageModel
import SourceControl
import SPMTestSupport
import TSCBasic
import Workspace
import XCTest

class ModuleAliasingTests: XCTestCase {

func testExternalSimple() {
fixture(name: "Miscellaneous/ModuleAliasing/Simple") { prefix in
let app = prefix.appending(components: "appPkg")
XCTAssertBuilds(app)
XCTAssertFileExists(prefix.appending(components: "appPkg", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "App"))

This comment has been minimized.

Copy link
@tomerd

tomerd Feb 8, 2022

Contributor

same comment re camel case (ie use AppPkg)

XCTAssertFileExists(prefix.appending(components: "appPkg", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "GameUtils.swiftmodule"))
XCTAssertFileExists(prefix.appending(components: "appPkg", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Utils.swiftmodule"))
let result = try SwiftPMProduct.SwiftBuild.executeProcess([], packagePath: app)
XCTAssertEqual(result.exitStatus, .terminated(code: 0))
}
}
}

1 comment on commit 954bb2b

@tomerd
Copy link
Contributor

@tomerd tomerd commented on 954bb2b Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great, some nits around naming.

Please sign in to comment.