当输出重定向到文件时,xcodebuild破坏测试结果输出 [英] xcodebuild corrupts test result output when output redirected to file

查看:181
本文介绍了当输出重定向到文件时,xcodebuild破坏测试结果输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让Jenkins的Xcode插件配置为通过将测试构建操作添加到自定义xcodebuild参数"设置中来运行单元测试.有关使Jenkins完全使用Xcode 5运行单元测试的更多信息,请参见此问题.

I have Jenkins with the Xcode plugin configured to run unit tests by adding the test build action to the Custom xcodebuild arguments setting. For more information on getting Jenkins to run the unit tests at all with Xcode 5, see this question.

现在我正在运行它,它似乎将NSLog语句的控制台输出或最终的** TEST SUCCEEDED **消息与测试结果混合在一起,因此偶尔会触发将单元测试结果转换为Jenkins所需的JUnit格式的解析器.

Now that I have it running, it seems to mix console output from NSLog statements or the final ** TEST SUCCEEDED ** message with the test results, thus occasionally tripping up the parser that converts unit test results to the JUnit format required for Jenkins.

例如,Jenkins日志显示如下输出:

For example, the Jenkins log shows output like this:

Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsNotZero]' passed (** TEST SUCCEEDED **

0.000 seconds).
Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsZero]' started.

实际上应该是:

Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsNotZero]' passed (0.000 seconds).
Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsZero]' started.
** TEST SUCCEEDED **

我进一步研究了这个问题,并将詹金斯排除在外.如果我直接在命令提示符下运行xcodebuild命令:

I have looked into this further and pulled Jenkins out of the picture. If I run the xcodebuild command directly at the command prompt:

xcodebuild \
    -workspace project.xcworkspace \
    -scheme Tests \
    -configuration Release \
    -sdk iphonesimulator7.0 \
    -destination "platform=iOS Simulator,name=iPhone Retina (4-inch),OS=latest" \
    test

输出总是按顺序很好地显示.

the output always comes out fine, in-order.

但是,如果我将输出通过管道传输到另一个程序或重定向到文件:

If, however, I pipe the output to another program or redirect to a file:

xcodebuild \
    -workspace project.xcworkspace \
    -scheme Tests \
    -configuration Release \
    -sdk iphonesimulator7.0 \
    -destination "platform=iOS Simulator,name=iPhone Retina (4-inch),OS=latest" \
    test > xcodebuild.out
cat xcodebuild.out

输出如上所述混乱.

这可能是由于不直接写入stdout时的缓冲还是缺少缓冲?有谁知道为什么会这样,我是否有能力解决这个问题?

Could this be due to buffering or lack of buffering when not directly writing to stdout? Does anyone know why this is happening and any workaround I might be able to perform to fix it?

推荐答案

感谢此答案,我发现了一种方法基本上使用script命令禁用缓冲.

Thanks to this answer, I discovered a way to essentially disable buffering using the script command.

script -q -t 0 xcodebuild.out \
    xcodebuild \
        -workspace project.xcworkspace \
        -scheme Tests \
        -configuration Release \
        -sdk iphonesimulator7.0 \
        -destination "platform=iOS Simulator,name=iPhone Retina (4-inch),OS=latest" \
        test
cat xcodebuild.out

这篇关于当输出重定向到文件时,xcodebuild破坏测试结果输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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