diff options
author | Robin Gloster <mail@glob.in> | 2017-09-02 23:29:04 +0200 |
---|---|---|
committer | Robin Gloster <mail@glob.in> | 2017-09-02 23:29:04 +0200 |
commit | 0156db2da530a52265fbccc8ad7747b00ee8aaf3 (patch) | |
tree | f5facfdd70ac838997ed0538fd9f4e8edffe9936 /pkgs/development/ruby-modules/testing/testing.nix | |
parent | 891a1662aa6cd6b2bcd2187d97f27822ed5df138 (diff) | |
parent | d784b830051bb86172b9a3669826774cc20e1f41 (diff) | |
download | nixlib-0156db2da530a52265fbccc8ad7747b00ee8aaf3.tar nixlib-0156db2da530a52265fbccc8ad7747b00ee8aaf3.tar.gz nixlib-0156db2da530a52265fbccc8ad7747b00ee8aaf3.tar.bz2 nixlib-0156db2da530a52265fbccc8ad7747b00ee8aaf3.tar.lz nixlib-0156db2da530a52265fbccc8ad7747b00ee8aaf3.tar.xz nixlib-0156db2da530a52265fbccc8ad7747b00ee8aaf3.tar.zst nixlib-0156db2da530a52265fbccc8ad7747b00ee8aaf3.zip |
Merge remote-tracking branch 'upstream/master' into HEAD
Diffstat (limited to 'pkgs/development/ruby-modules/testing/testing.nix')
-rw-r--r-- | pkgs/development/ruby-modules/testing/testing.nix | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pkgs/development/ruby-modules/testing/testing.nix b/pkgs/development/ruby-modules/testing/testing.nix new file mode 100644 index 000000000000..43d10fca0444 --- /dev/null +++ b/pkgs/development/ruby-modules/testing/testing.nix @@ -0,0 +1,62 @@ +with builtins; +let + /* + underTest = { + x = { + a = 1; + b = "2"; + }; + }; + + tests = [ + (root: false) + { + x = [ + (set: true) + { + a = (a: a > 1); + b = (b: b == "3"); + } + ]; + } + ]; + + results = run "Examples" underTest tests; + */ + + passed = desc: { + result = "pass"; + description = desc; + }; + + failed = desc: { + result = "failed"; + description = desc; + }; + + prefixName = name: res: { + inherit (res) result; + description = "${name}: ${res.description}"; + }; + + run = name: under: tests: if isList tests then + (concatLists (map (run name under) tests)) + else if isAttrs tests then + (concatLists (map ( + subName: run (name + "." + subName) (if hasAttr subName under then getAttr subName under else "<MISSING!>") (getAttr subName tests) + ) (attrNames tests))) + else if isFunction tests then + let + res = tests under; + in + if isBool res then + [ + (prefixName name (if tests under then passed "passed" else failed "failed")) + ] + else + [ (prefixName name res) ] + else [ + failed (name ": not a function, list or set") + ]; +in + { inherit run passed failed; } |