Files
mercury/tests/exceptions/test_exceptions_func.m
Zoltan Somogyi ecb5e4a9e6 Update the style of many test cases.
tests/declarative_debugger/*.m:
tests/exceptions/*.m:
tests/general/*.m:
tests/grade_subdirs/*.m:
tests/purity/*.m:
tests/submodules/*.m:
tests/typeclasses/*.m:
    Update programming style.

tests/declarative_debugger/*.inp:
    Update line numbers in breakpoint commands.
tests/declarative_debugger/*.exp:
    Update expected line numbers.

tests/exceptions/Mercury.options:
tests/general/Mercury.options:
    Disable some warnings that are irrelevant to the test.
2021-07-25 23:26:17 +10:00

64 lines
1.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
% Copyright (C) 1997-1998 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
%
% File: test_exceptions_func.m.
% Main author: fjh.
%
% Test cases for exception handling functions.
%
% XXX we should test nested exception handlers.
%
%---------------------------------------------------------------------------%
:- module test_exceptions_func.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
:- import_module exception.
main(!IO) :-
try(det_throw, R1),
io.print("det_throw: ", !IO),
print_r(R1, !IO), io.nl(!IO),
try(det_succeed, R2),
io.print("det_succeed: ", !IO),
print_r(R2, !IO), io.nl(!IO),
try(semidet_throw, SemidetThrowResult),
io.print("semidet_throw: ", !IO),
print_r(SemidetThrowResult, !IO), io.nl(!IO),
try(semidet_succeed, SemidetSucceedResult),
io.print("semidet_succeed: ", !IO),
print_r(SemidetSucceedResult, !IO), io.nl(!IO),
try(semidet_fail, SemidetFailResult),
io.print("semidet_fail: ", !IO),
print_r(SemidetFailResult, !IO), io.nl(!IO).
:- pred print_r(exception_result(T)::in, io::di, io::uo) is det.
print_r(E, !IO) :-
print(E, !IO).
:- pred det_throw(string::out) is det.
det_throw(throw("det_throw")).
:- pred semidet_throw(string::out) is semidet.
semidet_throw(throw("semidet_throw")).
:- pred det_succeed(string::out) is det.
det_succeed("det_succeed").
:- pred semidet_succeed(string::out) is semidet.
semidet_succeed("semidet_succeed").
:- pred semidet_fail(string::out) is semidet.
semidet_fail("semidet_fail") :-
fail.