Skip to content
Snippets Groups Projects
Commit ec56acb4 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'format_unit_test' into 'master'

Add testFormat

See merge request !599
parents d4c71d8b b82b6e1a
No related branches found
No related tags found
1 merge request!599Add testFormat
......@@ -1372,6 +1372,7 @@ AC_CONFIG_FILES([tests/testPeriodicBCPerturbed.sh], [chmod +x tests/testPeriodic
AC_CONFIG_FILES([tests/testInteractions.sh], [chmod +x tests/testInteractions.sh])
AC_CONFIG_FILES([tests/testParser.sh], [chmod +x tests/testParser.sh])
AC_CONFIG_FILES([tests/testSelectOutput.sh], [chmod +x tests/testSelectOutput.sh])
AC_CONFIG_FILES([tests/testFormat.sh], [chmod +x tests/testFormat.sh])
# Save the compilation options
AC_DEFINE_UNQUOTED([SWIFT_CONFIG_FLAGS],["$swift_config_flags"],[Flags passed to configure])
......
#!/bin/bash
clang-format-5.0 -style=file -i src/*.[ch] src/*/*.[ch] src/*/*/*.[ch] examples/main.c tests/*.[ch]
# Clang format command, can be overridden using CLANG_FORMAT_CMD.
# We currrently use version 5.0 so any overrides should provide that.
clang=${CLANG_FORMAT_CMD:="clang-format-5.0"}
# Formatting command
cmd="$clang -style=file src/*.[ch] src/*/*.[ch] src/*/*/*.[ch] examples/main.c tests/*.[ch]"
# Test if `clang-format-5.0` works
command -v $clang > /dev/null
if [[ $? -ne 0 ]]
then
echo "ERROR: cannot find $clang"
exit 1
fi
# Print the help
function show_help {
echo -e "This script formats SWIFT according to Google style"
echo -e " -h, --help \t Show this help"
echo -e " -t, --test \t Test if SWIFT is well formatted"
}
# Parse arguments (based on https://stackoverflow.com/questions/192249)
TEST=0
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
# print the help and exit
-h|--help)
show_help
exit
;;
# check if the code is well formatted
-t|--test)
TEST=1
shift
;;
# unknown option
*)
echo "Argument '$1' not implemented"
show_help
exit
;;
esac
done
# Run the required commands
if [[ $TEST -eq 1 ]]
then
# Note trapping the exit status from both commands in the pipe. Also note
# do not use -q in grep as that closes the pipe on first match and we get
# a SIGPIPE error.
echo "Testing if SWIFT is correctly formatted"
$cmd -output-replacements-xml | grep "<replacement " > /dev/null
status=("${PIPESTATUS[@]}")
# Trap if first command failed. Note 141 is SIGPIPE, that happens when no
# output
if [[ ${status[0]} -ne 0 ]]
then
echo "ERROR: $clang command failed"
exit 1
fi
# Check formatting
if [[ ${status[1]} -eq 0 ]]
then
echo "ERROR: needs formatting"
exit 1
else
echo "...is correctly formatted"
fi
else
echo "Formatting SWIFT"
$cmd -i
fi
......@@ -28,7 +28,7 @@ TESTS = testGreetings testMaths testReading.sh testSingle testKernel testSymmetr
testVoronoi1D testVoronoi2D testVoronoi3D testGravityDerivatives \
testPeriodicBC.sh testPeriodicBCPerturbed.sh testPotentialSelf \
testPotentialPair testEOS testUtilities testSelectOutput.sh \
testCbrt testCosmology testOutputList
testCbrt testCosmology testOutputList testFormat.sh
# List of test programs to compile
check_PROGRAMS = testGreetings testReading testSingle testTimeIntegration \
......
#!/bin/bash
set -e
cd @srcdir@/..
./format.sh --test
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment