tests.srcOnly: Add test cases for equivalences in the interface

This commit is contained in:
Robert Hensing 2025-03-01 22:45:57 +01:00 committed by Philip Taron
parent 734f17ad1f
commit af9b49edab
No known key found for this signature in database

View File

@ -1,28 +1,78 @@
{
runCommand,
srcOnly,
hello,
emptyDirectory,
glibc,
stdenv,
testers,
}:
let
emptySrc = srcOnly emptyDirectory;
glibcSrc = srcOnly glibc;
# It can be invoked in a number of ways. Let's make sure they're equivalent.
glibcSrcDrvAttrs = srcOnly glibc.drvAttrs;
# glibcSrcFreeform = # ???;
helloSrc = srcOnly hello;
helloSrcDrvAttrs = srcOnly hello.drvAttrs;
# The srcOnly <drv> invocation leaks a lot of attrs into the srcOnly derivation,
# so for comparing with the freeform invocation, we need to make a selection.
# Otherwise, we'll be comparing against whatever attribute the fancy hello drv
# has.
helloDrvSimple = stdenv.mkDerivation {
inherit (hello)
name
pname
version
src
patches
;
};
helloDrvSimpleSrc = srcOnly helloDrvSimple;
helloDrvSimpleSrcFreeform = srcOnly {
inherit (helloDrvSimple)
name
pname
version
src
patches
stdenv
;
};
in
runCommand "srcOnly-tests" { } ''
# Test that emptySrc is empty
if [ -n "$(ls -A ${emptySrc})" ]; then
echo "emptySrc is not empty"
exit 1
fi
runCommand "srcOnly-tests"
{
moreTests = [
(testers.testEqualDerivation "glibcSrcDrvAttrs == glibcSrc" glibcSrcDrvAttrs glibcSrc)
# (testers.testEqualDerivation
# "glibcSrcFreeform == glibcSrc"
# glibcSrcFreeform
# glibcSrc)
(testers.testEqualDerivation "helloSrcDrvAttrs == helloSrc" helloSrcDrvAttrs helloSrc)
(testers.testEqualDerivation "helloDrvSimpleSrcFreeform == helloDrvSimpleSrc"
helloDrvSimpleSrcFreeform
helloDrvSimpleSrc
)
];
}
''
# Test that emptySrc is empty
if [ -n "$(ls -A ${emptySrc})" ]; then
echo "emptySrc is not empty"
exit 1
fi
# Test that glibcSrc is not empty
if [ -z "$(ls -A ${glibcSrc})" ]; then
echo "glibcSrc is empty"
exit 1
fi
# Test that glibcSrc is not empty
if [ -z "$(ls -A ${glibcSrc})" ]; then
echo "glibcSrc is empty"
exit 1
fi
# Make $out exist to avoid build failure
mkdir -p $out
''
# Make $out exist to avoid build failure
mkdir -p $out
''