Commit 8ec2da6a authored by Loic Hausammann's avatar Loic Hausammann

Add testFormat

parent 91bb16c2
......@@ -1360,6 +1360,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 software name
clang="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 "Cannot find $clang"
exit 1
fi
set -e
# 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
echo "Testing Swift formatting"
$cmd -output-replacements-xml | grep -c "<replacement " >/dev/null
res=$?
# Check formatting
if [[ $res -ne 1 ]]
then
echo "Swift needs to be formatted"
exit 1
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment