Named groups of boolean expressions that are expected to evaluate to true.
If an expression evaluates to false, it is reported as a test failure.
Example:
// for brevity, code under test is defined here
function multiply(a, b) = a * b
facts {
["multiply numbers"] {
multiply(3, 5) == 15
multiple(3, 0) == 1 // will be reported as a test failure
}
// more facts here
}
Named groups of expressions whose results are expected to match results stored in $filename-expected.pcf.
If $filename-expected.pcf does not exist, it is generated based on the examples' actual results.
After verifying the contents of this file, it should be added to version control.
If $filename-expected.pcf does exist, its results are compared one-by-one to actual results.
If an actual result does not compare equal (according to ==) to its expected result,
it is reported as a test failure, and $filename-actual.pcf is generated to aid with debugging.
Example:
// for brevity, code under test is defined here
local function createPigeon(_age) = new {
name = "Pigeon"
age = _age
}
examples {
["create Pigeons"] {
createPigeon(21)
createPigeon(42)
}
// more examples here
}
When the above code is evaluated for the first time, the following $filename-expected.pcf is generated:
examples {
["create Pigeons"] {
new {
name = "Pigeon"
age = 21
}
new {
name = "Pigeon"
age = 42
}
}
}
To update expected results after making changes,
delete $filename-expected.pcf and evaluate the test module again.
Returns the relative, descendent directory path between this module and other.
Throws if no such path exists.
For example, if module mod1 has path /dir1/mod1.pkl, and module mod2 has path /dir1/dir2/dir3/mod2.pkl,
then mod1.relativePathTo(mod2) will return List("dir2", "dir3").
A common use case is to compute the directory path between a template located at the root of a hierarchy
(say rootModule.pkl) and the currently evaluated module (accessible via the module keyword):
A template for writing tests.