Module Tester
Tester is a unit test framework for OCaml. It allows the easy creation of unit tests for OCaml code. It is somewhat based on OUnit2, another unit testing framework for OCaml. However, its output can be customized per test case, and it is easier to see whether a case has passed or failed.
Copyright (C) 2020 Nikunj Chawla
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://www.gnu.org/licenses/.
val test : ('a -> 'a -> bool) -> ('a -> string) -> string -> 'a -> 'a lazy_t -> 'a ttestcreates an instance of thetrecord type with the given parameters- parameter pass_pred
A function to compare the expected and actual results of the computationally-delayed expression
- parameter string_of_result
A function to parse the output of the computationally-delayed expression
- parameter input
The string representing the input for the test
- parameter expected_result
The expected output of the computationally-delayed expression
- parameter actual_result_lazy
The lazily-evaluated result of actually executing the computationally-delayed expression
- returns
The
tinstance with the given values
val test_eq : ('a -> string) -> string -> 'a -> 'a lazy_t -> 'a ttest_eqcreates an instance of thetrecord type with the given parameters and (=) aspass_predfromtest- parameter string_of_result
A function to parse the output of the computationally-delayed expression
- parameter input
The string representing the input for the test
- parameter expected_result
The expected output of the computationally-delayed expression
- parameter actual_result_lazy
The lazily-evaluated result of actually executing the computationally-delayed expression
- returns
The
tinstance with the given values
val test_exn : (exn -> bool) -> (exn -> string) -> string -> string -> 'a lazy_t -> 'a ttest_exncreates an instance of thetrecord type with the given parameters- parameter pass_pred
A function to compare the expected and actual exceptions for the computationally-delayed expression
- parameter string_of_exn
A function to parse the exception raised by the computationally-delayed expression
- parameter input
The string representing the input for the test
- parameter except_cond_str
The string to print as what was expected if
pass_predfails
- parameter actual_result_lazy
The lazily-evaluated result of actually executing the computationally-delayed expression
- returns
The
tinstance with the given values
type 'a run_test_res_t=|PassResult of 'a|PassExcept of exn|FailureResult of 'a|FailureExcept of exnrun_test_res_tincludes the possible results of runningrun_test_res:–
PassResultif the result of executing the provided expression is equivalent to the expected result as determined bypass_predfrom the function that createdtPassExceptif the exception raised when executing the provided expression is equivalent to the expected exception as determined bypass_predfrom the function that createdt
–
FailureResultif the result of evaluating the provided expression is not equivalent to the expected outcome as determined bypass_predfrom the function that createdt–
FailureExceptif evaluating the provided expression causes an exception to be raised
val result_passed : 'a run_test_res_t -> boolresult_passedreturnstrueif the providedrun_test_res_thas the type constructorPassandfalseotherwise- parameter r
The
run_test_res_tinstance to test
- returns
trueif the providedrun_test_res_thas the type constructorPassandfalseotherwise
val run_test_res : string -> bool -> bool -> 'a t -> 'a run_test_res_trun_test_resexecutes a given test case and returns the appropriaterun_test_res_tdepending on the test succeeding or the multiple ways in which it can fail- parameter name
The printed name that is associated with this test case
- parameter show_input
trueif the input string for the test should be printed
- parameter show_pass
trueif something should be printed if a test passes
- parameter test
The instance of
tto be run
- returns
The appropriate
run_test_res_tdepending on the test succeeding or the multiple ways in which it can fail
val run_test : string -> bool -> bool -> 'a t -> unitrun_testexecutes a given test case- parameter name
The printed name that is associated with this test case
- parameter show_input
trueif the input string for the test should be printed
- parameter show_pass
trueif something should be printed if a test passes
- parameter test
The instance of
tto be run
- returns
Unit
val run_tests_res : string -> bool -> bool -> bool -> 'a t list -> int * int * intrun_tests_resruns alistofts usingrun_test_resand returns a tuple containing the number of tests that passed, the number of tests that failed due to differing results, and the number of tests that failed due to an exception being thrown- parameter name
The name that is associated with the given
t list
- parameter show_inputs
trueif the input string for each test in thet listshould be printed
- parameter show_passes
trueif something should be printed if a test passes for the individual test
- parameter show_num
trueif the number of tests passed should be shown
- parameter tests
The
listofts to run
- returns
A tuple containing the number of tests that passed, the number of tests that failed due to differing results, and the number of tests that failed due to an exception being thrown
val run_tests : string -> bool -> bool -> bool -> 'a t list -> unitrun_testsruns alistofts usingrun_test- parameter name
The name that is associated with the given
test list
- parameter show_inputs
trueif the input string for each test in thetest listshould be printed
- parameter show_passes
trueif something should be printed if a test passes for the individual test
- parameter show_num
trueif the number of tests passed should be shown
- parameter tests
The
listofts to run
- returns
Unit