tests: move to t, allow yath test from root

By moving the tests subdirectory to t, we gain the ability to run `yath
test` with no arguments from inside `nix develop` in the root of the
the repo.

(`nix develop` is necessary in order to set the proper env vars for
`yath` to find our test libraries.)
This commit is contained in:
Cole Helbling
2021-03-04 23:35:57 -08:00
parent a8ec1b1afa
commit 025be052b7
56 changed files with 20 additions and 14 deletions

20
t/jobs/basic.nix Normal file
View File

@ -0,0 +1,20 @@
with import ./config.nix;
{
empty_dir =
mkDerivation {
name = "empty-dir";
builder = ./empty-dir-builder.sh;
};
fails =
mkDerivation {
name = "fails";
builder = ./fail.sh;
};
succeed_with_failed =
mkDerivation {
name = "succeed-with-failed";
builder = ./succeed-with-failed.sh;
};
}

View File

@ -0,0 +1,18 @@
with import ./config.nix;
let
jobs = {
build1 =
mkDerivation {
name = "build1";
builder = ./empty-dir-builder.sh;
};
build2 =
{ build1 }:
mkDerivation {
name = "build2";
builder = ./empty-dir-builder.sh;
inherit build1;
};
};
in jobs

5
t/jobs/build-product-simple.sh Executable file
View File

@ -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

View File

@ -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

14
t/jobs/build-products.nix Normal file
View File

@ -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;
};
}

View File

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

25
t/jobs/bzr-checkout-update.sh Executable file
View File

@ -0,0 +1,25 @@
#! /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
export BZR_HOME; # Set by the Makefile
case $state in
(0) echo "::Create repo. -- continue -- updated::"
bzr init bzr-repo
bzr whoami "build <build@invalid.org>" -d bzr-repo
touch bzr-repo/bzr-file
bzr add bzr-repo/bzr-file
bzr commit -m "add bzr-file" bzr-repo/bzr-file
ln -s bzr-repo bzr-checkout-repo
;;
(*) echo "::End. -- stop -- nothing::" ;;
esac
echo $(($state + 1)) > $STATE_FILE

10
t/jobs/bzr-input.nix Normal file
View File

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

25
t/jobs/bzr-update.sh Executable file
View File

@ -0,0 +1,25 @@
#! /bin/sh
set -e
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@invalid.org>" -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

9
t/jobs/config.nix.in Normal file
View File

@ -0,0 +1,9 @@
rec {
path = "@testPath@";
mkDerivation = args:
derivation ({
system = builtins.currentSystem;
PATH = path;
} // args);
}

10
t/jobs/darcs-input.nix Normal file
View File

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

24
t/jobs/darcs-update.sh Executable file
View File

@ -0,0 +1,24 @@
#! /bin/sh
set -e
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::"
mkdir darcs-repo
darcs init --repodir darcs-repo
touch darcs-repo/file
darcs add --repodir darcs-repo file
darcs record --repodir darcs-repo -a -l -m "add a file" file -A foobar@bar.bar
;;
(*) 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

10
t/jobs/deepgit-input.nix Normal file
View File

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

3
t/jobs/empty-dir-builder.sh Executable file
View File

@ -0,0 +1,3 @@
#! /bin/sh
mkdir $out

2
t/jobs/fail.sh Executable file
View File

@ -0,0 +1,2 @@
#! /bin/sh
exit 1

10
t/jobs/git-input.nix Normal file
View File

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

10
t/jobs/git-rev-input.nix Normal file
View File

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

31
t/jobs/git-rev-update.sh Executable file
View File

@ -0,0 +1,31 @@
#! /bin/sh
set -e
repo=git-repo
export HOME=$(pwd)
export XDG_CONFIG_HOME=$(pwd)/.config
STATE_FILE=$(pwd)/.git-rev-state
if test -e $STATE_FILE; then
state=1
rm $STATE_FILE
else
state=0
touch $STATE_FILE
fi
echo "STATE: $state"
case $state in
(0) echo "::Create repo. -- continue -- updated::"
git init $repo
cd $repo
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
touch foo
git add foo
GIT_AUTHOR_DATE="1970-01-01T00:00:00 +0000" GIT_COMMITTER_DATE="1970-01-01T00:00:00 +0000" git commit -m "Add foo"
;;
(*) echo "::End. -- stop -- nothing::"
rm -rf $repo
;;
esac

56
t/jobs/git-update.sh Executable file
View File

@ -0,0 +1,56 @@
#! /bin/sh
# This script is used both by git & deepgit checks.
set -e
repo=git-repo
export HOME=$(pwd)
export XDG_CONFIG_HOME=$(pwd)/.config
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
echo "STATE: $state"
case $state in
(0) echo "::Create repo. -- continue -- updated::"
git init $repo
cd $repo
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
touch foo
git add foo
git commit -m "Add foo"
git tag -a -m "First Tag." tag0
;;
(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
echo $(($state + 1)) > $STATE_FILE

10
t/jobs/hg-input.nix Normal file
View File

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

24
t/jobs/hg-update.sh Executable file
View File

@ -0,0 +1,24 @@
#! /bin/sh
set -e
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

33
t/jobs/runcommand.nix Normal file
View File

@ -0,0 +1,33 @@
with import ./config.nix;
{
metrics = (
mkDerivation {
name = "my-build-product";
builder = "/bin/sh";
outputs = [ "out" "bin" ];
args = [
(
builtins.toFile "builder.sh" ''
#! /bin/sh
echo "$PATH"
mkdir $bin
echo "foo" > $bin/bar
metrics=$out/nix-support/hydra-metrics
mkdir -p "$(dirname "$metrics")"
echo "lineCoverage 18 %" >> "$metrics"
echo "maxResident 27 KiB" >> "$metrics"
''
)
];
}
) // {
meta = {
license = "GPL";
description = "An example meta property.";
homepage = "https://github.com/NixOS/hydra";
};
};
}

3
t/jobs/scm-builder.sh Executable file
View File

@ -0,0 +1,3 @@
#! /bin/sh
mkdir $out
cp -v $src/* $out/

3
t/jobs/succeed-with-failed.sh Executable file
View File

@ -0,0 +1,3 @@
#! /bin/sh
mkdir -p $out/nix-support
touch $out/nix-support/failed

View File

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

24
t/jobs/svn-checkout-update.sh Executable file
View File

@ -0,0 +1,24 @@
#! /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::"
svnadmin create svn-repo
svn co file://$PWD/$repo svn-checkout
touch svn-checkout/svn-file
svn add svn-checkout/svn-file
svn commit -m "add svn file" svn-checkout/svn-file
ln -s svn-repo svn-checkout-repo
;;
(*) echo "::End. -- stop -- nothing::" ;;
esac
echo $(($state + 1)) > $STATE_FILE

10
t/jobs/svn-input.nix Normal file
View File

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

24
t/jobs/svn-update.sh Executable file
View File

@ -0,0 +1,24 @@
#! /bin/sh
set -e
repo=svn-repo
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 file://$PWD/$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