Files
mercury/tests/trailing/tu_test1.m
Zoltan Somogyi fdd141bf77 Clean up the tests in the other test directories.
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
    Make these tests use four-space indentation, and ensure that
    each module is imported on its own line. (I intend to use the latter
    to figure out which subdirectories' tests can be executed in parallel.)

    These changes usually move code to different lines. For the tests
    that check compiler error messages, expect the new line numbers.

browser/cterm.m:
browser/tree234_cc.m:
    Import only one module per line.

tests/hard_coded/boyer.m:
    Fix something I missed.
2015-02-16 12:32:18 +11:00

106 lines
2.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
:- module tu_test1.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module solutions.
%---------------------------------------------------------------------------%
main(!IO) :-
solutions(test(1), Solns),
io.write(Solns, !IO),
io.nl(!IO).
:- pred test(int::in, int::out) is nondet.
test(X, Y) :-
promise_pure (
between(X, 10, Y),
impure save_ref_on_trail(Y),
is_correct(Y)
).
:- pred is_correct(int::in) is semidet.
is_correct(5).
is_correct(7).
:- pred between(int::in, int::in, int::out) is multi.
between(N, _, N).
between(L, U, N) :-
L < U,
between(L + 1, U, N).
:- impure pred save_ref_on_trail(int::in) is det.
:- pragma foreign_proc("C",
save_ref_on_trail(I::in),
[will_not_call_mercury, may_modify_trail],
"
MR_trail_function(print_entry, (void *)I);
").
:- pragma foreign_decl("C", "
#include <stdio.h>
#include <stdlib.h>
extern void print_entry(void *, MR_untrail_reason);
").
:- pragma foreign_code("C", "
void
print_entry(void *value, MR_untrail_reason reason)
{
switch (reason) {
case MR_undo:
printf(
\"undo %\" MR_INTEGER_LENGTH_MODIFIER \"d\\n\",
(MR_Integer)value);
break;
case MR_solve:
printf(
\"solve (soft commit) %\" MR_INTEGER_LENGTH_MODIFIER \"d\\n\",
(MR_Integer)value);
break;
case MR_commit:
printf(
\"*** unexpected (hard) commit %\" MR_INTEGER_LENGTH_MODIFIER \"d\\n\",
(MR_Integer)value);
break;
case MR_retry:
printf(
\"*** unexpected retry %\" MR_INTEGER_LENGTH_MODIFIER \"d\\n\",
(MR_Integer)value);
break;
case MR_exception:
printf(
\"*** unexpected exception %\" MR_INTEGER_LENGTH_MODIFIER \"d\\n\",
(MR_Integer)value);
break;
default:
printf(\"*** Unexpected call to print_entry\");
}
}
").
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%