@@ -1649,6 +1649,11 @@ module Test_exceptions : sig
1649
1649
[Test_error (name, i, e, st)]
1650
1650
means [name] failed on [i] with exception [e], and [st] is the
1651
1651
stacktrace (if enabled) or an empty string. *)
1652
+
1653
+ exception Test_unexpected_success of string
1654
+ (* * Exception raised when a negative test failed.
1655
+ [Test_unexpected_success name] means test [name] failed to find an
1656
+ expected counter example. *)
1652
1657
end
1653
1658
1654
1659
(* * A test is a pair of a generator and a property that all generated values must satisfy. *)
@@ -1801,9 +1806,11 @@ module Test : sig
1801
1806
@since 0.6 *)
1802
1807
1803
1808
val check_result : 'a cell -> 'a TestResult .t -> unit
1804
- (* * [check_result cell res] checks that [res] is [Ok _], and returns unit.
1809
+ (* * For a positive test [check_result cell res] checks that [res] is [Ok _], and returns unit.
1810
+ For a negative test [check_result cell res] checks that [res] is [Failed _], and returns unit.
1805
1811
Otherwise, it raises some exception.
1806
- @raise Test_fail if [res = Failed _]
1812
+ @raise Test_fail if the test is positive and [res = Failed _]
1813
+ @raise Test_unexpected_success if the test is negative and [res = Ok _]
1807
1814
@raise Test_error if [res = Error _] *)
1808
1815
1809
1816
type res =
@@ -1840,6 +1847,10 @@ module Test : sig
1840
1847
predicate [law] is called on them and if it returns [false] or raises an
1841
1848
exception then we have a counter-example for the [law].
1842
1849
1850
+ Note: [check_cell] ignores a test's polarity, acting as
1851
+ described above regardless of whether the tested cell is a
1852
+ positive or negative test.
1853
+
1843
1854
@param long if [true] then multiply the number of instances to generate
1844
1855
by the cell's long_factor.
1845
1856
@param call function called on each test case, with the result.
@@ -1852,13 +1863,19 @@ module Test : sig
1852
1863
?step : 'a step -> ?handler : 'a handler ->
1853
1864
?rand : Random.State .t -> 'a cell -> unit
1854
1865
(* * Same as {!check_cell} but calls {!check_result} on the result.
1855
- @raise Test_fail if [res = Failed _]
1866
+ [check_cell test] honors test polarity and thus expects positive tests to succeed
1867
+ without finding a counterexample and expects negative tests to fail by finding one.
1868
+ @raise Test_fail if the test is positive and [res = Failed _]
1869
+ @raise Test_unexpected_success if the test is negative and [res = Success _]
1856
1870
@raise Test_error if [res = Error _] *)
1857
1871
1858
1872
val check_exn : ?long : bool -> ?rand : Random.State .t -> t -> unit
1859
1873
(* * Checks the property against some test cases, and calls {!check_result},
1860
1874
which might raise an exception in case of failure.
1861
- @raise Test_fail if [res = Failed _]
1875
+ [check_exn test] honors test polarity and thus expects positive tests to succeed
1876
+ without finding a counterexample and expects negative tests to fail by finding one.
1877
+ @raise Test_fail if the test is positive and [res = Failed _]
1878
+ @raise Test_unexpected_success if the test is negative and [res = Success _]
1862
1879
@raise Test_error if [res = Error _] *)
1863
1880
end
1864
1881
0 commit comments