在 Swift 中打开代码覆盖率时出现分段错误 11 [英] Segmentation fault 11 when code coverage is turned on in Swift

查看:30
本文介绍了在 Swift 中打开代码覆盖率时出现分段错误 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Swift 中使用 XCTest 运行单元测试时,当代码覆盖率关闭时它们运行良好.但是,一旦我尝试启用代码覆盖率,我的 4 个类的构建/测试失败,并给出以下错误消息:由于信号导致命令失败:分段错误:11.

While I am running unit tests with XCTest in Swift, they run fine when code coverage is turned off. However once I try to enable code coverage, I have a failed build/test with 4 classes giving the following error message: Command failed due to signal: Segmentation fault: 11.

推荐答案

这对我有用(因为所有其他建议在我的情况下都不起作用).尝试在代码覆盖率打开的情况下运行单元测试时,我在特定的 Swift 类上遇到了分段错误 11.事实证明,我们在类的属性上有一个三元表达式,如下所示:

Here is what worked for me (as all the other suggestions did not work in my case). I was getting a segmentation fault 11 on a particular Swift class when trying to run unit tests with code coverage turned ON. It turns out that we had a ternary expression on a class's property like so:

let cellBorder : CGFloat = MyHelperClass.isIPad() ? 10.0 : 6.0

使它成为一个懒惰的变量解决了这个问题:

Making it a lazy var fixed the problem:

lazy var cellBorder : CGFloat = MyHelperClass.isIPad() ? 10.0 : 6.0

明确地说,代码编译并运行良好直到我们尝试打开代码覆盖率.我还发现了这个 Open Radar这个人的帖子 概述了解决方案.似乎是 Apple 的错误.

To be clear, the code compiled and worked fine until we tried turning on code coverage. I also found this Open Radar and this guy's post that outlined the solution. Appears to be an Apple bug.

这篇关于在 Swift 中打开代码覆盖率时出现分段错误 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆