1. Graham Helliwell
  2. guestrepo

Source

guestrepo / tests / run.sh

The default branch has multiple heads

#!/usr/bin/env bash
# Guestrepo: A Mercurial Extension for the managing of components
# Copyright (C) 2012   Schweitzer Engineering Laboratories, Inc.

# 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; either version 2 of the License, or
# (at your option) any later version.

# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Contact information:

# opensource@selinc.com

# Schweitzer Engineering Laboratories, Inc.
# 2350 NE Hopkins Court
# Pullman, WA 99163 - USA


#  Guest repo test script
#
#  Run guestrepo tests using a certain version of python and mercurial
#

die()
{
   echo $1 > /dev/stderr
   exit 1
}

set -e

which cram || die "could not find cram. Is it installed?"


case $# in
   0)
      use_venv=false
      ;;
   2)
      use_venv=true
      ;;
   3)
      use_venv=true
      cache=$3
      ;;
   *)
      echo "Usage: run.sh [python-version mercurial-version [mercurial-cache]]" >> /dev/stderr
      exit 1
      ;;
esac

# keep track of the system python
test_python=`which python`

# Make a temporary hgrc for testing
export HGUSER=`whoami`
export HGRCPATH=`mktemp`
echo "[ui]" >> $HGRCPATH
echo username = jenkins >> $HGRCPATH
echo "[extensions]" >> $HGRCPATH
echo guestrepo = `readlink -f ../guestrepo` >> $HGRCPATH
echo bookmarks = >> $HGRCPATH
echo >> $HGRCPATH

if $use_venv
then
   # set up virtual environment
   envdir=`mktemp -d`
   virtualenv --python=$1 $envdir/venv

   # get mercurial
   hgdir=$envdir/mercurial
   mkdir $hgdir

   if [ $cache ]
   then
      # create or update the cache
      if [ ! -d $cache ]
      then
         hg clone http://selenic.com/hg $cache --noupdate --insecure
         touch $cache/lastpull
      else
         #http://stackoverflow.com/questions/205666/
         touch -d '-1 hour' $envdir/hourago
         if [ $envdir/hourago -nt $cache/lastpull ]; then
            set +e
            hg pull -R $cache --insecure
            touch $cache/lastpull
            set -e
         fi
      fi
      hgrepo=$cache
   else
      hgrepo="http://selenic.com/hg"
   fi
   hg clone $hgrepo $hgdir --updaterev $2

   # activate python virtualenv
   source $envdir/venv/bin/activate
   # compile mercurial
   pushd $hgdir
   make local
   #tests should use the recently compiled hg
   export PATH=$hgdir:$PATH
   popd
fi

#output some debug info
echo
echo '=============================================='
echo 'Guestrepo:'
hg id
echo "----------------------------------------------"
echo 'Python:'
which python
python -V
echo "----------------------------------------------"
echo 'Mercurial:'
which hg
hg version
echo "=============================================="
echo


$test_python `which cram` *.t