From 69f9175986597490c973aa90cec36dbddf58bd1d Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 29 Apr 2012 20:59:43 -0700 Subject: [PATCH] Add tests for "git describe --long". * Move test logic to scm-update.sh scripts. * Check for "git describe --long". --- tests/Makefile.am | 33 +---------- tests/Setup.pm | 9 +-- tests/evaluation-tests.pl | 97 ++++++++++++++++++++++++++----- tests/jobs/bzr-checkout-update.sh | 18 ++++++ tests/jobs/bzr-update.sh | 23 ++++++++ tests/jobs/deepgit-builder.sh | 6 ++ tests/jobs/deepgit-input.nix | 10 ++++ tests/jobs/git-update.sh | 48 +++++++++++---- tests/jobs/hg-update.sh | 22 +++++++ tests/jobs/svn-checkout-update.sh | 18 ++++++ tests/jobs/svn-update.sh | 22 +++++++ 11 files changed, 242 insertions(+), 64 deletions(-) create mode 100644 tests/jobs/deepgit-builder.sh create mode 100644 tests/jobs/deepgit-input.nix diff --git a/tests/Makefile.am b/tests/Makefile.am index 464d8141..ae2a1d73 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,7 +33,7 @@ check_SCRIPTS = db.sqlite repos db.sqlite : $(top_srcdir)/src/sql/hydra-sqlite.sql $(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 : mkdir -p data @@ -43,34 +43,3 @@ dirs : touch nix/etc/nix/nix.conf mkdir -p nix/store 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 " -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 - diff --git a/tests/Setup.pm b/tests/Setup.pm index 551c1683..3643a891 100644 --- a/tests/Setup.pm +++ b/tests/Setup.pm @@ -75,11 +75,12 @@ sub runBuild { } sub updateRepository { - my ($scm, $update, $repo) = @_; - my ($res, $stdout, $stderr) = captureStdoutStderr(60, ($update, $repo)); + my ($scm, $update) = @_; + my ($res, $stdout, $stderr) = captureStdoutStderr(60, ($update, $scm)); die "Unexpected update error with $scm: $stderr\n" unless $res; - print STDOUT "Update $scm repository: $stdout" if $stdout ne ""; - return $stdout ne ""; + my ($message, $loop, $status) = $stdout =~ m/::(.*) -- (.*) -- (.*)::/; + print STDOUT "Update $scm repository: $message\n"; + return ($loop eq "continue", $status eq "updated"); } 1; diff --git a/tests/evaluation-tests.pl b/tests/evaluation-tests.pl index f01cb593..55dac24b 100755 --- a/tests/evaluation-tests.pl +++ b/tests/evaluation-tests.pl @@ -7,7 +7,7 @@ use Setup; my $db = Hydra::Model::DB->new; -use Test::Simple tests => 48; +use Test::Simple tests => 60; hydra_setup($db); @@ -52,22 +52,87 @@ for my $build (queuedBuildsForJobset($jobset)) { } -# Test scm inputs -my @scminputs = ("svn", "svn-checkout", "git", "bzr", "bzr-checkout", "hg"); -foreach my $scm (@scminputs) { - $jobset = createJobsetWithOneInput($scm, "$scm-input.nix", "src", $scm, "$jobsBaseUri/$scm-repo"); +# Test scm inputs +my @scminputs = ( + { + 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; - my $q = 1; - do { - # Verify that it can be fetched and queued. - ok(evalSucceeds($jobset), "$c Evaluating jobs/$scm-input.nix should exit with return code 0."); $c++; - ok(nrQueuedBuildsForJobset($jobset) == $q, "$c Evaluating jobs/$scm-input.nix should result in 1 build in queue"); $c++; +foreach my $scm ( @scminputs ) { + my $scmName = $scm->{"name"}; + my $nixexpr = $scm->{"nixexpr"}; + my $type = $scm->{"type"}; + my $uri = $scm->{"uri"}; + my $update = $scm->{"update"}; + $jobset = createJobsetWithOneInput($scmName, $nixexpr, "src", $type, $uri); - # Verify that it is deterministic and not queued again. - ok(evalSucceeds($jobset), "$c Evaluating jobs/$scm-input.nix should exit with return code 0."); $c++; - ok(nrQueuedBuildsForJobset($jobset) == $q, "$c Evaluating jobs/$scm-input.nix should result in $q build in queue"); $c++; + my $state = 0; + my $q = 0; + my ($loop, $updated) = updateRepository($scmName, $update); + while($loop) { + my $c = 0; - $q++; - } while(updateRepository($scm, getcwd . "/jobs/$scm-update.sh", getcwd . "/$scm-repo/")); + # Verify that it can be fetched and possibly queued. + 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/"); + } } diff --git a/tests/jobs/bzr-checkout-update.sh b/tests/jobs/bzr-checkout-update.sh index 50d48845..0aaeca14 100755 --- a/tests/jobs/bzr-checkout-update.sh +++ b/tests/jobs/bzr-checkout-update.sh @@ -1 +1,19 @@ #! /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 diff --git a/tests/jobs/bzr-update.sh b/tests/jobs/bzr-update.sh index 50d48845..f269fe3f 100755 --- a/tests/jobs/bzr-update.sh +++ b/tests/jobs/bzr-update.sh @@ -1 +1,24 @@ #! /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 " -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 diff --git a/tests/jobs/deepgit-builder.sh b/tests/jobs/deepgit-builder.sh new file mode 100644 index 00000000..60a31294 --- /dev/null +++ b/tests/jobs/deepgit-builder.sh @@ -0,0 +1,6 @@ +#! /bin/sh + +set -e +mkdir $out +cp -v $src/* $out/ +git describe --long > $out/Version diff --git a/tests/jobs/deepgit-input.nix b/tests/jobs/deepgit-input.nix new file mode 100644 index 00000000..14552fc3 --- /dev/null +++ b/tests/jobs/deepgit-input.nix @@ -0,0 +1,10 @@ +with import ./config.nix; +{ src }: +{ + copy = + mkDerivation { + name = "git-input"; + builder = ./scm-builder.sh; + inherit src; + }; +} diff --git a/tests/jobs/git-update.sh b/tests/jobs/git-update.sh index f5631a87..10967d3a 100755 --- a/tests/jobs/git-update.sh +++ b/tests/jobs/git-update.sh @@ -1,25 +1,49 @@ #! /bin/sh +# This script is used both by git & deepgit checks. -cd "$1" -STATE_FILE=.state +repo=git-repo +STATE_FILE=$(pwd)/.git-state if test -e $STATE_FILE; then state=$(cat $STATE_FILE) + test $state -gt 3 && state=0 else state=0; fi case $state in - (0) - echo "Add new file." - touch git-file-2 - git add git-file-2 >&2 - git commit -m "add git file 2" git-file-2 >&2 + (0) echo "::Create repo. -- continue -- updated::" + git init $repo + cd $repo + touch foo + git add foo + git commit -m "Add foo" + git tag -a -m "First Tag." tag0 + git checkout -b master HEAD ;; - (1) - echo "Rewrite commit." - echo 1 > git-file-2 - git add git-file-2 >&2 - git commit --amend -m "add git file 2" git-file-2 >&2 + (1) echo "::Create new commit. -- continue -- updated::" + cd $repo + # Increase depth to make sure the tag is not fetched by default. + echo 0 > foo + 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 diff --git a/tests/jobs/hg-update.sh b/tests/jobs/hg-update.sh index 50d48845..9d1a67e0 100755 --- a/tests/jobs/hg-update.sh +++ b/tests/jobs/hg-update.sh @@ -1 +1,23 @@ #! /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 diff --git a/tests/jobs/svn-checkout-update.sh b/tests/jobs/svn-checkout-update.sh index 50d48845..7aa6c868 100755 --- a/tests/jobs/svn-checkout-update.sh +++ b/tests/jobs/svn-checkout-update.sh @@ -1 +1,19 @@ #! /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 diff --git a/tests/jobs/svn-update.sh b/tests/jobs/svn-update.sh index 50d48845..65b4ae13 100755 --- a/tests/jobs/svn-update.sh +++ b/tests/jobs/svn-update.sh @@ -1 +1,23 @@ #! /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