Files
mercury/tests/general/environment.m
Zoltan Somogyi c02eb5163e Carve io.{call_system,environment}.m out of io.m.
library/io.call_system.m:
    Move the code in the "system access predicates" section of io.m
    to this new module.

library/io.environment.m:
    Move the predicates dealing with environment variables in io.m
    to this new module.

library/io.m:
    Delete the code moved to the new modules.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in the new modules, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the types used
    by some parameters of some of the moved predicates.

library/MODULES_DOC:
    List the new modules among the documented modules.

library/library.m:
    List the new modules, including io.file.m (added in a previous change)
    among the documented standard library modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
compiler/fact_table.m:
compiler/handle_options.m:
compiler/make.module_target.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/optimize.m:
compiler/options_file.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_test.m:
library/io.file.m:
mdbcomp/trace_counts.m:
ssdb/ssdb.m:
tests/general/environment.m:
tests/hard_coded/closeable_channel_test.m:
tests/hard_coded/setenv.m:
tests/hard_coded/system_sort.m:
    Call the moved predicates directly in their new modules,
    not indirectly through io.m.
2022-03-08 09:38:27 +11:00

86 lines
2.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Short series of tests for io.get_environment_var and
% io.set_environment_var.
%
% Author: bromage
%
% The .exp file is for backends where io.set_environment_var/4 is supported.
% The .exp2 file is for Java backend where io.set_environment_var/4 is
% *not* supported.
%
%---------------------------------------------------------------------------%
:- module environment.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module bool.
:- import_module io.environment.
:- import_module list.
:- import_module maybe.
:- import_module string.
main(!IO) :-
% PATH should be set on all Unix systems but may differ
% on the different machines that generate .exp and .out files
test("PATH", yes, no, !IO),
% This one probably isn't. :-)
test("SHOULD_NOT_BE_SET", no, yes, !IO),
( try [io(!IO)] (
% So set it...
io.environment.set_environment_var("SHOULD_NOT_BE_SET",
"Hello World!", !IO)
)
then
% Did that work?
environment.test("SHOULD_NOT_BE_SET", yes, yes, !IO)
catch_any E ->
io.write_string("Cannot modify environment on this platform:\n", !IO),
io.write_line(E, !IO)
).
:- pred environment.test(string::in, bool::in, bool::in,
io::di, io::uo) is det.
test(Var, ShouldBeSet, ShouldBePrinted, !IO) :-
io.environment.get_environment_var(Var, MaybeValue, !IO),
io.write_strings(["Variable \"", Var, "\" is set "], !IO),
(
MaybeValue = yes(Value),
(
ShouldBePrinted = yes,
io.write_strings(["to \"", Value, "\" "], !IO)
;
ShouldBePrinted = no
),
Ok = ShouldBeSet
;
MaybeValue = no,
io.write_string("not set ", !IO),
bool.not(ShouldBeSet, Ok)
),
(
Ok = yes,
io.write_string("(passed)\n", !IO)
;
Ok = no,
io.write_string("(failed)\n", !IO)
).
%---------------------------------------------------------------------------%
:- end_module environment.
%---------------------------------------------------------------------------%