xcodebuild corrupts test result output when output redirected to file - xcode

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?

As noted by Malte in a comment above, a cleaner solution might be
env NSUnbufferedIO=YES xcodebuild ...

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

Related

gitlab CI/CD xxx.tmp/TRIGGER_PAYLOAD: No such file or directory

On my window computer, I use git bash to register and start gitlab runner. gitlab-runner.exe stored in C:Runner directory. I open git-bash terminal, cd /c/Runner to register and run gitlab runner as following:
If I use CI/CD>>Schedules UI to start pipelines, everything works fine. But when I use trigger command like following, pipeline job failed.
curl -X POST \
-F token=xxxxxxx \
-F ref=develop \
http://git.xxxxxxxxx/trigger/pipeline
Error message is:
It seems that “/c/Runner/C:/Runner/builds...” is a wrong path. Does anyone know how to fix it? Thank you very much.
BTW: For some reason, I have to use bash terminal on window to start gitlab-runner.

How to run Robot Framework's `robot` command from a shell/bash script on Windows?

As a user I want to execute Robot Framework's robot command with some command line options. I put everything in a script to avoid retyping the long command each time - see example below. On Linux an Mac OS I can execute this script from any terminal emulator, i.e.
# Linux
. run_local_tests.sh
# Mac OS
./run_local_tests.sh
On Windows an application (VSCode Editor) associated with .sh file type is opened instead of executing the robot command or an error like robot: command not found is returned
# Windows
.\run_local_tests.sh
# OR
run_local_tests.sh
# OR
bash run_local_tests.sh
shell script - filename: run_local_tests.sh
#!/bin/bash
# Set desired loglevel: NONE (less details), INFO, DEBUG, TRACE (most details)
export LOG_LEVEL=TRACE
# RUN CONTRIBUTION SERVICE TESTS
robot -i CONTRIBUTION -e circleci \
--outputdir results \
--log NONE \
--report NONE \
--output XML/CONTRIBUTION.xml \
--noncritical not-ready \
--flattenkeywords for \
--flattenkeywords foritem \
--flattenkeywords name:_resources.* \
--loglevel $LOG_LEVEL \
--name CONTRI \
robot/CONTRIBUTION_TESTS/
Renaming the script from .sh to .bat doen't help :(
entering bash, then activating venv and calling the script doesn't work
What other options are there (without installing additional tools like Cygwin etc.)?
I'm actually trying to answer the same question in the opposite direction (how to trigger/run them on my machine as .sh). Looks like we may help each other out. 8)
I believe this is what you're looking for:
Your file would be run_local_tests.bat
Contents:
#echo off
cd C:\path\to\robot\project
call robot -d relative/path/to/test/output/dir relative/path/to/run_local_tests.bat
Of course you can use any other valid robot cli syntax in the call also. You may have to make it executable too. I'm not sure.

makefile stopping after some commands in windows

this is my first time using makefile to simplify my hybrid mobileapps developement. So, i have this pretty makefile which refuses to run after some commands. Please have a check.
.PHONY: run
OUTPUT_FILE=final.apk
ALIAS=mycert
KEYPASS=shittypass
KEYSTORE=certs/bang.keystore
UNSIGNED=platforms/android/build/outputs/apk/android-release-unsigned.apk
PACKAGE='com.example.testapp'
sign:
del -f ${OUTPUT_FILE}
cordova build android --release
jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore ${KEYSTORE} -storepass ${KEYPASS} ${UNSIGNED} ${ALIAS}
zipalign -v 4 ${UNSIGNED} ${OUTPUT_FILE}
execute:
adb shell am start -n ${PACKAGE}/${PACKAGE}.MainActivity
install:
adb install -r ${OUTPUT_FILE}
log:
adb logcat | grep `adb shell ps | grep ${PACKAGE} | cut -c10-15`
run: sign install execute log
The commands under "sign:" section are running perfectly but log: execute: and install: are not even showing in the cmd.
I am using Windows 7 and GnuWin32 make program.
make always tries to build only the first target in the makefile, unless you specify a specific target on the command line; for example you could invoke make sign install execute log and it would run them all.
It looks like you wanted the run target to be the default target when you type make; if so it must be the first target in the makefile not the last one.
Also, you should not be indenting the log and run targets like you do in your example above. It's confusing at best and an error at worst.

Passing arguments to Bash Script to use with a command

I have an iOS Build command on Mac and I want to create a script that will receive arguments like iOS version, Device etc and run a build with it.
For some reason I am unable to pass the arguments successfully from the cmd to the script itself.
Here's the script:
#!/usr/bin/env node
DEVICENAME="iPhone 5s"
OS="9"
xcodebuild -scheme MyScheme -destination 'platform=iOS Simulator,name=iPhone 5s,OS=9.2' -project /Users/etc/etc/Application.xcodeproj
I tried substituting like this:
xcodebuild -scheme MyScheme -destination 'platform=iOS Simulator,name=$DEVICENAME,OS=$OS' -project /Users/etc/etc/Application.xcodeproj
And like this:
xcodebuild -scheme MyScheme -destination 'platform=iOS Simulator,name=${DEVICENAME},OS=${OS}' -project /Users/etc/etc/Application.xcodeproj
Neither works and I can't seem to find a fix online.
Anybody knows what should I do here?
Bash doesn't put variables in single quotes, so it should be:
xcodebuild -scheme MyScheme -destination "platform=iOS Simulator,name=$DEVICENAME,OS=$OS" -project /Users/etc/etc/Application.xcodeproj

maven release plugin and command line arguments

I am trying to do a non-interactive maven release:
mvn clean install \
-PmyAssembly,attach-installer \
-DcustomerFlag=simple \
release:clean \
release:prepare \
release:perform \
-DreleaseVersion=1.0.1 \
-DdevelopmentVersion=1.0.2-SNAPSHOT \
-Dtag=my-project-1.0.1
But the property -DcustomerFlag=simple is not set when running perform only when running prepare.
Do I need to specify all command line arguments and profile twice, once for prepare and once for perform ?
Alternatively I guess I can just skip the perform step and do a regular build/deploy afterwards with the parameters I need from the generated tag.
None of the -D args from the commandline are passed by the maven-release-plugin to the inner Maven calls. You should use -Darguments="-DcustomerFlag=simple" to get the expected result, see arguments

Resources