【问题标题】:'unexpected '@' in program' error while building tests构建测试时出现“程序中的意外'@'错误”
【发布时间】:2017-12-19 06:10:00
【问题描述】:

在我的项目中,我使用了来自 ReactiveCocoa 的名为 keypath 的宏:

NSString *lowercaseStringPath = @keypath(NSString.new, lowercaseString);
// => @"lowercaseString"

 * @endcode
 *
 * ... the macro returns an \c NSString containing all but the first path
 * component or argument (e.g., @"lowercaseString.UTF8String", @"version").
 *
 * In addition to simply creating a key path, this macro ensures that the key
 * path is valid at compile-time (causing a syntax error if not), and supports
 * refactoring, such that changing the name of the property will also update any
 * uses of \@keypath.
 */
#define keypath(...) \
    metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__))(keypath1(__VA_ARGS__))(keypath2(__VA_ARGS__))

#define keypath1(PATH) \
    (((void)(NO && ((void)PATH, NO)), strchr(# PATH, '.') + 1))

#define keypath2(OBJ, PATH) \
    (((void)(NO && ((void)OBJ.PATH, NO)), # PATH))

它适用于主要目标。但是当我尝试运行测试时,它向我显示了这个错误:

我看到this post

这与我项目中的问题非常相似。但仍然不同,没有有用的答案。 有谁知道如何解决它?因为我真的被困在这里,不知道该去哪里。

【问题讨论】:

  • TokenModel 是否在测试目标和您的主要目标中?
  • 是的,当然,我已经包含了它。

标签: objective-c xcode xctest uitest


【解决方案1】:

TokenModel 不应编译到您的测试目标中。测试目标应该只包含测试代码(以及任何需要的库)。

转到您的测试目标设置。在测试部分的常规下,确保您已指定“主机应用程序”。您可能还需要启用“允许测试主机应用程序 API”复选框。

然后从您的测试目标中删除生产代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-24
    • 2020-03-15
    • 1970-01-01
    • 2023-03-26
    • 2021-03-21
    相关资源
    最近更新 更多