Add spacefmt test to CI

This commit is contained in:
JAremko 2017-04-20 06:00:04 +03:00 committed by syl20bnr
parent bb70793c75
commit ca1d3c141a
3 changed files with 76 additions and 13 deletions

View File

@ -17,6 +17,7 @@ if [ $USER != "travis" ]; then
exit 1
fi
# Make sure that PR doesn't target master branch
if [ $TRAVIS_SECURE_ENV_VARS = false ] &&
[ $TRAVIS_PULL_REQUEST != false ] &&
[ $TRAVIS_BRANCH = "master" ]; then
@ -28,22 +29,50 @@ if [ $TRAVIS_SECURE_ENV_VARS = false ] &&
echo "https://github.com/syl20bnr/spacemacs/blob/develop/CONTRIBUTING.org"
exit 1
fi
if [ "${FORMATTING}" = "space-test" ]; then
# Formatting conventions tests
if [ ! -z "$FORMATTING" ]; then
cd "${TRAVIS_BUILD_DIR}"
echo "Testing for trailing and all sorts of broken white spaces"
echo "TRAVIS_COMMIT_RANGE: ${TRAVIS_COMMIT_RANGE}"
first_commit=`echo ${TRAVIS_COMMIT_RANGE} | sed -r 's/\..*//'`
git reset -q "${first_commit}"
git diff --check --color > space_test_result
if [[ -s space_test_result ]]; then
cat space_test_result
exit 1
fi
echo "No bad spaces detected"
exit 0
git diff --name-only "${first_commit}" HEAD > /tmp/changed_files
case "${FORMATTING}" in
space-test)
echo "Testing for trailing and all sorts of broken white spaces"
git reset -q "${first_commit}"
git diff --check --color > space_test_result
if [[ -s space_test_result ]]; then
cat space_test_result
exit 1
fi
echo "No bad spaces detected"
exit 0
;;
spacefmt)
echo "Testing changed files with spacefmt"
rm -rf ~/.emacs.d
ln -sf `pwd` ~/.emacs.d
cp ~/.emacs.d/core/templates/.spacemacs.template ~/
mv ~/.spacemacs.template ~/.spacemacs
while read p
do
echo "Checking $p file"
./core/tools/spacefmt/spacefmt -f "$p"
if [ $? -ne 0 ]; then
echo "spacefmt exited with $?"
exit 2
fi
done </tmp/changed_files
git diff --color HEAD > spacefmt_result
if [[ -s spacefmt_result ]]; then
echo "Please apply these changes:"
cat spacefmt_result
exit 1
fi
echo "All changed files comply with spacefmt"
exit 0
;;
esac
fi
# Emacs tests
echo "Pwd $(pwd)"

View File

@ -20,6 +20,7 @@ env:
- TESTS=doc EVM_EMACS=emacs-25.1-travis
- TESTS=doc EVM_EMACS=emacs-git-snapshot-travis
- FORMATTING=space-test
- FORMATTING=spacefmt EVM_EMACS=emacs-25.1-travis
matrix:
fast_finish: true

View File

@ -6,10 +6,11 @@
# Authors: Eugene Yaremenko and Sylvain Benner
#
# Arguments:
# $1: action name can be `all`, `doc`, `config`
# $1: action name can be `all`, `doc`, `config` `-f`
# `doc` formats documentation files
# `config` format configuration files
# `all` performs all actions
# `-f <FILEPATH>` process FILEPATH file
# $2: if equal to `test` then use test files as input
# TODO a function to add headers to config.el, packages.el etc...
@ -37,6 +38,38 @@ if hash md5 2>/dev/null; then
mdfive="md5"
fi
if [[ $1 = "-f" ]]
then
before_md5="foo"
after_md5="bar"
while ! [ "$before_md5" = "$after_md5" ]
do
before_md5=$($mdfive "$2")
if [ ${2: -4} == ".org" ]
then
# Remove trailing delimiters in headlines
$seder -i 's/^\(*\+\s\+.*\)[;,.]$/\1/g' "$2"
# Remove trailing spaces
$seder -i 's/[ \t]*$//' "$2"
# Remove #+HTML_HEAD_EXTRA: ... readtheorg.css" />
$seder -i '/#+HTML_HEAD_EXTRA.*readtheorg.css.*/d' "$2"
# Replace multiply empty lines with a single empty line
$seder -i '/^$/N;/^\n$/D' "$2"
# Replace :TOC_4_org: with :TOC_4_gh:
$seder -i 's/:TOC_4_org:/:TOC_4_gh:/' "$2"
# apply toc-org
emacs -batch -l ./core/tools/spacefmt/spacefmt.el "$2" -f apply-all
fi
if [ ${2: -3} == ".el" ]
then
# migrate packages lists to config.el
emacs -batch -l ./core/tools/spacefmt/spacefmt.el "$2" -f move-packages-to-config
fi
# Calculate md5 of the files in $place after formating
after_md5=$($mdfive "$2")
done
exit 0
fi
if [[ $2 = "test" ]]
then