Skip to content

Commit 1f5d30e

Browse files
authored
Merge pull request #44 from Backelite/feature/disable-unit-tests
Allow the de-activation of unit tests execution and coverage
2 parents 8642baf + 1852dfb commit 1f5d30e

File tree

1 file changed

+68
-59
lines changed

1 file changed

+68
-59
lines changed

src/main/shell/run-sonar-swift.sh

Lines changed: 68 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function runCommand() {
124124
## COMMAND LINE OPTIONS
125125
vflag=""
126126
nflag=""
127+
unittests="on"
127128
swiftlint="on"
128129
lizard="on"
129130

@@ -132,12 +133,13 @@ do
132133
case "$1" in
133134
-v) vflag=on;;
134135
-n) nflag=on;;
135-
-noswiftlint) swiftlint="";;
136-
--) shift; break;;
137-
-*)
136+
-nounittests) unittests="";;
137+
-noswiftlint) swiftlint="";;
138+
--) shift; break;;
139+
-*)
138140
echo >&2 "Usage: $0 [-v]"
139-
exit 1;;
140-
*) break;; # terminate while loop
141+
exit 1;;
142+
*) break;; # terminate while loop
141143
esac
142144
shift
143145
done
@@ -198,9 +200,11 @@ if [ -z "$appScheme" -o "$appScheme" = " " ]; then
198200
echo >&2 "ERROR - sonar.swift.appScheme parameter is missing in sonar-project.properties. You must specify which scheme is used to build your application."
199201
exit 1
200202
fi
201-
if [ -z "$destinationSimulator" -o "$destinationSimulator" = " " ]; then
202-
echo >&2 "ERROR - sonar.swift.simulator parameter is missing in sonar-project.properties. You must specify which simulator to use."
203-
exit 1
203+
if [ "$unittests" = "on" ]; then
204+
if [ -z "$destinationSimulator" -o "$destinationSimulator" = " " ]; then
205+
echo >&2 "ERROR - sonar.swift.simulator parameter is missing in sonar-project.properties. You must specify which simulator to use."
206+
exit 1
207+
fi
204208
fi
205209

206210
# if the appConfiguration is not specified then set to Debug
@@ -214,8 +218,12 @@ if [ "$vflag" = "on" ]; then
214218
echo "Xcode project file is: $projectFile"
215219
echo "Xcode workspace file is: $workspaceFile"
216220
echo "Xcode application scheme is: $appScheme"
217-
echo "Destination simulator is: $destinationSimulator"
218-
echo "Excluded paths from coverage are: $excludedPathsFromCoverage"
221+
if [ -n "$unittests"]; then
222+
echo "Destination simulator is: $destinationSimulator"
223+
echo "Excluded paths from coverage are: $excludedPathsFromCoverage"
224+
else
225+
echo "Unit tests are disabled"
226+
fi
219227
fi
220228

221229
## SCRIPT
@@ -234,56 +242,57 @@ fi
234242
rm -rf sonar-reports
235243
mkdir sonar-reports
236244

237-
# Unit tests and coverage
238-
239-
# Put default xml files with no tests and no coverage...
240-
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><testsuites name='AllTestUnits'></testsuites>" > sonar-reports/TEST-report.xml
241-
echo "<?xml version='1.0' ?><!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'><coverage><sources></sources><packages></packages></coverage>" > sonar-reports/coverage.xml
242-
243-
echo -n 'Running tests'
244-
buildCmd=(xcodebuild clean build test)
245-
if [[ ! -z "$workspaceFile" ]]; then
246-
buildCmd+=(-workspace $workspaceFile)
247-
elif [[ ! -z "$projectFile" ]]; then
248-
buildCmd+=(-project $projectFile)
245+
if [ "$unittests" = "on" ]; then
246+
# Unit tests and coverage
247+
248+
# Put default xml files with no tests and no coverage...
249+
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><testsuites name='AllTestUnits'></testsuites>" > sonar-reports/TEST-report.xml
250+
echo "<?xml version='1.0' ?><!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'><coverage><sources></sources><packages></packages></coverage>" > sonar-reports/coverage.xml
251+
252+
echo -n 'Running tests'
253+
buildCmd=(xcodebuild clean build test)
254+
if [[ ! -z "$workspaceFile" ]]; then
255+
buildCmd+=(-workspace $workspaceFile)
256+
elif [[ ! -z "$projectFile" ]]; then
257+
buildCmd+=(-project $projectFile)
258+
fi
259+
buildCmd+=( -scheme "$appScheme" -configuration "$appConfiguration" -enableCodeCoverage YES)
260+
if [[ ! -z "$destinationSimulator" ]]; then
261+
buildCmd+=(-destination "$destinationSimulator" -destination-timeout 60)
262+
fi
263+
264+
runCommand sonar-reports/xcodebuild.log "${buildCmd[@]}"
265+
cat sonar-reports/xcodebuild.log | $XCPRETTY_CMD -t --report junit
266+
mv build/reports/junit.xml sonar-reports/TEST-report.xml
267+
268+
269+
echo -n 'Computing coverage report'
270+
271+
# Build the --exclude flags
272+
excludedCommandLineFlags=""
273+
if [ ! -z "$excludedPathsFromCoverage" -a "$excludedPathsFromCoverage" != " " ]; then
274+
echo $excludedPathsFromCoverage | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh2
275+
while read word; do
276+
excludedCommandLineFlags+=" -i $word"
277+
done < tmpFileRunSonarSh2
278+
rm -rf tmpFileRunSonarSh2
279+
fi
280+
if [ "$vflag" = "on" ]; then
281+
echo "Command line exclusion flags for slather is:$excludedCommandLineFlags"
282+
fi
283+
284+
projectArray=(${projectFile//,/ })
285+
firstProject=${projectArray[0]}
286+
287+
slatherCmd=($SLATHER_CMD coverage --input-format profdata $excludedCommandLineFlags --cobertura-xml --output-directory sonar-reports)
288+
if [[ ! -z "$workspaceFile" ]]; then
289+
slatherCmd+=( --workspace $workspaceFile)
290+
fi
291+
slatherCmd+=( --scheme "$appScheme" $firstProject)
292+
293+
runCommand /dev/stdout "${slatherCmd[@]}"
294+
mv sonar-reports/cobertura.xml sonar-reports/coverage.xml
249295
fi
250-
buildCmd+=( -scheme "$appScheme" -configuration "$appConfiguration" -enableCodeCoverage YES)
251-
if [[ ! -z "$destinationSimulator" ]]; then
252-
buildCmd+=(-destination "$destinationSimulator" -destination-timeout 60)
253-
fi
254-
255-
runCommand sonar-reports/xcodebuild.log "${buildCmd[@]}"
256-
cat sonar-reports/xcodebuild.log | $XCPRETTY_CMD -t --report junit
257-
mv build/reports/junit.xml sonar-reports/TEST-report.xml
258-
259-
260-
echo -n 'Computing coverage report'
261-
262-
# Build the --exclude flags
263-
excludedCommandLineFlags=""
264-
if [ ! -z "$excludedPathsFromCoverage" -a "$excludedPathsFromCoverage" != " " ]; then
265-
echo $excludedPathsFromCoverage | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh2
266-
while read word; do
267-
excludedCommandLineFlags+=" -i $word"
268-
done < tmpFileRunSonarSh2
269-
rm -rf tmpFileRunSonarSh2
270-
fi
271-
if [ "$vflag" = "on" ]; then
272-
echo "Command line exclusion flags for slather is:$excludedCommandLineFlags"
273-
fi
274-
275-
projectArray=(${projectFile//,/ })
276-
firstProject=${projectArray[0]}
277-
278-
slatherCmd=($SLATHER_CMD coverage --input-format profdata $excludedCommandLineFlags --cobertura-xml --output-directory sonar-reports)
279-
if [[ ! -z "$workspaceFile" ]]; then
280-
slatherCmd+=( --workspace $workspaceFile)
281-
fi
282-
slatherCmd+=( --scheme "$appScheme" $firstProject)
283-
284-
runCommand /dev/stdout "${slatherCmd[@]}"
285-
mv sonar-reports/cobertura.xml sonar-reports/coverage.xml
286-
287296

288297
# SwiftLint
289298
if [ "$swiftlint" = "on" ]; then

0 commit comments

Comments
 (0)