Skip to content

Commit

Permalink
Add testFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
loikki committed Aug 23, 2018
1 parent 91bb16c commit 8ec2da6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
68 changes: 67 additions & 1 deletion format.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@
#!/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
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 6 additions & 0 deletions tests/testFormat.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e

cd @srcdir@/..
./format.sh --test

0 comments on commit 8ec2da6

Please sign in to comment.