aboutsummaryrefslogtreecommitdiffstats
path: root/test/testdata/eval-okay-context-introspection.nix
diff options
context:
space:
mode:
authorRutger Broekhoff2025-07-07 21:52:08 +0200
committerRutger Broekhoff2025-07-07 21:52:08 +0200
commitba61dfd69504ec6263a9dee9931d93adeb6f3142 (patch)
treed6c9b78e50eeab24e0c1c09ab45909a6ae3fd5db /test/testdata/eval-okay-context-introspection.nix
downloadverified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.tar.gz
verified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.zip
Initialize repository
Diffstat (limited to 'test/testdata/eval-okay-context-introspection.nix')
-rw-r--r--test/testdata/eval-okay-context-introspection.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/testdata/eval-okay-context-introspection.nix b/test/testdata/eval-okay-context-introspection.nix
new file mode 100644
index 0000000..8886cf3
--- /dev/null
+++ b/test/testdata/eval-okay-context-introspection.nix
@@ -0,0 +1,59 @@
1let
2 drv = derivation {
3 name = "fail";
4 builder = "/bin/false";
5 system = "x86_64-linux";
6 outputs = [ "out" "foo" ];
7 };
8
9 path = "${./eval-okay-context-introspection.nix}";
10
11 desired-context = {
12 "${builtins.unsafeDiscardStringContext path}" = {
13 path = true;
14 };
15 "${builtins.unsafeDiscardStringContext drv.drvPath}" = {
16 outputs = [ "foo" "out" ];
17 allOutputs = true;
18 };
19 };
20
21 combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}";
22 legit-context = builtins.getContext combo-path;
23
24 reconstructed-path = builtins.appendContext
25 (builtins.unsafeDiscardStringContext combo-path)
26 desired-context;
27
28 # Eta rule for strings with context.
29 etaRule = str:
30 str == builtins.appendContext
31 (builtins.unsafeDiscardStringContext str)
32 (builtins.getContext str);
33
34 # Only holds true if string context contains both a `DrvDeep` and
35 # `Opaque` element.
36 almostEtaRule = str:
37 str == builtins.addDrvOutputDependencies
38 (builtins.unsafeDiscardOutputDependency str);
39
40 addDrvOutputDependencies_idempotent = str:
41 builtins.addDrvOutputDependencies str ==
42 builtins.addDrvOutputDependencies (builtins.addDrvOutputDependencies str);
43
44 rules = str: [
45 (etaRule str)
46 (almostEtaRule str)
47 (addDrvOutputDependencies_idempotent str)
48 ];
49
50in [
51 (legit-context == desired-context)
52 (reconstructed-path == combo-path)
53 (etaRule "foo")
54 (etaRule drv.foo.outPath)
55] ++ builtins.concatMap rules [
56 drv.drvPath
57 (builtins.addDrvOutputDependencies drv.drvPath)
58 (builtins.unsafeDiscardOutputDependency drv.drvPath)
59]