From ca1d3c141a070c326387e35c2472bad42679d491 Mon Sep 17 00:00:00 2001 From: JAremko Date: Thu, 20 Apr 2017 06:00:04 +0300 Subject: [PATCH] Add spacefmt test to CI --- .travis-build.sh | 53 ++++++++++++++++++++++++++++-------- .travis.yml | 1 + core/tools/spacefmt/spacefmt | 35 +++++++++++++++++++++++- 3 files changed, 76 insertions(+), 13 deletions(-) diff --git a/.travis-build.sh b/.travis-build.sh index bcf624db6..89f726409 100755 --- a/.travis-build.sh +++ b/.travis-build.sh @@ -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 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)" diff --git a/.travis.yml b/.travis.yml index 43e0dec1b..a5829ae97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/core/tools/spacefmt/spacefmt b/core/tools/spacefmt/spacefmt index 2641779ac..027bb2514 100755 --- a/core/tools/spacefmt/spacefmt +++ b/core/tools/spacefmt/spacefmt @@ -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 ` 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