Merge pull request #9 from nbp/deep-clone-check

Add tests for "git describe --long".
This commit is contained in:
Rob Vermaas 2012-04-30 01:15:00 -07:00
commit c1653a9561
11 changed files with 242 additions and 64 deletions

View file

@ -33,7 +33,7 @@ check_SCRIPTS = db.sqlite repos
db.sqlite : $(top_srcdir)/src/sql/hydra-sqlite.sql db.sqlite : $(top_srcdir)/src/sql/hydra-sqlite.sql
$(TESTS_ENVIRONMENT) $(top_srcdir)/src/script/hydra-init $(TESTS_ENVIRONMENT) $(top_srcdir)/src/script/hydra-init
repos : dirs git-repo hg-repo svn-repo svn-checkout-repo bzr-repo bzr-checkout-repo repos : dirs
dirs : dirs :
mkdir -p data mkdir -p data
@ -43,34 +43,3 @@ dirs :
touch nix/etc/nix/nix.conf touch nix/etc/nix/nix.conf
mkdir -p nix/store mkdir -p nix/store
mkdir -p nix/var mkdir -p nix/var
git-repo :
git init git-repo
touch git-repo/git-file
(cd git-repo; git add git-file ; git commit -m "add git file" git-file)
hg-repo :
hg init hg-repo
touch hg-repo/hg-file
(cd hg-repo; hg add hg-file ; hg commit -m "add hg file" hg-file -u foobar)
svn-repo :
svnadmin create svn-repo
svn co file://$(abs_builddir)/svn-repo svn-checkout
touch svn-checkout/svn-file
svn add svn-checkout/svn-file
svn commit -m "add svn file" svn-checkout/svn-file
bzr-repo :
bzr init bzr-repo
BZR_HOME=$(abs_builddir)/data bzr whoami "build <build@donotemail.com>" -d bzr-repo
touch bzr-repo/bzr-file
bzr add bzr-repo/bzr-file
BZR_HOME=$(abs_builddir)/data bzr commit -m "add bzr-file" bzr-repo/bzr-file
svn-checkout-repo :
ln -s svn-repo svn-checkout-repo
bzr-checkout-repo :
ln -s bzr-repo bzr-checkout-repo

View file

@ -75,11 +75,12 @@ sub runBuild {
} }
sub updateRepository { sub updateRepository {
my ($scm, $update, $repo) = @_; my ($scm, $update) = @_;
my ($res, $stdout, $stderr) = captureStdoutStderr(60, ($update, $repo)); my ($res, $stdout, $stderr) = captureStdoutStderr(60, ($update, $scm));
die "Unexpected update error with $scm: $stderr\n" unless $res; die "Unexpected update error with $scm: $stderr\n" unless $res;
print STDOUT "Update $scm repository: $stdout" if $stdout ne ""; my ($message, $loop, $status) = $stdout =~ m/::(.*) -- (.*) -- (.*)::/;
return $stdout ne ""; print STDOUT "Update $scm repository: $message\n";
return ($loop eq "continue", $status eq "updated");
} }
1; 1;

View file

@ -7,7 +7,7 @@ use Setup;
my $db = Hydra::Model::DB->new; my $db = Hydra::Model::DB->new;
use Test::Simple tests => 48; use Test::Simple tests => 60;
hydra_setup($db); hydra_setup($db);
@ -53,21 +53,86 @@ for my $build (queuedBuildsForJobset($jobset)) {
# Test scm inputs # Test scm inputs
my @scminputs = ("svn", "svn-checkout", "git", "bzr", "bzr-checkout", "hg"); my @scminputs = (
foreach my $scm (@scminputs) { {
$jobset = createJobsetWithOneInput($scm, "$scm-input.nix", "src", $scm, "$jobsBaseUri/$scm-repo"); name => "svn",
nixexpr => "svn-input.nix",
type => "svn",
uri => "$jobsBaseUri/svn-repo",
update => getcwd . "/jobs/svn-update.sh"
},
{
name => "svn-checkout",
nixexpr => "svn-checkout-input.nix",
type => "svn-checkout",
uri => "$jobsBaseUri/svn-checkout-repo",
update => getcwd . "/jobs/svn-checkout-update.sh"
},
{
name => "git",
nixexpr => "git-input.nix",
type => "git",
uri => "$jobsBaseUri/git-repo",
update => getcwd . "/jobs/git-update.sh"
},
{
name => "deepgit",
nixexpr => "deepgit-input.nix",
type => "git",
uri => "$jobsBaseUri/git-repo master 1",
update => getcwd . "/jobs/git-update.sh"
},
{
name => "bzr",
nixexpr => "bzr-input.nix",
type => "bzr",
uri => "$jobsBaseUri/bzr-repo",
update => getcwd . "/jobs/bzr-update.sh"
},
{
name => "bzr-checkout",
nixexpr => "bzr-checkout-input.nix",
type => "bzr-checkout",
uri => "$jobsBaseUri/bzr-checkout-repo",
update => getcwd . "/jobs/bzr-checkout-update.sh"
},
{
name => "hg",
nixexpr => "hg-input.nix",
type => "hg",
uri => "$jobsBaseUri/hg-repo",
update => getcwd . "/jobs/hg-update.sh"
}
);
my $c = 1; foreach my $scm ( @scminputs ) {
my $q = 1; my $scmName = $scm->{"name"};
do { my $nixexpr = $scm->{"nixexpr"};
# Verify that it can be fetched and queued. my $type = $scm->{"type"};
ok(evalSucceeds($jobset), "$c Evaluating jobs/$scm-input.nix should exit with return code 0."); $c++; my $uri = $scm->{"uri"};
ok(nrQueuedBuildsForJobset($jobset) == $q, "$c Evaluating jobs/$scm-input.nix should result in 1 build in queue"); $c++; my $update = $scm->{"update"};
$jobset = createJobsetWithOneInput($scmName, $nixexpr, "src", $type, $uri);
# Verify that it is deterministic and not queued again. my $state = 0;
ok(evalSucceeds($jobset), "$c Evaluating jobs/$scm-input.nix should exit with return code 0."); $c++; my $q = 0;
ok(nrQueuedBuildsForJobset($jobset) == $q, "$c Evaluating jobs/$scm-input.nix should result in $q build in queue"); $c++; my ($loop, $updated) = updateRepository($scmName, $update);
while($loop) {
my $c = 0;
$q++; # Verify that it can be fetched and possibly queued.
} while(updateRepository($scm, getcwd . "/jobs/$scm-update.sh", getcwd . "/$scm-repo/")); ok(evalSucceeds($jobset), "$scmName:$state.$c: Evaluating nix-expression."); $c++;
# Verify that the evaluation has queued a new job and evaluate again to ...
if ($updated) {
$q++;
ok(nrQueuedBuildsForJobset($jobset) == $q, "$scmName:$state.$c: Expect $q jobs in the queue."); $c++;
ok(evalSucceeds($jobset), "$scmName:$state.$c: Evaluating nix-expression again."); $c++;
}
# ... check that it is deterministic and not queued again.
ok(nrQueuedBuildsForJobset($jobset) == $q, "$scmName:$state.$c: Expect $q jobs in the queue."); $c++;
$state++;
($loop, $updated) = updateRepository($scmName, $update, getcwd . "/$scmName-repo/");
}
} }

View file

@ -1 +1,19 @@
#! /bin/sh #! /bin/sh
repo="$1"
STATE_FILE=$(pwd)/.bzr-checkout-state
if test -e $STATE_FILE; then
state=$(cat $STATE_FILE)
test $state -gt 1 && state=0
else
state=0;
fi
case $state in
(0) echo "::Create repo. -- continue -- updated::"
ln -s bzr-repo bzr-checkout-repo
;;
(*) echo "::End. -- stop -- nothing::" ;;
esac
echo $(($state + 1)) > $STATE_FILE

View file

@ -1 +1,24 @@
#! /bin/sh #! /bin/sh
repo="$1"
STATE_FILE=$(pwd)/.bzr-state
if test -e $STATE_FILE; then
state=$(cat $STATE_FILE)
test $state -gt 1 && state=0
else
state=0;
fi
export BZR_HOME; # Set by the Makefile
case $state in
(0) echo "::Create repo. -- continue -- updated::"
bzr init bzr-repo
bzr whoami "build <build@donotemail.com>" -d bzr-repo
touch bzr-repo/bzr-file
bzr add bzr-repo/bzr-file
bzr commit -m "add bzr-file" bzr-repo/bzr-file
;;
(*) echo "::End. -- stop -- nothing::";;
esac
echo $(($state + 1)) > $STATE_FILE

View file

@ -0,0 +1,6 @@
#! /bin/sh
set -e
mkdir $out
cp -v $src/* $out/
git describe --long > $out/Version

View file

@ -0,0 +1,10 @@
with import ./config.nix;
{ src }:
{
copy =
mkDerivation {
name = "git-input";
builder = ./scm-builder.sh;
inherit src;
};
}

View file

@ -1,25 +1,49 @@
#! /bin/sh #! /bin/sh
# This script is used both by git & deepgit checks.
cd "$1" repo=git-repo
STATE_FILE=.state STATE_FILE=$(pwd)/.git-state
if test -e $STATE_FILE; then if test -e $STATE_FILE; then
state=$(cat $STATE_FILE) state=$(cat $STATE_FILE)
test $state -gt 3 && state=0
else else
state=0; state=0;
fi fi
case $state in case $state in
(0) (0) echo "::Create repo. -- continue -- updated::"
echo "Add new file." git init $repo
touch git-file-2 cd $repo
git add git-file-2 >&2 touch foo
git commit -m "add git file 2" git-file-2 >&2 git add foo
git commit -m "Add foo"
git tag -a -m "First Tag." tag0
git checkout -b master HEAD
;; ;;
(1) (1) echo "::Create new commit. -- continue -- updated::"
echo "Rewrite commit." cd $repo
echo 1 > git-file-2 # Increase depth to make sure the tag is not fetched by default.
git add git-file-2 >&2 echo 0 > foo
git commit --amend -m "add git file 2" git-file-2 >&2 git add foo
git commit -m "Increase depth 0"
echo 1 > foo
git add foo
git commit -m "Increase depth 1"
echo 2 > foo
git add foo
git commit -m "Increase depth 2"
echo 0 > bar
git add bar
git commit -m "Add bar with 0"
;;
(2) echo "::Amend commit. (push -f) -- continue -- updated::"
cd $repo
echo 1 > bar
git add bar
git commit --amend -m "Add bar with 1"
;;
(*) echo "::End. -- stop -- nothing::"
rm -rf $repo
;; ;;
esac esac

View file

@ -1 +1,23 @@
#! /bin/sh #! /bin/sh
repo="$1"
STATE_FILE=$(pwd)/.hg-state
if test -e $STATE_FILE; then
state=$(cat $STATE_FILE)
test $state -gt 1 && state=0
else
state=0;
fi
case $state in
(0) echo "::Create repo. -- continue -- updated::"
hg init hg-repo
touch hg-repo/hg-file
cd hg-repo
hg add hg-file
hg commit -m "add hg file" hg-file -u foobar
;;
(*) echo "::End. -- stop -- nothing::" ;;
esac
echo $(($state + 1)) > $STATE_FILE

View file

@ -1 +1,19 @@
#! /bin/sh #! /bin/sh
repo="$1"
STATE_FILE=$(pwd)/.svn-checkout-state
if test -e $STATE_FILE; then
state=$(cat $STATE_FILE)
test $state -gt 1 && state=0
else
state=0;
fi
case $state in
(0) echo "::Create repo. -- continue -- updated::"
ln -s svn-repo svn-checkout-repo
;;
(*) echo "::End. -- stop -- nothing::" ;;
esac
echo $(($state + 1)) > $STATE_FILE

View file

@ -1 +1,23 @@
#! /bin/sh #! /bin/sh
repo="$1"
STATE_FILE=$(pwd)/.svn-state
if test -e $STATE_FILE; then
state=$(cat $STATE_FILE)
test $state -gt 1 && state=0
else
state=0;
fi
case $state in
(0) echo "::Create repo. -- continue -- updated::"
svnadmin create svn-repo
svn co $repo svn-checkout
touch svn-checkout/svn-file
svn add svn-checkout/svn-file
svn commit -m "add svn file" svn-checkout/svn-file
;;
(*) echo "::End. -- stop -- nothing::";;
esac
echo $(($state + 1)) > $STATE_FILE