mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 12:53:47 +00:00
tests/general/read_dir_regression.m:
Fix the code that canonicalized error messages for C#.
It probably broke when we added a "can't open input file:" prefix
to the error message, because the quote in "can't" confused it.
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_helper_1.m:
Fix several things to make this test case work.
- Add a foreign_import_module pragma for the helper module.
There was one originally, but it was marked as being for "il",
and the pragma was deleted, not replaced, when the IL backend
was deleted.
- Refer to the foo function and the foo2 predicate that
the main module imports from the helper module by their
actual names in the compiler-generated C# code.
(The old names the test used were probably IL-specific,
though I am not sure.)
- Invoke the foo function as a function; we used to invoke it as
a predicate. (The C# calling convention may have changed
in the meantime, and in fact, the original convention could have
been for Managed C++ instead.)
- Make the predicate exported by the C# foreign_code in the
helper module public.
- Initialize a variable passed by reference in order to avoid
an error message from the C# compiler.
Add an XXX about the code of foreign_import_module.m containing
two just-about-identical halves.
tests/EXPECT_FAIL_TESTS.csharp:
Stop expecting the foreign_import_module test case to fail.
tests/hard_coded/dst_test.m:
Improve programming style, and fix some typos.
74 lines
2.7 KiB
Mathematica
74 lines
2.7 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% Regression test for a problem where I/O errors were being reported as EOF.
|
|
%
|
|
% The .exp file is for the C grades (on Unix like systems).
|
|
% The .exp2 file is for the Java grades.
|
|
% The .exp3 file is for the C# grades.
|
|
% The .exp4 file is for the C grades (on Windows).
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module read_dir_regression.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module string.
|
|
:- import_module list.
|
|
|
|
main(!IO) :-
|
|
io.open_input(".", FileResult, !IO),
|
|
(
|
|
FileResult = ok(File),
|
|
read_line(File, LineResult, !IO),
|
|
(
|
|
LineResult = ok(_),
|
|
io.write_string("ok\n", !IO)
|
|
;
|
|
LineResult = eof,
|
|
io.write_string("eof\n", !IO)
|
|
;
|
|
LineResult = error(Error),
|
|
io.format("read failed: %s\n", [s(error_message(Error))], !IO)
|
|
),
|
|
io.close_input(File, !IO)
|
|
;
|
|
FileResult = error(Error),
|
|
ErrorMsg0 = io.error_message(Error),
|
|
% We use the approach below because over time, ErrorMsg0 has been both
|
|
% "Access to the path 'xyz' is denied." and
|
|
% "can't open input file: Access to the path 'xyz' is denied.;
|
|
% note the presence of an extra quote in "can't".
|
|
%
|
|
% The code below can cope with both two and three quotes in ErrorMsg0,
|
|
% and therefore with both three and four elements in QuoteChunks0.
|
|
% And if ever needed, with higher numbers as well.
|
|
QuoteChunks0 = string.split_at_char('\'', ErrorMsg0),
|
|
list.reverse(QuoteChunks0, RevQuoteChunks0),
|
|
( if
|
|
RevQuoteChunks0 =
|
|
[LastChunk1, _PathNameChunk, LastChunk3 | RevEarlyChunks],
|
|
% The text before has to end with "Access to the path ",
|
|
% but what comes before that does not matter.
|
|
string.remove_suffix(LastChunk3, "Access to the path ", _),
|
|
LastChunk1 = " is denied."
|
|
then
|
|
% Replace an error message that reports a path that may be
|
|
% workspace-specific, with the standard path we put into
|
|
% the .expN files, which is the current directory.
|
|
RevQuoteChunks = [LastChunk1, ".", LastChunk3 | RevEarlyChunks],
|
|
list.reverse(RevQuoteChunks, QuoteChunks),
|
|
ErrorMsg = string.join_list("'", QuoteChunks)
|
|
else
|
|
ErrorMsg = ErrorMsg0
|
|
),
|
|
io.format("open failed: %s\n", [s(ErrorMsg)], !IO)
|
|
).
|