aboutsummaryrefslogtreecommitdiff
path: root/tests/lang/eval-okay-context-introspection.nix
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-21 23:50:09 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-21 23:50:09 -0500
commit88d8f6ac4817e44fba0a4f086ea0b8c06234cdd7 (patch)
treec957613cf5a423fdb52bd77cbef06b43c849afaa /tests/lang/eval-okay-context-introspection.nix
parent04de0dd0b4059c75115c780dae8ddc49a847b0e5 (diff)
Expand tests to reproduce #7655
The original `builtins.getContext` test from 1d757292d0cb78beec32fcdfe15c2944a4bc4a95 would have caught this. The problem is that b30be6b450f872f8be6dc8afa28f4b030fa8d1d1 adding `builtins.appendContext` modified that test to make it test too much at once, rather than adding a separate test. We now have isolated tests for both functions, and also a property test showing everything put together (in the form of an eta rule for strings with context). This is better coverage and properly reproduces the bug.
Diffstat (limited to 'tests/lang/eval-okay-context-introspection.nix')
-rw-r--r--tests/lang/eval-okay-context-introspection.nix23
1 files changed, 20 insertions, 3 deletions
diff --git a/tests/lang/eval-okay-context-introspection.nix b/tests/lang/eval-okay-context-introspection.nix
index 43178bd2e..50a78d946 100644
--- a/tests/lang/eval-okay-context-introspection.nix
+++ b/tests/lang/eval-okay-context-introspection.nix
@@ -18,7 +18,24 @@ let
};
};
- legit-context = builtins.getContext "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}";
+ combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}";
+ legit-context = builtins.getContext combo-path;
- constructed-context = builtins.getContext (builtins.appendContext "" desired-context);
-in legit-context == constructed-context
+ reconstructed-path = builtins.appendContext
+ (builtins.unsafeDiscardStringContext combo-path)
+ desired-context;
+
+ # Eta rule for strings with context.
+ etaRule = str:
+ str == builtins.appendContext
+ (builtins.unsafeDiscardStringContext str)
+ (builtins.getContext str);
+
+in [
+ (legit-context == desired-context)
+ (reconstructed-path == combo-path)
+ (etaRule "foo")
+ (etaRule drv.drvPath)
+ (etaRule drv.foo.outPath)
+ (etaRule (builtins.unsafeDiscardOutputDependency drv.drvPath))
+]