xcodebuild corrupts test result output when output redirected to file

非 Y 不嫁゛ 提交于 2019-12-31 22:27:54

问题


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.

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.

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.

when it should actually be:

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

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

The output is out-of-order as described above.

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?


回答1:


As noted by Malte in a comment above, a cleaner solution might be

    env NSUnbufferedIO=YES xcodebuild ...



回答2:


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


来源:https://stackoverflow.com/questions/18995187/xcodebuild-corrupts-test-result-output-when-output-redirected-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!