add filesystem test

This commit is contained in:
Johannes Kirschbauer 2024-01-19 12:56:58 +01:00 committed by mergify[bot]
parent df26fb319f
commit bf07b8fb37
3 changed files with 94 additions and 41 deletions

View File

@ -98,9 +98,9 @@
```nix ```nix
{ {
"node_modules/tap-dot" = { "node_modules/tap-dot" = {
bins = { bins = {
"node_modules/.bin/tap-dot" = "node_modules/tap-dot/bin/dot"; "node_modules/.bin/tap-dot" = "node_modules/tap-dot/bin/dot";
}; };
source = «derivation tap-dot.drv»; source = «derivation tap-dot.drv»;
}; };

View File

@ -20,54 +20,55 @@
else "dist"; else "dist";
}; };
/** /*
A Convinient wrapper around sanitizeGraph *
which allows to pass options such as { dev=false; } A Convinient wrapper around sanitizeGraph
which allows to pass options such as { dev=false; }
*/ */
getSanitizedGraph = { getSanitizedGraph = {
# The lockfile entry; One depdency used as a root. # The lockfile entry; One depdency used as a root.
plent, plent,
# The dependency 'graph'. See: sanitizeGraph # The dependency 'graph'. See: sanitizeGraph
pdefs, pdefs,
/** /*
Drops dependencies including their subtree connection by filter attribute. *
Drops dependencies including their subtree connection by filter attribute.
for example:
``` for example:
filterTree = {
dev = false;
};
```
Will filter out all dev dependencies including all children below dev-dependencies. ```
filterTree = {
dev = false;
};
```
Which will result in a prod only tree. Will filter out all dev dependencies including all children below dev-dependencies.
*/
filterTree ? {}, Which will result in a prod only tree.
}: */
let filterTree ? {},
}: let
root = { root = {
name = plent.name; name = plent.name;
version = plent.version; version = plent.version;
}; };
graph = pdefs; graph = pdefs;
in in
graphUtils.sanitizeGraph { graphUtils.sanitizeGraph {
inherit root graph; inherit root graph;
pred = ( pred = (
e: e:
l.foldlAttrs ( l.foldlAttrs (
res: name: value: res: name: value:
if res == false if res == false
then false then false
else value == e.${name} else value == e.${name}
) )
true true
filterTree filterTree
); );
}; };
in { in {
inherit getInfo getSanitizedGraph; inherit getInfo getSanitizedGraph;
} }

View File

@ -35,6 +35,58 @@ in {
}; };
}; };
}; };
# Currently only "dist" packages
# can be used to populate node_modules
test_only_dist = let
graph = {
"a"."1" = {
dist = "<Source A Derivation>";
dependencies = {
b.version = "1";
};
dev = false;
bins = {
};
info = {
initialState = "source";
allPaths = {
"" = true;
};
};
};
"b"."1" = {
dist = "<B Derivation>";
dependencies = {};
dev = false;
bins = {
};
info = {
initialState = "dist";
allPaths = {
"node_modules/b" = true;
};
};
};
};
sanitizedGraph = utils.sanitizeGraph {
inherit graph;
root = {
name = "a";
version = "1";
};
};
fileSystem = utils.getFileSystem graph sanitizedGraph;
in {
expr = fileSystem;
expected = {
"node_modules/b" = {
bins = {};
source = "<B Derivation>";
};
};
};
test_cyclic_dependency = let test_cyclic_dependency = let
graph = { graph = {