#!/bin/sh # # Run test suite for morph. # # Copyright (C) 2011-2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . set -e # Parse the command line. run_style=false run_unit_tests=false run_yarns=false snapshot='' if [ "$#" -eq 0 ]; then run_style=true run_unit_tests=true run_yarns=true fi while [ "$#" -gt 0 ] do case "$1" in --style) run_style=true ;; --no-style) run_style=false ;; --unit-tests) run_unit_tests=true ;; --no-unit-tests) run_unit_tests=false ;; --yarns) run_yarns=true ;; --no-yarns) run_yarns=false ;; --snapshot) snapshot='--snapshot' ;; --no-snapshot) snapshot='' ;; *) echo "ERROR: Unknown argument $1." 1>&2; exit 1 ;; esac shift done # Find and set tempdir from morph.conf or use /tmp if it does not # exist. Since the config file can be quite complicated, we use the # Python ConfigParser module to find TMPDIR. We append a folder called # testSuite to this so any existing files are not removed. TMPDIR=$( morph --dump-config | python -c ' import sys, ConfigParser cp = ConfigParser.RawConfigParser() cp.readfp(sys.stdin) try: print cp.get("config", "tempdir") except ConfigParser.NoOptionError: print "/tmp"' ) if [ "$TMPDIR" == "None" ]; then TMPDIR="/tmp" fi TMPDIR="$TMPDIR/testSuite" mkdir -p "$TMPDIR" TMPDIR=$(mktemp -d -p "$TMPDIR") export TMPDIR # Set PYTHONPATH to start with the current directory so that we always # find the right version of it for the test suite. case "$PYTHONPATH" in '') PYTHONPATH="$(pwd)" ;; *) PYTHONPATH="$(pwd):$PYTHONPATH" ;; esac export PYTHONPATH # Run the style checks if "$run_style" && [ -d .git ]; then echo "Checking copyright statements" if ! (git ls-files --cached -z | xargs -0r scripts/check-copyright-year); then exit 1 fi echo 'Checking source code for silliness' if ! (git ls-files --cached | grep -v '\.gz$' | grep -v '\.json-schema$' | grep -v 'yarns/xfce-system-dependencies' | xargs -r scripts/check-silliness); then exit 1 fi fi # Clean up artifacts from previous (possibly failed) runs, build, # and run the tests. if "$run_unit_tests"; then python setup.py clean check fi # Run scenario tests with yarn, if yarn is available. # # Yarn cleans up the environment when it runs tests, and this removes # PYTHONPATH from the environment. However, we need our tests to have # the PYTHONPATH, so that we can get them to, for example, use the right # versions of updated dependencies. The immediate current need is to # be able to get them to use an updated version of cliapp, but it is # a general need. # # We solve this by using the yarn --env option, allowing us to tell yarn # explicitly which environment variables to set in addition to the set # it sets anyway. if "$run_yarns" && command -v yarn > /dev/null then yarn --env "PYTHONPATH=$PYTHONPATH" --env "TMPDIR=$TMPDIR" $snapshot \ --tempdir "$TMPDIR" -s yarns/morph.shell-lib \ yarns/*.yarn fi