diff: string__format bug fix
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Oct 28 02:32:11 AEDT 1998
library/string.m:
Fix a bug in string__format: it was not reporting an error
in the case where the argument list had more elements
than was appropriate for the format string.
tests/general/Mmakefile:
tests/general/string_format_test_2.m:
tests/general/string_format_test_2.exp:
tests/general/string_format_test_3.m:
tests/general/string_format_test_3.exp:
Test cases for the above-mentioned bug fix.
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.106
diff -u -r1.106 string.m
--- string.m 1998/08/24 04:45:28 1.106
+++ string.m 1998/10/27 15:04:01
@@ -815,7 +815,13 @@
% is not efficient. Instead, many short strings are added to the front
% of a (long) and growing string.
%
-string__format_2([], _, "").
+string__format_2([], Vars_in, Result) :-
+ ( Vars_in = [] ->
+ Result = ""
+ ;
+ error(
+ "string__format: argument list has more elements than format string")
+ ).
string__format_2([Achar|As], Vars_in, Ostring) :-
(
Achar = '%'
@@ -833,7 +839,8 @@
string__format_2(As_out, Vars_out, String_2),
string__append(String_1, String_2, Ostring)
;
- error("string__format: Too few variables.")
+ error(
+ "string__format: argument list has fewer elements than format string")
)
)
;
Index: tests/general/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.23
diff -u -r1.23 Mmakefile
--- Mmakefile 1998/09/21 13:18:01 1.23
+++ Mmakefile 1998/10/27 15:13:51
@@ -57,6 +57,8 @@
semidet_map \
set_test \
string_format_test \
+ string_format_test_2 \
+ string_format_test_3 \
string_test \
string_test_2 \
univ \
@@ -66,6 +68,11 @@
# (i.e. tabling) and tabling is not yet implemented for non-gc grades.
NOT_WORKING = dnf
+#-----------------------------------------------------------------------------#
+#
+# Some test cases need special handling.
+#
+
# mode_inf and mode_inf_bug need to be compiled with `--infer-all'.
MCFLAGS-mode_inf = --infer-all
MCFLAGS-mode_inf_bug = --infer-all
@@ -83,6 +90,15 @@
# tracking it down.
MLFLAGS-string_test = --no-strip
+# string_format_test_2 and string__format_test_3 are expected to fail
+# (string__format should call error/1 for these test cases)
+# so we need to ignore the exit status (hence the leading `-')
+string_format_test_2.out: string_format_test_2
+ -./string_format_test_2 > string_format_test_2.out 2>&1;
+string_format_test_3.out: string_format_test_3
+ -./string_format_test_3 > string_format_test_2.out 2>&1;
+
+#-----------------------------------------------------------------------------#
DEPENDS=$(PROGS:%=%.depend)
OUTS= $(PROGS:%=%.out)
Index: tests/general/string_format_test_2.exp
===================================================================
RCS file: string_format_test_2.exp
diff -N string_format_test_2.exp
--- /dev/null Wed Oct 28 02:21:38 1998
+++ string_format_test_2.exp Wed Oct 28 02:16:15 1998
@@ -0,0 +1,2 @@
+Software error: string__format: argument list has more elements than format string
+Stack dump not available in this grade.
Index: tests/general/string_format_test_2.m
===================================================================
RCS file: string_format_test_2.m
diff -N string_format_test_2.m
--- /dev/null Wed Oct 28 02:21:38 1998
+++ string_format_test_2.m Wed Oct 28 02:14:33 1998
@@ -0,0 +1,13 @@
+:- module string_format_test_2.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module list, string.
+
+main --> io__format("foo\n", [i(42)]).
Index: tests/general/string_format_test_3.exp
===================================================================
RCS file: string_format_test_3.exp
diff -N string_format_test_3.exp
--- /dev/null Wed Oct 28 02:21:38 1998
+++ string_format_test_3.exp Wed Oct 28 02:29:31 1998
@@ -0,0 +1,2 @@
+Software error: string__format: argument list has fewer elements than format string
+Stack dump not available in this grade.
Index: tests/general/string_format_test_3.m
===================================================================
RCS file: string_format_test_3.m
diff -N string_format_test_3.m
--- /dev/null Wed Oct 28 02:21:38 1998
+++ string_format_test_3.m Wed Oct 28 02:14:41 1998
@@ -0,0 +1,13 @@
+:- module string_format_test_3.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module list, string.
+
+main --> io__format("%s\n", []).
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list