From af9b49edab7bb92b319ff459c9ed52bd4a45f1ec Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 1 Mar 2025 22:45:57 +0100 Subject: [PATCH] tests.srcOnly: Add test cases for equivalences in the interface --- pkgs/build-support/src-only/tests.nix | 78 ++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/pkgs/build-support/src-only/tests.nix b/pkgs/build-support/src-only/tests.nix index 7ea7c23621be..51f5b4c96181 100644 --- a/pkgs/build-support/src-only/tests.nix +++ b/pkgs/build-support/src-only/tests.nix @@ -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 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 + ''