Files
mercury/tests/invalid/magicbox.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

66 lines
2.2 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% This test case is a cut down version of magicbox.m:
%
% Gillian Tee : pptee@cs.mu.oz.au
% Leslie Gondor : leslieg@cs.mu.oz.au
%
% 433-481 - Agent Programming Languages - Project 1
% Department of Computer Science and Software Engineering
% The University of Melbourne
% March/April, 2004
%
%---------------------------------------------------------------------------%
%
% The problem this test case tests for is an overstrong sanity check in
% determinism analysis. The problem scenario is as follows:
%
% 1. The arguments_handler predicate is in a first_soln context.
% 2. So is the outer if-then-else, and its then-part and else-part.
% 3. The then-part, the call to string.to_int, can fail.
% 4. The condition of the other if-then-else is thus in an all_soln context.
% 5. Parts 3 and 4 also hold for the inner if-then-else, making it naturally
% nondet, which is converted into cc_nondet by its being inside a first_soln
% context.
% 6. The then part of the outer if-then-else is semidet, the else part is
% cc_nondet. The sanity check complains that only one of the two arms of the
% switch seems to be in first_soln context. It doesn't see that the then
% part is in a first_soln context too; its detism doesn't say that.
:- module magicbox.
:- interface.
:- import_module io.
:- pred arguments_handler(io.state, io.state, int).
:- mode arguments_handler(di, uo, out) is cc_multi.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module list.
:- import_module string.
arguments_handler(!IO, Length) :-
% Check for correct command-line arguments:
io.command_line_arguments(Arguments, !IO),
(
% Valid arguments - Scenario 1
list.member("-1", Arguments, ArgsSubS1),
list.index0(ArgsSubS1, 1, LengthStr)
->
string.to_int(LengthStr, Length)
;
% Valid arguments - Scenario 2
list.member("-2", Arguments, ArgsSubS2),
list.index0(ArgsSubS2, 2, LengthStr)
->
string.to_int(LengthStr, Length)
;
Length = 0
).