From 890a7867b47520f7d96d30463cb506c851bb32b0 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Wed, 16 Mar 2011 13:18:12 +0000 Subject: [PATCH] add first evaluations tests --- configure.ac | 5 +++-- tests/Makefile.am | 19 ++++++++++++------- tests/Setup.pm | 14 ++++++++++++++ tests/evaluation-tests.pl.in | 31 +++++++++++++++++++++++++++++++ tests/jobs/basic.nix | 23 +++++++++++++++++++++++ tests/jobs/empty-dir-builder.sh | 1 + tests/jobs/fail.sh | 1 + tests/jobs/succeed-with-failed.sh | 2 ++ 8 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 tests/Setup.pm create mode 100755 tests/evaluation-tests.pl.in create mode 100644 tests/jobs/basic.nix create mode 100644 tests/jobs/empty-dir-builder.sh create mode 100644 tests/jobs/fail.sh create mode 100644 tests/jobs/succeed-with-failed.sh diff --git a/configure.ac b/configure.ac index 6506a355..3cc262a9 100644 --- a/configure.ac +++ b/configure.ac @@ -36,8 +36,8 @@ LIBS="-L$nix/lib/nix" AC_CHECK_HEADER([store-api.hh], [:], [AC_MSG_ERROR([Nix headers not found; please install Nix or check the `--with-nix' option.])]) -AC_CHECK_LIB([expr], [_ZN3nix17parseExprFromFileERNS_9EvalStateESs], [:], - [AC_MSG_ERROR([Nix library not found; please install Nix or check the `--with-nix' option.])]) +#AC_CHECK_LIB([expr], [_ZN3nix17parseExprFromFileERNS_9EvalStateESs], [:], +# [AC_MSG_ERROR([Nix library not found; please install Nix or check the `--with-nix' option.])]) CPPFLAGS="$old_CPPFLAGS" LIBS="$old_LIBS" @@ -67,6 +67,7 @@ AC_CONFIG_FILES([ tests/Makefile tests/query-all-tables.pl + tests/evaluation-tests.pl ]) AC_OUTPUT diff --git a/tests/Makefile.am b/tests/Makefile.am index d323dbaa..764a25da 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,19 +1,24 @@ - +TESTDIR=`pwd` TESTS_ENVIRONMENT = \ HYDRA_DBI="dbi:SQLite:db.sqlite" \ - HYDRA_DATA="$(top_srcdir)/tests/data" \ + HYDRA_DATA="$(TESTDIR)/data" \ HYDRA_HOME="$(topsrc_dir)/src" \ NIX_REMOTE= \ - NIX_STATE_DIR=$(top_srcdir)/tests/nix/var \ - NIX_DATA_DIR=$(top_srcdir)/tests/nix/var \ - NIX_STORE_DIR=$(top_srcdir)/tests/nix/store \ + NIX_STATE_DIR="$(TESTDIR)/nix/var/nix" \ + NIX_STORE_DIR="$(TESTDIR)/nix/store" \ + NIX_LOG_DIR="$(TESTDIR)/nix/var/log/nix" \ PERL5LIB=$$PERL5LIB:$(top_srcdir)/src/lib \ perl -w TESTS = \ - query-all-tables.pl + query-all-tables.pl \ + evaluation-tests.pl -$(TESTS) : db.sqlite dirs +clean : + chmod -R a+w nix + rm -rf db.sqlite data nix + +$(TESTS) : clean db.sqlite dirs db.sqlite : $(top_srcdir)/src/sql/hydra-sqlite.sql sqlite3 db.sqlite < $(top_srcdir)/src/sql/hydra-sqlite.sql diff --git a/tests/Setup.pm b/tests/Setup.pm new file mode 100644 index 00000000..209f8715 --- /dev/null +++ b/tests/Setup.pm @@ -0,0 +1,14 @@ +package Setup; + +use strict; +use Exporter; + +our @ISA = qw(Exporter); +our @EXPORT = qw(hydra_setup); + +sub hydra_setup { + my ($db) = @_; + $db->resultset('Users')->create({ username => "root", emailaddress => 'root@email.com', password => '' }); +} + +1; diff --git a/tests/evaluation-tests.pl.in b/tests/evaluation-tests.pl.in new file mode 100755 index 00000000..59903bad --- /dev/null +++ b/tests/evaluation-tests.pl.in @@ -0,0 +1,31 @@ +#! @perl@ -w -I@nix@/libexec/nix + +use strict; +use Hydra::Schema; +use Hydra::Helper::Nix; +use Hydra::Helper::AddBuilds; +use Cwd; + +use Setup; + +my $db = openHydraDB; + +use Test::Simple tests => 1; + +hydra_setup($db); + +my $res; +my $stdout; +my $stderr; + +my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"}); +my $jobset = $project->jobsets->create({name => "basic", nixexprinput => "input", nixexprpath => "basic.nix", emailoverride => ""}); +my $jobsetinput = $jobset->jobsetinputs->create({name => "input", type => "path"}); +my $jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"}); + +($res, $stdout, $stderr) = captureStdoutStderr(60, ("../src/script/hydra_evaluator.pl", "tests", "basic")); + +ok($res, "Evaluating jobs/basic.nix should exit with return code 0"); + +print STDERR "\n$res\n"; + diff --git a/tests/jobs/basic.nix b/tests/jobs/basic.nix new file mode 100644 index 00000000..c5343076 --- /dev/null +++ b/tests/jobs/basic.nix @@ -0,0 +1,23 @@ +{ input }: +{ + empty_dir = + derivation { + name = "empty-dir"; + system = builtins.currentSystem; + builder = ./empty-dir-builder.sh; + }; + + fails = + derivation { + name = "fails"; + system = builtins.currentSystem; + builder = ./fail.sh; + }; + + succeed_with_failed = + derivation { + name = "succeed-with-failed"; + system = builtins.currentSystem; + builder = ./succeed-with-failed.sh; + }; +} diff --git a/tests/jobs/empty-dir-builder.sh b/tests/jobs/empty-dir-builder.sh new file mode 100644 index 00000000..03697d30 --- /dev/null +++ b/tests/jobs/empty-dir-builder.sh @@ -0,0 +1 @@ +mkdir $out diff --git a/tests/jobs/fail.sh b/tests/jobs/fail.sh new file mode 100644 index 00000000..379a4c98 --- /dev/null +++ b/tests/jobs/fail.sh @@ -0,0 +1 @@ +exit 1 diff --git a/tests/jobs/succeed-with-failed.sh b/tests/jobs/succeed-with-failed.sh new file mode 100644 index 00000000..ad1be8e5 --- /dev/null +++ b/tests/jobs/succeed-with-failed.sh @@ -0,0 +1,2 @@ +mkdir -p $out/nix-support/failed +