Mercurial tests
This commit is contained in:
parent
c6de084cc4
commit
70eb9b7856
|
@ -0,0 +1,113 @@
|
|||
#! /usr/bin/env bats
|
||||
|
||||
# This is a test file for use with the bats testing framework
|
||||
# https://github.com/bats-core/bats-core
|
||||
# On Debian: apt install bats
|
||||
|
||||
function setup {
|
||||
ORIGDIR="$(pwd)"
|
||||
|
||||
# If no $FORGEBUILD is supplied in ENV, use the default
|
||||
# (otherwise you can't `bats ./tests/` manually)
|
||||
[ -z "$FORGEBUILD" ] && FORGEBUILD="forgebuild"
|
||||
|
||||
# Ensure output from previous test does not exist
|
||||
# (in case something crashed)
|
||||
clean
|
||||
|
||||
# Setup simple git repository
|
||||
REPO="$(mktemp -d)"
|
||||
cd $REPO
|
||||
hg init
|
||||
echo "first commit" > README
|
||||
hg add README
|
||||
hg commit -m "first commit"
|
||||
|
||||
# Setup forgebuild tasks
|
||||
FORGEBUILDDIR="$(mktemp -d)"
|
||||
echo "$REPO" > $FORGEBUILDDIR/time.source
|
||||
echo "mercurial" > $FORGEBUILDDIR/time.dvcs
|
||||
echo "date +%s%N > /tmp/forgebuild-time" > $FORGEBUILDDIR/time
|
||||
chmod +x $FORGEBUILDDIR/time
|
||||
echo "$REPO" > $FORGEBUILDDIR/host.source
|
||||
echo "mercurial" > $FORGEBUILDDIR/host.dvcs
|
||||
echo "cat \$GITBUILDCONF/entry > /tmp/forgebuild-host" > $FORGEBUILDDIR/host
|
||||
chmod +x $FORGEBUILDDIR/host
|
||||
echo "$REPO" > $FORGEBUILDDIR/branch.source
|
||||
echo "mercurial" > $FORGEBUILDDIR/branch.dvcs
|
||||
echo "cat \$GITBUILDDIR/.branch/branch > /tmp/forgebuild-branch" > $FORGEBUILDDIR/branch
|
||||
chmod +x $FORGEBUILDDIR/branch
|
||||
|
||||
# Setup settings
|
||||
mkdir $FORGEBUILDDIR/config
|
||||
echo "default" > $FORGEBUILDDIR/config/entry
|
||||
mkdir $FORGEBUILDDIR/$HOSTNAME
|
||||
echo "host" > $FORGEBUILDDIR/$HOSTNAME/entry
|
||||
}
|
||||
|
||||
function teardown {
|
||||
cd $ORIGDIR
|
||||
clean
|
||||
}
|
||||
|
||||
function clean {
|
||||
if [ -d $REPO ]; then rm -rf $GITREPO; fi
|
||||
if [ -d $FORGEBUILDDIR ]; then rm -rf $FORGEBUILDDIR; fi
|
||||
if [ -f /tmp/forgebuild-time ]; then rm /tmp/forgebuild-time; fi
|
||||
if [ -f /tmp/forgebuild-host ]; then rm /tmp/forgebuild-host; fi
|
||||
if [ -f /tmp/forgebuild-branch ]; then rm /tmp/forgebuild-branch; fi
|
||||
}
|
||||
|
||||
# Simple repository
|
||||
|
||||
@test "hg: repository is cloned" {
|
||||
$FORGEBUILD -b $FORGEBUILDDIR time
|
||||
[ -f $FORGEBUILDDIR/.time/README ]
|
||||
}
|
||||
|
||||
@test "hg: first run triggers task" {
|
||||
$FORGEBUILD -b $FORGEBUILDDIR time
|
||||
[ -f /tmp/forgebuild-time ]
|
||||
}
|
||||
|
||||
@test "hg: no update does not trigger task" {
|
||||
$FORGEBUILD -b $FORGEBUILDDIR time
|
||||
[ -f /tmp/forgebuild-time ]
|
||||
TIME="$(cat /tmp/forgebuild-time)"
|
||||
$FORGEBUILD -b $FORGEBUILDDIR time
|
||||
NEWTIME="$(cat /tmp/forgebuild-time)"
|
||||
[[ "$TIME" = "$NEWTIME" ]]
|
||||
}
|
||||
|
||||
@test "hg: update triggers task" {
|
||||
$FORGEBUILD -b $FORGEBUILDDIR time
|
||||
[ -f /tmp/forgebuild-time ]
|
||||
TIME="$(cat /tmp/forgebuild-time)"
|
||||
cd $REPO
|
||||
touch NEWFILE
|
||||
hg add NEWFILE
|
||||
hg commit -m "second commit"
|
||||
|
||||
$FORGEBUILD -b $FORGEBUILDDIR time
|
||||
NEWTIME="$(cat /tmp/forgebuild-time)"
|
||||
|
||||
[[ "$TIME" != "$NEWTIME" ]]
|
||||
}
|
||||
|
||||
@test "hg: can checkout to a specific branch/commit" {
|
||||
echo "branch" > $FORGEBUILDDIR/branch.checkout
|
||||
cd $REPO
|
||||
hg branch branch
|
||||
echo "branch" > branch
|
||||
hg add branch
|
||||
hg commit -m "new branch"
|
||||
hg update default
|
||||
$FORGEBUILD -b $FORGEBUILDDIR branch
|
||||
[[ "$(cat /tmp/forgebuild-branch)" = "branch" ]]
|
||||
}
|
||||
|
||||
@test "hg: repository unavailable fails to trigger task" {
|
||||
rm -Rf $REPO
|
||||
! $FORGEBUILD -b $FORGEBUILDDIR time
|
||||
[ ! -f /tmp/forgebuild-time ]
|
||||
}
|
Loading…
Reference in New Issue