mirror of
https://gitlab.com/rensa-nix/core.git
synced 2026-02-01 23:05:08 +01:00
chore: add nixtest for testing and a couple of tests
This commit is contained in:
parent
e08c48b5db
commit
e6c13290bb
8 changed files with 281 additions and 0 deletions
90
tests/builder_test.nix
Normal file
90
tests/builder_test.nix
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
{
|
||||
pkgs,
|
||||
ntlib,
|
||||
rensa,
|
||||
...
|
||||
}: {
|
||||
suites."Builder" = {
|
||||
pos = __curPos;
|
||||
tests = [
|
||||
{
|
||||
name = "has system outputs";
|
||||
expected = true;
|
||||
actual = let
|
||||
testFlake = rensa.build {
|
||||
inputs = {};
|
||||
cellsFrom = ../cells;
|
||||
cellBlocks = with rensa.blocks; [
|
||||
(simple "test")
|
||||
];
|
||||
systems = ["x86_64-linux"];
|
||||
};
|
||||
in
|
||||
builtins.hasAttr "x86_64-linux" testFlake;
|
||||
}
|
||||
{
|
||||
name = "has ren metadata";
|
||||
expected = true;
|
||||
actual = let
|
||||
testFlake = rensa.build {
|
||||
inputs = {};
|
||||
cellsFrom = ../cells;
|
||||
cellBlocks = with rensa.blocks; [
|
||||
(simple "test")
|
||||
];
|
||||
systems = ["x86_64-linux"];
|
||||
};
|
||||
in
|
||||
builtins.hasAttr "__ren" testFlake;
|
||||
}
|
||||
{
|
||||
name = "merges outputs";
|
||||
expected = {
|
||||
packages = {
|
||||
test-package = "merged";
|
||||
};
|
||||
};
|
||||
actual = let
|
||||
testFlake =
|
||||
rensa.buildWith {
|
||||
inputs = {};
|
||||
cellsFrom = ../cells;
|
||||
cellBlocks = with rensa.blocks; [
|
||||
(simple "test")
|
||||
];
|
||||
systems = ["x86_64-linux"];
|
||||
} {
|
||||
packages = {
|
||||
test-package = "merged";
|
||||
};
|
||||
};
|
||||
in {
|
||||
packages = testFlake.packages;
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "eval test";
|
||||
type = "script";
|
||||
script = ''
|
||||
${ntlib.helpers.path [pkgs.gnugrep pkgs.coreutils pkgs.nix]}
|
||||
${ntlib.helpers.scriptHelpers}
|
||||
|
||||
result=$(nix eval --impure --expr '
|
||||
let
|
||||
rensa = import ${../lib} {lib = import ${pkgs.path}/lib;};
|
||||
testFlake = rensa.build {
|
||||
inputs = { test = "value"; };
|
||||
cellsFrom = ${../cells};
|
||||
cellBlocks = [];
|
||||
systems = [ "x86_64-linux" ];
|
||||
};
|
||||
in
|
||||
testFlake.__ren.__schema
|
||||
')
|
||||
|
||||
assert "$result == \"v0\"" "should contain version"
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
51
tests/filter_test.nix
Normal file
51
tests/filter_test.nix
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{rensa, ...}: {
|
||||
suites."Filter" = {
|
||||
pos = __curPos;
|
||||
tests = [
|
||||
{
|
||||
name = "filter by cell";
|
||||
expected = {
|
||||
x86_64-linux = {};
|
||||
};
|
||||
actual = let
|
||||
testFlake = {
|
||||
__ren = {
|
||||
cells = ["repo" "other"];
|
||||
};
|
||||
x86_64-linux = {
|
||||
repo = {
|
||||
docs = {value = "docs-value";};
|
||||
ci = {value = "ci-value";};
|
||||
};
|
||||
other = {
|
||||
packages = {value = "other-packages";};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
rensa.filter (_: cell: cell == "repo") testFlake [["*" "*"]];
|
||||
}
|
||||
{
|
||||
name = "filter by block";
|
||||
expected = {
|
||||
x86_64-linux = {};
|
||||
};
|
||||
actual = let
|
||||
testFlake = {
|
||||
__ren = {
|
||||
cells = ["repo"];
|
||||
};
|
||||
x86_64-linux = {
|
||||
repo = {
|
||||
docs = {value = "docs-value";};
|
||||
ci = {value = "ci-value";};
|
||||
packages = {value = "packages-value";};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
rensa.filter (block: _: block == "docs") testFlake [["repo" "*"]];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
57
tests/loader_test.nix
Normal file
57
tests/loader_test.nix
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
pkgs,
|
||||
ntlib,
|
||||
rensa,
|
||||
...
|
||||
}: {
|
||||
suites."Loader" = {
|
||||
pos = __curPos;
|
||||
tests = [
|
||||
{
|
||||
name = "cell sibling access";
|
||||
expected = {
|
||||
hello = "world";
|
||||
};
|
||||
actual = let
|
||||
testFlake = rensa.build {
|
||||
inputs = {};
|
||||
cellsFrom = ../cells;
|
||||
cellBlocks = with rensa.blocks; [
|
||||
(simple "test")
|
||||
];
|
||||
systems = ["x86_64-linux"];
|
||||
};
|
||||
in
|
||||
testFlake.x86_64-linux.test.test;
|
||||
}
|
||||
{
|
||||
name = "load file";
|
||||
type = "script";
|
||||
script = ''
|
||||
${ntlib.helpers.path [pkgs.gnugrep pkgs.coreutils pkgs.nix]}
|
||||
${ntlib.helpers.scriptHelpers}
|
||||
|
||||
mkdir -p "cells/testcell"
|
||||
echo '{ hello = "world"; }' > "cells/testcell/packages.nix"
|
||||
|
||||
cat > "flake.nix" << 'EOF'
|
||||
{
|
||||
outputs = inputs: let
|
||||
rensa = import ${../lib} { lib = import "${pkgs.path}/lib"; };
|
||||
in rensa.build {
|
||||
inputs = {};
|
||||
cellsFrom = ./cells;
|
||||
cellBlocks = with rensa.blocks; [ (simple "packages") ];
|
||||
systems = [ "x86_64-linux" ];
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
result=$(nix eval --impure .#x86_64-linux.testcell.packages.hello)
|
||||
|
||||
assert "$result == \"world\"" "should equal to world"
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
49
tests/select_test.nix
Normal file
49
tests/select_test.nix
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
{rensa, ...}: {
|
||||
suites."Select" = {
|
||||
pos = __curPos;
|
||||
tests = [
|
||||
{
|
||||
name = "single block";
|
||||
expected = {
|
||||
x86_64-linux = {value = "test-value";};
|
||||
};
|
||||
actual = let
|
||||
testFlake = {
|
||||
__ren = {
|
||||
cells = ["repo"];
|
||||
};
|
||||
x86_64-linux = {
|
||||
repo = {
|
||||
docs = {value = "test-value";};
|
||||
ci = {packages = {value = "ci-packages";};};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
rensa.select testFlake [["repo" "docs"]];
|
||||
}
|
||||
{
|
||||
name = "multiple blocks";
|
||||
expected = {
|
||||
x86_64-linux = {value = "ci-packages";};
|
||||
};
|
||||
actual = let
|
||||
testFlake = {
|
||||
__ren = {
|
||||
cells = ["repo"];
|
||||
};
|
||||
x86_64-linux = {
|
||||
repo = {
|
||||
ci = {packages = {value = "ci-packages";};};
|
||||
other = {value = "ignored";};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
rensa.select testFlake [
|
||||
["repo" "ci" "packages"]
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue