From 27132bb9994a2b334963fc12f0dac92873fb1f58 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Wed, 11 Nov 2015 18:05:17 -0800 Subject: [PATCH] Add a makefile defining some common tasks. This makefile makes it easier to run things like unit tests and pylint against the code. Especially before doing a commit. It also helps ensure unit tests are not affected by local config files (e.g., ~/.xonshrc). --- Makefile | 47 ++++++++++++++++++++++++++++++++++++++++++++ scripts/run_tests.sh | 24 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Makefile create mode 100644 scripts/run_tests.sh diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..53d86aac2 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +SHELL = /bin/sh + +all: + @echo "You must specifiy a make target." + @echo "Targets are:" + @echo " clean" + @echo " lint" + @echo " lint-all" + @echo " test" + @echo " test-all" + @echo " build-tables" + +clean: + rm -f xonsh/lexer_table.py xonsh/parser_table.py + rm -f xonsh/lexer_test_table.py xonsh/parser_test_table.py + rm -f xonsh/*.pyc tests/*.pyc + rm -f xonsh/*.rej tests/*.rej + rm -fr build + +# Line just the changed python files. It doesn't matter if "git add" has +# already been done but obviously if you've already done "git commit" then +# they're no longer consider changed. This should be run (along with "make +# test") before commiting a set of changes. +lint: + pylint $$(git status -s | awk '/\.py$$/ { print $$2 }' | sort) + +# Lint all the python files. +lint-all: + make clean + pylint $$(find tests xonsh -name \*.py | sort) + +# Test just the changed python files. It doesn't matter if "git add" has +# already been done but obviously if you've already done "git commit" then +# they're no longer consider changed. This should be run (along with "make +# lint") before commiting a set of changes. +test: + scripts/run_tests.sh -e + +# Test all the python files. +test-all: + scripts/run_tests.sh + +# Build the parser_table.py module. This is normally done by setup.py at +# install time. This just makes it easy to create the parser module on the fly +# to facilitate development. +build-tables: + python3 -c 'import setup; setup.build_tables()' diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh new file mode 100644 index 000000000..f07dbe63f --- /dev/null +++ b/scripts/run_tests.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Run all the nosetests or just the ones relevant for the edited files. +# +if [[ $1 == "-e" ]]; then + tmp_file=$(mktemp /tmp/nose_tests_XXXXXX) + git status -s | + awk '/\.py$/ { print $2 }' | + while read f; do + if [[ $f == xonsh/* ]]; then + f="tests/test_$(basename $f)" + if [[ -f $f ]]; then + echo $f + fi + else + echo $f + fi + done | + sort -u > $tmp_file + XONSHRC=/dev/null nosetests -v $(< $tmp_file) + rm $tmp_file +else + XONSHRC=/dev/null nosetests +fi