From 02972b92d54f887fc7e9033bb973affd450be1d9 Mon Sep 17 00:00:00 2001
From: Marc Weber <marco-oweber@gmx.de>
Date: Sun, 22 Nov 2009 21:28:38 +0000
Subject: [PATCH] nix lang runTests: ignore tests which are not prefixed by
 "test"

svn path=/nixpkgs/trunk/; revision=18537
---
 pkgs/lib/debug.nix | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/pkgs/lib/debug.nix b/pkgs/lib/debug.nix
index e0f8b414a0de..25ca733951a3 100644
--- a/pkgs/lib/debug.nix
+++ b/pkgs/lib/debug.nix
@@ -3,7 +3,7 @@ let lib = import ./default.nix;
 inherit (builtins) trace attrNamesToStr isAttrs isFunction isList isInt
         isString isBool head substring attrNames;
 
-inherit (lib) all id mapAttrsFlatten;
+inherit (lib) all id mapAttrsFlatten elem;
 
 in
 
@@ -59,9 +59,15 @@ rec {
      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.
+     Only tests having names starting with "test" are run.
+     Add attr { tests = ["testName"]; } to run these test only
   */
   runTests = tests: lib.concatLists (lib.attrValues (lib.mapAttrs (name: test:
-    if ! lib.eqStrict test.expr test.expected
+    let testsToRun = if tests ? tests then tests.tests else [];
+    in if (substring 0 4 name == "test" ||  elem name testsToRun)
+       && ((testsToRun == []) || elem name tests.tests)
+       && (!lib.eqStrict test.expr test.expected)
+
       then [ { inherit name; expected = test.expected; result = test.expr; } ]
       else [] ) tests));