gpt4 book ai didi

swift - 在 Kitura 中运行单元测试时出错

转载 作者:行者123 更新时间:2023-11-28 10:58:01 24 4
gpt4 key购买 nike

我是 Kitura 和 Xcode 的新手,在添加测试文件时遇到了一些问题。它似乎与@testing 指令有关。我的设置与 Kitura website 上显示的相同.当我在控制台中调用 swift build 然后 swift test 我得到以下错误:

Compile Swift Module 'testTests' (1 sources)
Linking ./.build/debug/testPackageTests.xctest/Contents/MacOS/testPackageTests
Undefined symbols for architecture x86_64:
"__TFC4test3OkoCfT_S0_", referenced from:
__TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
"__TMaC4test3Oko", referenced from:
__TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test

然而,当我注释掉行 @testable import test 并键入 swift build 然后 swift test 然后我得到以下错误:

Compile Swift Module 'testTests' (1 sources)
/Users/*user*/Projects/Kitura/test/Tests/testTests/OkoTests.swift:6:17: error: use of unresolved identifier 'Oko'
let o = Oko()
^~~
<unknown>:0: warning: 'cacheParamsComputed' is deprecated
<unknown>:0: warning: 'cacheAlphaComputed' is deprecated
<unknown>:0: warning: 'keepCacheWindow' is deprecated
<unknown>:0: error: 'memoryless' is unavailable
Metal.MTLCommandBufferError:19:14: note: 'memoryless' has been explicitly marked unavailable here
case memoryless
^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test

当我尝试从 Xcode 生成的项目(swift package generate-xcodeproj)对其进行测试时,出现编译错误:

Xcode build error

没有测试文件,一切正常。下面我介绍项目结构:

Xcode Project structure

最佳答案

我认为问题是 Swift 无法为包含 main.swift 文件的模块编译单元测试(即,要编译成可执行文件而不是库的模块在其他项目中使用)。我克隆了您的存储库,并能够在 1) 删除 main.swift 和 2) 取消注释可测试的导入语句后编译和运行单元测试。

关于swift - 在 Kitura 中运行单元测试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42101177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com