object
lgtunit¶
A unit test framework supporting predicate clause coverage, determinism testing, input/output testing, property-based testing, and multiple test dialects.
static, context_switching_calls
Usage: Define test objects as extensions of the
lgtunitobject and compile their source files using the compiler optionhook(lgtunit).Portability: Deterministic unit tests are currently not available when using Lean Prolog or Quintus Prolog as backend compilers.
Known issues: Parameter variables cannot currently be used in the definition of test options.
Public predicates¶
cover/1¶
Declares entities being tested for which code coverage information should be collected.
staticcover(Entity)cover(?entity_identifier) - zero_or_morerun/0¶
Runs the unit tests, writing the results to the current output stream.
staticrun - onerun/1¶
Runs a unit test or a list of unit tests, writing the results to the current output stream. Runs the global setup and cleanup steps when defined, failing if either step fails.
staticrun(Tests)run(+atom) - zero_or_onerun(+list(atom)) - zero_or_onerun/2¶
Runs the unit tests, writing the results to the specified file. Mode can be either write (to create a new file) or append (to add results to an existing file).
staticrun(File,Mode)run(+atom,+atom) - onerun_test_sets/1¶
Runs two or more test sets as a unified set generating a single code coverage report if one is requested. Fails if the list does not contains at least two test objects.
staticrun_test_sets(TestObjects)run_test_sets(+list(object_identifier)) - zero_or_onedeterministic/1¶
True if the goal succeeds once without leaving choice-points.
staticdeterministic(Goal)deterministic(0)deterministic(+callable) - zero_or_onedeterministic/2¶
Reified version of the deterministic/1 predicate. True if the goal succeeds. Returns a boolean value (true or false) indicating if the goal succeeded without leaving choice-points.
staticdeterministic(Goal,Deterministic)deterministic(0,*)deterministic(+callable,--atom) - zero_or_oneassertion/1¶
True if the assertion goal succeeds. Throws an error using the assertion goal as argument if the assertion goal throws an error or fails.
staticassertion(Assertion)assertion(::)assertion(+callable) - oneassertion_failure(Assertion)assertion_error(Assertion,Error)assertion/2¶
True if the assertion goal succeeds. Throws an error using the description as argument if the assertion goal throws an error or fails. The description argument helps to distinguish between different assertions in the same test body.
staticassertion(Description,Assertion)assertion(*,0)assertion(+nonvar,+callable) - oneassertion_failure(Description)assertion_error(Description,Error)quick_check/3¶
Reified version of the quick_check/2 predicate. Reports the result as passed, failed(Goal) where Goal is the test that failed, or error(Error,Template).
staticquick_check(Template,Result,Options)quick_check(@callable,-callable,++list(compound)) - onequick_check/2¶
Generates and runs random tests for a given predicate given its mode template. Fails when a random generated test fails printing the test. Accepts an option n(NumberOfTests). Default is to run 100 random tests.
staticquick_check(Template,Options)quick_check(@callable,++list(compound)) - zero_or_onequick_check/1¶
Generates and runs 100 random tests for a given predicate given its mode template. Fails when a random generated call fails printing the test.
staticquick_check(Template)quick_check(@callable) - zero_or_onebenchmark/2¶
Benchmarks a goal and returns the total execution time in seconds. Uses cpu clock. Goals that may throw an exception should be wrapped by the catch/3 control construct.
staticbenchmark(Goal,Time)benchmark(0,*)benchmark(+callable,-float) - onebenchmark_reified/3¶
Benchmarks a goal and returns the total execution time in seconds plus its result (success, failure, or error(Error)). Uses CPU clock.
staticbenchmark_reified(Goal,Time,Result)benchmark_reified(0,*,*)benchmark_reified(+callable,-float,-callable) - onebenchmark/3¶
Benchmarks a goal by repeating it the specified number of times and returning the total execution time in seconds. Uses CPU clock. Goals that may throw an exception should be wrapped by the catch/3 control construct.
staticbenchmark(Goal,Repetitions,Time)benchmark(0,*,*)benchmark(@callable,+positive_integer,-float) - onebenchmark/4¶
Benchmarks a goal by repeating it the specified number of times and returning the total execution time in seconds using the given clock (cpu or wall). Goals that may throw an exception should be wrapped by the catch/3 control construct.
staticbenchmark(Goal,Repetitions,Clock,Time)benchmark(0,*,*,*)benchmark(@callable,+positive_integer,+atom,-float) - onevariant/2¶
True when the two arguments are a variant of each other. I.e. if is possible to rename the term variables to make them identical. Useful for checking expected test results that contain variables.
staticvariant(Term1,Term2)variant(@term,@term) - zero_or_oneapproximately_equal/3¶
Compares two numbers for approximate equality given an epsilon value using the de facto standard formula abs(Number1 - Number2) =< max(abs(Number1), abs(Number2)) * Epsilon. Type-checked.
staticapproximately_equal(Number1,Number2,Epsilon)approximately_equal(+number,+number,+number) - zero_or_oneessentially_equal/3¶
Compares two numbers for essential equality given an epsilon value using the de facto standard formula abs(Number1 - Number2) =< min(abs(Number1), abs(Number2)) * Epsilon. Type-checked.
staticessentially_equal(Number1,Number2,Epsilon)essentially_equal(+number,+number,+number) - zero_or_onetolerance_equal/4¶
Compares two numbers for close equality given relative and absolute tolerances using the de facto standard formula abs(Number1 - Number2) =< max(RelativeTolerance * max(abs(Number1), abs(Number2)), AbsoluteTolerance). Type-checked.
statictolerance_equal(Number1,Number2,RelativeTolerance,AbsoluteTolerance)tolerance_equal(+number,+number,+number,+number) - zero_or_one=~= / 2¶
Compares two numbers (or lists of numbers) for approximate equality using 100*epsilon for the absolute error and, if that fails, 99.999% accuracy for the relative error. But these precision values may not be adequate for all cases. Type-checked.
static=~=(Number1,Number2)=~=(+number,+number) - zero_or_one=~=(+list(number),+list(number)) - zero_or_oneProtected predicates¶
run_tests/0¶
Runs all defined unit tests.
staticrun_tests - onerun_tests/2¶
Runs a list of defined tests.
staticrun_tests(Tests,File)run_tests(+list(callable),+atom) - onerun_test_set/0¶
Runs a test set as part of running two or more test sets as a unified set.
staticrun_test_set - onerun_quick_check_tests/2¶
Runs a list of defined tests using the given options.
staticrun_quick_check_tests(Template,Options)run_quick_check_tests(@callable,+list) - one_or_errorcondition/0¶
Verifies conditions for running the tests. Defaults to the goal true.
staticcondition - zero_or_onesetup/0¶
Setup environment before running the test set. Defaults to the goal true.
staticsetup - zero_or_onecleanup/0¶
Cleanup environment after running the test set. Defaults to the goal true.
staticcleanup - zero_or_onemake/1¶
Make target for automatically running the test set when calling the logtalk_make/1 built-in predicate. No default. Possible values are all and check.
staticmake(?atom) - zero_or_onenote/1¶
Note to be printed after the test results. Defaults to the empty atom.
staticnote(?atom) - zero_or_onesuppress_text_output/0¶
Suppresses text output. Useful to avoid irrelevant text output from predicates being tested to clutter the test logs.
staticsuppress_text_output - onesuppress_binary_output/0¶
Suppresses binary output. Useful to avoid irrelevant binary output from predicates being tested to clutter the test logs.
staticsuppress_binary_output - oneset_text_input/3¶
Creates a temporary file with the given text contents and opens it for reading referenced by the given alias and using the additional options. If no eof_action/1 option is specified, its value will be the default used by the backend compiler.
staticset_text_input(Alias,Contents,Options)set_text_input(+atom,+atom,+list(stream_option)) - oneset_text_input/2¶
Creates a temporary file with the given text contents and opens it for reading referenced by the given alias and using the default end-of-file action for the used backend compiler.
staticset_text_input(Alias,Contents)set_text_input(+atom,+atom) - oneset_text_input/1¶
Creates a temporary file with the given text contents, opens it for reading using the default end-of-file action for the used backend compiler, and sets the current input stream to the file.
staticset_text_input(Contents)set_text_input(+atom) - onecheck_text_input/2¶
Checks that the temporary file (referenced with the given alias) being written have the expected text contents.
staticcheck_text_input(Alias,Contents)check_text_input(+atom,+atom) - zero_or_onecheck_text_input/1¶
Checks that the temporary file being written have the expected text contents.
staticcheck_text_input(Contents)check_text_input(+atom) - zero_or_onetext_input_assertion/3¶
Returns an assertion for checking that the temporary file (referenced with the given alias) being written have the expected text contents.
statictext_input_assertion(Alias,Contents,Assertion)text_input_assertion(+atom,+atom,--callable) - onetext_input_assertion/2¶
Returns an assertion for checking that the temporary file being written have the expected text contents.
statictext_input_assertion(Contents,Assertion)text_input_assertion(+atom,--callable) - oneclean_text_input/0¶
Cleans the temporary file used when testing text input.
staticclean_text_input - oneset_binary_input/3¶
Creates a temporary file with the given binary contents and opens it for reading referenced by the given alias and using the additional options. If no eof_action/1 option is specified, its value will be the default used by the backend compiler.
staticset_binary_input(Alias,Bytes,Options)set_binary_input(+atom,+list(byte),+list(stream_option)) - oneset_binary_input/2¶
Creates a temporary file with the given binary contents and opens it for reading referenced by the given alias and using the default end-of-file action for the used backend compiler.
staticset_binary_input(Alias,Bytes)set_binary_input(+atom,+list(byte)) - oneset_binary_input/1¶
Creates a temporary file with the given binary contents, opens it for reading using the default end-of-file action for the used backend compiler, and sets the current input stream to the file.
staticset_binary_input(Bytes)set_binary_input(+list(byte)) - onecheck_binary_input/2¶
Checks that the temporary file (referenced with the given alias) have the expected binary contents.
staticcheck_binary_input(Alias,Bytes)check_binary_input(+atom,+list(byte)) - zero_or_onecheck_binary_input/1¶
Checks that the temporary file have the expected binary contents.
staticcheck_binary_input(Bytes)check_binary_input(+list(byte)) - zero_or_onebinary_input_assertion/3¶
Returns an assertion for checking that the temporary file (referenced with the given alias) have the expected binary contents.
staticbinary_input_assertion(Alias,Bytes,Assertion)binary_input_assertion(+atom,+list(byte),--callable) - onebinary_input_assertion/2¶
Returns an assertion for checking that the temporary file have the expected binary contents.
staticbinary_input_assertion(Bytes,Assertion)binary_input_assertion(+list(byte),--callable) - oneclean_binary_input/0¶
Cleans the temporary file used when testing binary input.
staticclean_binary_input - oneset_text_output/2¶
Creates a temporary file with the given text contents and referenced with the given alias.
staticset_text_output(Alias,Contents)set_text_output(+atom,+atom) - oneset_text_output/1¶
Creates a temporary file with the given text contents and sets the current output stream to the file.
staticset_text_output(Contents)set_text_output(+atom) - onecheck_text_output/2¶
Checks that the temporary file (referenced with the given alias) being written have the expected text contents.
staticcheck_text_output(Alias,Contents)check_text_output(+atom,+atom) - zero_or_onecheck_text_output/1¶
Checks that the temporary file being written have the expected text contents.
staticcheck_text_output(Contents)check_text_output(+atom) - zero_or_onetext_output_assertion/3¶
Returns an assertion for checking that the temporary file (referenced with the given alias) being written have the expected text contents.
statictext_output_assertion(Alias,Contents,Assertion)text_output_assertion(+atom,+atom,--callable) - onetext_output_assertion/2¶
Returns an assertion for checking that the temporary file being written have the expected text contents.
statictext_output_assertion(Contents,Assertion)text_output_assertion(+atom,--callable) - oneclean_text_output/0¶
Cleans the temporary file used when testing text output.
staticclean_text_output - oneset_binary_output/2¶
Creates a temporary file with the given binary contents and referenced with the given alias.
staticset_binary_output(Alias,Bytes)set_binary_output(+atom,+list(byte)) - oneset_binary_output/1¶
Creates a temporary file with the given binary contents and sets the current output stream to the file.
staticset_binary_output(Bytes)set_binary_output(+list(byte)) - onecheck_binary_output/2¶
Checks that the temporary file (referenced with the given alias) have the expected binary contents.
staticcheck_binary_output(Alias,Bytes)check_binary_output(+atom,+list(byte)) - zero_or_onecheck_binary_output/1¶
Checks that the temporary file have the expected binary contents.
staticcheck_binary_output(Bytes)check_binary_output(+list(byte)) - zero_or_onebinary_output_assertion/3¶
Returns an assertion for checking that the temporary file (referenced with the given alias) have the expected binary contents.
staticbinary_output_assertion(Alias,Bytes,Assertion)binary_output_assertion(+atom,+list(byte),--callable) - onebinary_output_assertion/2¶
Returns an assertion for checking that the temporary file have the expected binary contents.
staticbinary_output_assertion(Bytes,Assertion)binary_output_assertion(+list(byte),--callable) - oneclean_binary_output/0¶
Cleans the temporary file used when testing binary output.
staticclean_binary_output - onecreate_text_file/2¶
Creates a text file with the given contents.
staticcreate_text_file(File,Contents)create_text_file(+atom,+atom) - onecreate_binary_file/2¶
Creates a binary file with the given contents.
staticcreate_binary_file(File,Bytes)create_binary_file(+atom,+list(byte)) - onecheck_text_file/2¶
Checks that the contents of a text file match the expected contents.
staticcheck_text_file(File,Contents)check_text_file(+atom,+atom) - zero_or_onecheck_binary_file/2¶
Checks the contents of a binary file match the expected contents.
staticcheck_binary_file(File,Bytes)check_binary_file(+atom,+list(byte)) - zero_or_oneclean_file/1¶
Closes any existing stream associated with the file and deletes the file if it exists.
staticclean_file(File)clean_file(+atom) - oneclosed_input_stream/2¶
Opens a temporary file with the given options for reading, closes it, and returns its stream handle.
staticclosed_input_stream(Stream,Options)closed_input_stream(-stream,+list(stream_option)) - oneclosed_output_stream/2¶
Opens a temporary file with the given options for writing, closes it, and returns its stream handle.
staticclosed_output_stream(Stream,Options)closed_output_stream(-stream,+list(stream_option)) - zero_or_onestream_position/1¶
Returns a syntactically valid stream position.
staticstream_position(Position)stream_position(-stream_position) - onePrivate predicates¶
running_test_sets_/0¶
Internal flag used when running two or more test sets as a unified set.
dynamicrunning_test_sets_ - zero_or_onetest/3¶
Specifies a unit test.
statictest(Identifier,Variables,Outcome)test(?atom,?list(variable),?nonvar) - zero_or_moreauxiliary_predicate_counter_/1¶
Counter for generating unique auxiliary predicate names.
dynamicauxiliary_predicate_counter_(Counter)auxiliary_predicate_counter_(?integer) - one_or_moretest_/2¶
Table of defined tests.
dynamictest_(Identifier,Test)test_(?atom,?compound) - zero_or_moreskipped_/1¶
Counter for skipped tests.
dynamicskipped_(Counter)skipped_(?integer) - zero_or_onepassed_/1¶
Counter for passed tests.
dynamicpassed_(Counter)passed_(?integer) - zero_or_onefailed_/1¶
Counter for failed tests.
dynamicfailed_(Counter)failed_(?callable) - zero_or_onefired_/3¶
Fired clauses when running the unit tests.
dynamicfired_(Entity,Predicate,Clause)fired_(?entity_identifier,?predicate_indicator,?integer) - zero_or_morecovered_/4¶
Auxiliary predicate for collecting statistics on clause coverage.
dynamiccovered_(Entity,Predicate,Covered,Total)covered_(?entity_identifier,?callable,?integer,?integer) - zero_or_moreOperators¶
op(700,xfx,=~=)¶
public