12 inherit (lib.fetchers) normalizeHash withNormalizedHash;
14 testingThrow = expr: {
15 expr = with builtins; tryEval (seq expr "didn't throw");
23 sri256 = "sha256-d6xi4mKdjkX2JFicDIv5niSzpyI0m/Hnm8GGAIU04kY=";
24 sri512 = "sha512-AXFyVo7jiZ5we10fxZ5E9qfPjSfqkizY2apCzORKFVYZaNhCIVbooY+J4cYST00ztLf0EjivIBPPdtIYFUMfzQ==";
26 unionOfDisjoints = lib.foldl lib.attrsets.unionOfDisjoint { };
29 "test${n}AlreadyNormalized" = {
32 outputHashAlgo = "md42";
36 outputHashAlgo = "md42";
40 "test${n}EmptySha256" = {
41 expr = f { } { sha256 = ""; };
43 outputHash = fakeSha256;
44 outputHashAlgo = "sha256";
48 "test${n}EmptySha512" = {
49 expr = f { hashTypes = [ "sha512" ]; } { sha512 = ""; };
51 outputHash = fakeSha512;
52 outputHashAlgo = "sha512";
56 "test${n}EmptyHash" = {
57 expr = f { } { hash = ""; };
59 outputHash = fakeHash;
60 outputHashAlgo = null;
65 expr = f { } { hash = sri256; };
68 outputHashAlgo = null;
73 expr = f { } { hash = sri512; };
76 outputHashAlgo = null;
80 "test${n}PreservesAttrs" = {
83 destination = "Earth";
87 outputHashAlgo = null;
88 destination = "Earth";
92 "test${n}RejectsSha1ByDefault" = testingThrow (f { } { sha1 = ""; });
93 "test${n}RejectsSha512ByDefault" = testingThrow (f { } { sha512 = ""; });
95 "test${n}ThrowsOnMissing" = testingThrow (f { } { gibi = false; });
98 runTests (unionOfDisjoints [
99 (genTests "NormalizeHash" normalizeHash)
100 (genTests "WithNormalized" (
101 flip withNormalizedHash ({ outputHash, outputHashAlgo, ... }@args: args)
104 testNormalizeNotRequiredEquivalent = {
105 expr = normalizeHash { required = false; } {
109 expected = normalizeHash { } {
115 testNormalizeNotRequiredPassthru = {
116 expr = normalizeHash { required = false; } { "ga bu" = "zo meu"; };
117 expected."ga bu" = "zo meu";
121 expr = withNormalizedHash { } (
124 outputHashAlgo ? null,
128 ) { author = "Jacques Rouxel"; };
129 expected.author = "Jacques Rouxel";
132 testOptionalArgMetadata = {
133 expr = functionArgs (
134 withNormalizedHash { } (
137 outputHashAlgo ? null,
142 expected.hash = true;
145 testPreservesArgsMetadata = {
146 expr = functionArgs (
147 withNormalizedHash { } (
162 testRejectsMissingHashArg = testingThrow (withNormalizedHash { } ({ outputHashAlgo }: { }));
163 testRejectsMissingAlgoArg = testingThrow (withNormalizedHash { } ({ outputHash }: { }));