From 03189bf62bbc91734c8e46d397028baa531fcda3 Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Wed, 20 Mar 2013 18:05:21 +0100 Subject: [PATCH 1/2] Implemented quoted strings support in hydra-build-products to allow file names with spaces + testcase --- src/lib/Hydra/Helper/AddBuilds.pm | 4 ++-- tests/evaluation-tests.pl | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index f554bb5c..aca8fb77 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -782,10 +782,10 @@ sub addBuildProducts { open LIST, "$outPath/nix-support/hydra-build-products" or die; while () { - /^([\w\-]+)\s+([\w\-]+)\s+(\S+)(\s+(\S+))?$/ or next; + /^([\w\-]+)\s+([\w\-]+)\s+("[^"]*"|\S+)(\s+(\S+))?$/ or next; my $type = $1; my $subtype = $2 eq "none" ? "" : $2; - my $path = File::Spec->canonpath($3); + my $path = File::Spec->canonpath((substr $3, 0, 1) eq "\"" ? substr $3, 1, -1 : $3); my $defaultPath = $5; # Ensure that the path exists and points into the Nix store. diff --git a/tests/evaluation-tests.pl b/tests/evaluation-tests.pl index 08e47b5c..2044c1be 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 => 60; +use Test::Simple tests => 68; hydra_setup($db); @@ -136,3 +136,25 @@ foreach my $scm ( @scminputs ) { ($loop, $updated) = updateRepository($scmName, $update, getcwd . "/$scmName-repo/"); } } + +# Test build products + +$jobset = createBaseJobset("build-products", "build-products.nix"); + +ok(evalSucceeds($jobset), "Evaluating jobs/build-products.nix should exit with return code 0"); +ok(nrQueuedBuildsForJobset($jobset) == 2 , "Evaluating jobs/build-products.nix should result in 2 builds"); + +for my $build (queuedBuildsForJobset($jobset)) { + ok(runBuild($build), "Build '".$build->job->name."' from jobs/build-products.nix should exit with code 0"); + my $newbuild = $db->resultset('Builds')->find($build->id); + ok($newbuild->finished == 1 && $newbuild->buildstatus == 0, "Build '".$build->job->name."' from jobs/build-products.nix should have buildstatus 0"); + + my $buildproducts = $db->resultset('BuildProducts')->search({ build => $build->id }); + my $buildproduct = $buildproducts->next; + + if($build->job->name eq "simple") { + ok($buildproduct->name eq "text.txt", "We should have text.txt, but found: ".$buildproduct->name."\n"); + } elsif ($build->job->name eq "with_spaces") { + ok($buildproduct->name eq "some text.txt", "We should have: \"some text.txt\", but found: ".$buildproduct->name."\n"); + } +} From 3884725bfd28c50792ecf542a97b95c1430c861a Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Wed, 20 Mar 2013 18:08:25 +0100 Subject: [PATCH 2/2] Added build product test files --- tests/jobs/build-product-simple.sh | 5 +++++ tests/jobs/build-product-with-spaces.sh | 5 +++++ tests/jobs/build-products.nix | 14 ++++++++++++++ 3 files changed, 24 insertions(+) create mode 100755 tests/jobs/build-product-simple.sh create mode 100755 tests/jobs/build-product-with-spaces.sh create mode 100644 tests/jobs/build-products.nix diff --git a/tests/jobs/build-product-simple.sh b/tests/jobs/build-product-simple.sh new file mode 100755 index 00000000..9cb0f784 --- /dev/null +++ b/tests/jobs/build-product-simple.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +mkdir -p $out/nix-support +echo "Hello" > $out/text.txt +echo "doc none $out/text.txt" > $out/nix-support/hydra-build-products diff --git a/tests/jobs/build-product-with-spaces.sh b/tests/jobs/build-product-with-spaces.sh new file mode 100755 index 00000000..1eb9482e --- /dev/null +++ b/tests/jobs/build-product-with-spaces.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +mkdir -p $out/nix-support +echo "Hello" > "$out/some text.txt" +echo "doc none \"$out/some text.txt\"" > $out/nix-support/hydra-build-products diff --git a/tests/jobs/build-products.nix b/tests/jobs/build-products.nix new file mode 100644 index 00000000..43c52db3 --- /dev/null +++ b/tests/jobs/build-products.nix @@ -0,0 +1,14 @@ +with import ./config.nix; +{ + simple = + mkDerivation { + name = "build-product-simple"; + builder = ./build-product-simple.sh; + }; + + with_spaces = + mkDerivation { + name = "build-product-with-spaces"; + builder = ./build-product-with-spaces.sh; + }; +}