From f1183f33e3407bf626890484bb88fdd923b675a9 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Fri, 6 Mar 2009 23:21:17 +0000 Subject: [PATCH] added simple lib test case for overridableDelayableArgs svn path=/nixpkgs/trunk/; revision=14426 --- pkgs/lib/misc-tests.nix | 53 +++++++++++++++++++++++++++++++++ pkgs/lib/tests.nix | 8 +++++ pkgs/top-level/all-packages.nix | 3 +- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 pkgs/lib/misc-tests.nix create mode 100644 pkgs/lib/tests.nix diff --git a/pkgs/lib/misc-tests.nix b/pkgs/lib/misc-tests.nix new file mode 100644 index 000000000000..f8deb1b1a8ab --- /dev/null +++ b/pkgs/lib/misc-tests.nix @@ -0,0 +1,53 @@ +let lib = import ./default.nix; + + eqStrictTest = + let inherit(lib) eqStrict; in + assert eqStrict 2 2; + assert !(eqStrict 3 2); + assert eqStrict [2 1] [2 1]; + assert !(eqStrict [1 3] [1 2]); + assert eqStrict {a = 7; b = 20;} {b= 20; a = 7;}; + assert eqStrict [{a = 7; b = 20;}] [{b= 20; a = 7;}]; + assert eqStrict {a = [7 8]; b = 20;} {b= 20; a = [7 8];}; + "ok"; + + overridableDelayableArgsTest = + let inherit (lib) defaultOverridableDelayableArgs; + res1 = defaultOverridableDelayableArgs lib.id {}; + res2 = defaultOverridableDelayableArgs lib.id { a = 7; }; + res3 = let x = defaultOverridableDelayableArgs lib.id { a = 7; }; + in (x.merge) { b = 10; }; + res4 = let x = defaultOverridableDelayableArgs lib.id { a = 7; }; + in (x.merge) ( x: { b = 10; }); + res5 = let x = defaultOverridableDelayableArgs lib.id { a = 7; }; + in (x.merge) ( x: { a = __add x.a 3; }); + res6 = let x = defaultOverridableDelayableArgs lib.id { a = 7; mergeAttrBy = { a = __add; }; }; + y = x.merge {}; + in (y.merge) { a = 10; }; + + resRem7 = res6.replace (a : removeAttrs a ["a"]); + + resReplace6 = let x = defaultOverridableDelayableArgs lib.id { a = 7; mergeAttrBy = { a = __add; }; }; + x2 = x.merge { a = 20; }; # now we have 27 + in (x2.replace) { a = 10; }; # and override the value by 10 + + # fixed tests (delayed args): (when using them add some comments, please) + resFixed1 = + let x = defaultOverridableDelayableArgs lib.id ( x : { a = 7; c = x.fixed.b; }); + y = x.merge (x : { name = "name-${builtins.toString x.fixed.c}"; }); + in (y.merge) { b = 10; }; + strip = attrs : removeAttrs attrs ["merge" "replace"]; + + in + assert lib.eqStrict (strip res1) { }; + assert lib.eqStrict (strip res2) { a = 7; }; + assert lib.eqStrict (strip res3) { a = 7; b = 10; }; + assert lib.eqStrict (strip res4) { a = 7; b = 10; }; + assert lib.eqStrict (strip res5) { a = 10; }; + assert lib.eqStrict (strip res6) { a = 17; }; + assert lib.eqStrict (strip resRem7) {}; + assert lib.eqStrict (strip resFixed1) { a = 7; b = 10; c =10; name = "name-10"; }; + "ok"; + + +in [ eqStrictTest overridableDelayableArgsTest ] diff --git a/pkgs/lib/tests.nix b/pkgs/lib/tests.nix new file mode 100644 index 000000000000..2e75d7f141fa --- /dev/null +++ b/pkgs/lib/tests.nix @@ -0,0 +1,8 @@ +let lib = import ./default.nix; + + miscTests = import ./misc-tests.nix; + +in + if lib.all (a : a == "ok") (lib.concatLists [ miscTests ]) then + throw "all tests have passed" + else "there has been a some lib test failures" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index db0ea33f15ba..91f14e1cd9f7 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -34,7 +34,7 @@ let - lib = import ../lib; + lib = import ../lib; # see also libTests below # The contents of the configuration file found at $NIXPKGS_CONFIG or # $HOME/.nixpkgs/config.nix. @@ -9583,4 +9583,5 @@ let inherit (stdenv) mkDerivation; }; + libTests = import ../lib/tests.nix; }; in pkgs