Debugging functions

lib.debug.traceIf

traceIf :: bool -> string -> a -> a

Conditionally trace the supplied message, based on a predicate.

pred

Predicate to check

msg

Message that should be traced

x

Value to return

lib.debug.traceIf usage example

traceIf true "hello" 3
trace: hello
=> 3

lib.debug.traceValFn

traceValFn :: (a -> b) -> a -> a

Trace the supplied value after applying a function to it, and return the original value.

f

Function to apply

x

Value to trace and return

lib.debug.traceValFn usage example

traceValFn (v: "mystring ${v}") "foo"
trace: mystring foo
=> "foo"

lib.debug.traceVal

traceVal :: a -> a

Trace the supplied value and return it.

lib.debug.traceVal usage example

traceVal 42
# trace: 42
=> 42

lib.debug.traceSeq

traceSeq :: a -> b -> b

builtins.trace, but the value is builtins.deepSeqed first.

x

The value to trace

y

The value to return

lib.debug.traceSeq usage example

trace { a.b.c = 3; } null
trace: { a = <CODE>; }
=> null
traceSeq { a.b.c = 3; } null
trace: { a = { b = { c = 3; }; }; }
=> null

lib.debug.traceSeqN

Like traceSeq, but only evaluate down to depth n. This is very useful because lots of traceSeq usages lead to an infinite recursion.

depth

Function argument

x

Function argument

y

Function argument

lib.debug.traceSeqN usage example

traceSeqN 2 { a.b.c = 3; } null
trace: { a = { b = {…}; }; }
=> null

lib.debug.traceValSeqFn

A combination of traceVal and traceSeq that applies a provided function to the value to be traced after deepSeqing it.

f

Function to apply

v

Value to trace

lib.debug.traceValSeq

A combination of traceVal and traceSeq.

lib.debug.traceValSeqNFn

A combination of traceVal and traceSeqN that applies a provided function to the value to be traced.

f

Function to apply

depth

Function argument

v

Value to trace

lib.debug.traceValSeqN

A combination of traceVal and traceSeqN.

lib.debug.traceFnSeqN

Trace the input and output of a function f named name, both down to depth.

This is useful for adding around a function call, to see the before/after of values as they are transformed.

depth

Function argument

name

Function argument

f

Function argument

v

Function argument

lib.debug.traceFnSeqN usage example

traceFnSeqN 2 "id" (x: x) { a.b.c = 3; }
trace: { fn = "id"; from = { a.b = {…}; }; to = { a.b = {…}; }; }
=> { a.b.c = 3; }

lib.debug.runTests

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. Only tests having names starting with "test" are run.

Add attr { tests = ["testName"]; } to run these tests only.

tests

Tests to run

lib.debug.testAllTrue

Create a test assuming that list elements are true.

expr

Function argument

lib.debug.testAllTrue usage example

{ testX = allTrue [ true ]; }