mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2026-02-02 03:15:12 +01:00
feat: add test helpers
default args to {}
This commit is contained in:
parent
001b575f31
commit
bed029f4a9
3 changed files with 59 additions and 1 deletions
|
|
@ -5,6 +5,8 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) evalModules toList;
|
inherit (lib) evalModules toList;
|
||||||
in rec {
|
in rec {
|
||||||
|
helpers = import ./testHelpers.nix {inherit lib;};
|
||||||
|
|
||||||
mkBinary = {
|
mkBinary = {
|
||||||
nixtests,
|
nixtests,
|
||||||
extraParams,
|
extraParams,
|
||||||
|
|
@ -46,7 +48,7 @@ in rec {
|
||||||
|
|
||||||
mkNixtestConfig = {
|
mkNixtestConfig = {
|
||||||
modules,
|
modules,
|
||||||
args,
|
args ? {},
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
(evalModules {
|
(evalModules {
|
||||||
|
|
|
||||||
51
lib/scriptHelpers.sh
Normal file
51
lib/scriptHelpers.sh
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
output=
|
||||||
|
exit_code=
|
||||||
|
|
||||||
|
function assert() {
|
||||||
|
test $1 || { echo "Assertion '$1' failed: $2" >&2; exit 1; }
|
||||||
|
}
|
||||||
|
function assert_eq() {
|
||||||
|
assert "$1 -eq $2" "$3"
|
||||||
|
}
|
||||||
|
function assert_not_eq() {
|
||||||
|
assert "$1 -ne $2" "$3"
|
||||||
|
}
|
||||||
|
function assert_contains() {
|
||||||
|
echo "$1" | grep -q -- "$2" || {
|
||||||
|
echo "Assertion failed: $3. $1 does not contain $2" >&2;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function assert_not_contains() {
|
||||||
|
echo "$1" | grep -q -- "$2" && {
|
||||||
|
echo "Assertion failed: $3. $1 does contain $2" >&2;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function assert_file_contains() {
|
||||||
|
grep -q -- "$2" $1 || {
|
||||||
|
echo "Assertion failed: $3. $1 does not contain $2" >&2;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function assert_file_not_contains() {
|
||||||
|
grep -q -- "$2" $1 && {
|
||||||
|
echo "Assertion failed: $3. $1 does contain $2" >&2;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tmpdir() {
|
||||||
|
dir=$(mktemp -d)
|
||||||
|
trap "rm -rf $dir" EXIT
|
||||||
|
echo -n "$dir"
|
||||||
|
}
|
||||||
|
function tmpfile() {
|
||||||
|
file=$(mktemp)
|
||||||
|
trap "rm -f $file" EXIT
|
||||||
|
echo -n "$file"
|
||||||
|
}
|
||||||
|
function run() {
|
||||||
|
output=$($@ 2>&1)
|
||||||
|
exit_code=$?
|
||||||
|
}
|
||||||
5
lib/testHelpers.nix
Normal file
5
lib/testHelpers.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{lib, ...}: {
|
||||||
|
path = pkgs: "export PATH=${lib.makeBinPath pkgs}";
|
||||||
|
pathAdd = pkgs: "export PATH=$PATH:${lib.makeBinPath pkgs}";
|
||||||
|
scriptHelpers = builtins.readFile ./scriptHelpers.sh;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue