当我尝试在 linux上构建一个swift包时,我有一个错误: swift build -vlsb_release -rwhich clang/opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/4 -lPackageDescription -swift-version 4 -I /opt/swift/
> swift build -v lsb_release -r which clang /opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/4 -lPackageDescription -swift-version 4 -I /opt/swift/usr/lib/swift/pm/4 -sdk / /home/me/SwiftProject/Package.swift -fileno 5 /opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/3 -lPackageDescription -swift-version 3 -I /opt/swift/usr/lib/swift/pm/3 -sdk / /home/me/SwiftProject/.build/checkouts/siesta-3156441904511450749/Package.swift -fileno 5 /opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/3 -lPackageDescription -swift-version 3 -I /opt/swift/usr/lib/swift/pm/3 -sdk / /home/me/SwiftProject/.build/checkouts/SwiftyJSON-6376406316629445150/Package.swift -fileno 5 error: missingLinuxMain
运行最后一个命令时没有错误:
/opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/3 -lPackageDescription -swift-version 3 -I /opt/swift/usr/lib/swift/pm/3 -sdk / /home/me/SwiftProject/.build/checkouts/SwiftyJSON-6376406316629445150/Package.swift -fileno 5
我在Test目录中有一个文件LinuxMain.swift:
Tests ├── ProjectTests │ ├── SomeTests.swift └── LinuxMain.swift
LinuxMain.swift:
import XCTest @testable import ProjectTests XCTMain([ testCase(SomeTests.allTests), ])
我在ubuntu 17.04上使用swift 4.0
SwiftPM使用名为LinuxMain.swift的文件(位于测试目标的根目录,通常是Tests / LinuxMain.swift)来查找Linux上的单元测试. (在Apple平台上,它使用Objective-C运行时,但这在Linux上不可用.)看起来您的构建失败,因为SwiftPM无法找到该文件.
如果您还没有LinuxMain.swift文件,则应创建一个.查看它应该如何格式化的最简单方法可能是在空目录中运行swift package init并检查预期的目录和文件结构.
该文件应该看起来像这样,但适合您的包(我从here复制了这个):
import XCTest @testable import MarathonTests XCTMain([ testCase(MarathonTests.allTests) ])
每个XCTestCase子类还需要一个allTests属性.同样,默认目录结构应该让您了解它应该如何显示.
您可能还会发现this article I wrote a few months ago很有趣.