summary refs log tree commit diff
path: root/pkgs/lib/debug.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2009-03-31 13:03:50 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2009-03-31 13:03:50 +0000
commit1f9740e01c4da98c1a49641f2313729798fafcf3 (patch)
treebb93942c8c3e0daf609020aec8c1c0dc6e26fee8 /pkgs/lib/debug.nix
parentacca11b49c04ecc05e6eb279357b5d0808767f40 (diff)
downloadnixpkgs-1f9740e01c4da98c1a49641f2313729798fafcf3.tar
nixpkgs-1f9740e01c4da98c1a49641f2313729798fafcf3.tar.gz
nixpkgs-1f9740e01c4da98c1a49641f2313729798fafcf3.tar.bz2
nixpkgs-1f9740e01c4da98c1a49641f2313729798fafcf3.tar.lz
nixpkgs-1f9740e01c4da98c1a49641f2313729798fafcf3.tar.xz
nixpkgs-1f9740e01c4da98c1a49641f2313729798fafcf3.tar.zst
nixpkgs-1f9740e01c4da98c1a49641f2313729798fafcf3.zip
* Added some regression tests for lib that I wrote a while ago but
  didn't commit.  Also, run the tests when making a Nixpkgs tarball.

svn path=/nixpkgs/trunk/; revision=14802
Diffstat (limited to 'pkgs/lib/debug.nix')
-rw-r--r--pkgs/lib/debug.nix15
1 files changed, 15 insertions, 0 deletions
diff --git a/pkgs/lib/debug.nix b/pkgs/lib/debug.nix
index ce38259725e..a58539ee3c4 100644
--- a/pkgs/lib/debug.nix
+++ b/pkgs/lib/debug.nix
@@ -14,9 +14,11 @@ rec {
 
   addErrorContextToAttrs = lib.mapAttrs (a : v : lib.addErrorContext "while evaluating ${a}" v);
 
+  
   traceVal = if builtins ? trace then x: (builtins.trace x x) else x: x;
   traceXMLVal = if builtins ? trace then x: (builtins.trace (builtins.toXML x) x) else x: x;
 
+  
   # this can help debug your code as well - designed to not produce thousands of lines
   traceShowVal = x : __trace (showVal x) x;
   traceShowValMarked = str: x: __trace (str + showVal x) x;
@@ -37,4 +39,17 @@ rec {
   traceCall2 = n : f : a : b : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b));
   traceCall3 = n : f : a : b : c : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b) (t "arg 3" c));
 
+
+  /* Evaluate a set of tests.  A test is an attribute set {expr,
+     expected}, denoting an expression and its expected result.  The
+     result is a list of failed tests, each represented as {name,
+     expected, actual}, denoting the attribute name of the failing
+     test and its expected and actual results.  Used for regression
+     testing of the functions in lib; see tests.nix for an example.
+  */
+  runTests = tests: lib.concatLists (lib.attrValues (lib.mapAttrs (name: test:
+    if ! lib.eqStrict test.expr test.expected
+      then [ { inherit name; expected = test.expected; result = test.expr; } ]
+      else [] ) tests));
+  
 }