[m-rev.] diff: add a test case for a recent bug fix.
Julien Fischer
jfischer at opturion.com
Mon Sep 2 17:01:50 AEST 2019
This is a test case for the recent bug fix for problem with arrays of
unsigned integer types in the C# grade that Mark reported. (I forgot to
post the fix to the list, in case anyone is wondering where it is.)
Note that this test still fails in the C# grade for other reasons
that I am currently looking into.
-------------------------------------
Add a test case for a recent bug fix.
Add a regression test for the bug fixed in commit 65f683e. There were multiple
places that had the same underlying issue; the new test case covers those as
well.
tests/hard_coded/Mmakefile:
tests/hard_coded/array_primitives.{m,exp}:
Add the new test case.
Julien.
diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index e68cec0..390eafe 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -16,6 +16,7 @@ ORDINARY_PROGS = \
array_all_tf \
array_copy \
array_gen \
+ array_primitives \
array_sort \
array_test \
array_test2 \
diff --git a/tests/hard_coded/array_primitives.exp b/tests/hard_coded/array_primitives.exp
index e69de29..a49b169 100644
--- a/tests/hard_coded/array_primitives.exp
+++ b/tests/hard_coded/array_primitives.exp
@@ -0,0 +1,72 @@
+*** Testing with element type: int8 ****
+init = array([2i8, 2i8, 2i8, 2i8, 2i8])
+generate = array([2i8, 2i8, 2i8, 2i8, 2i8])
+resize = array([2i8, 2i8, 2i8, 2i8, 2i8, 3i8, 3i8])
+shrink = array([2i8, 2i8])
+
+*** Testing with element type: uint8 ****
+init = array([2u8, 2u8, 2u8, 2u8, 2u8])
+generate = array([2u8, 2u8, 2u8, 2u8, 2u8])
+resize = array([2u8, 2u8, 2u8, 2u8, 2u8, 3u8, 3u8])
+shrink = array([2u8, 2u8])
+
+*** Testing with element type: int16 ****
+init = array([2i16, 2i16, 2i16, 2i16, 2i16])
+generate = array([2i16, 2i16, 2i16, 2i16, 2i16])
+resize = array([2i16, 2i16, 2i16, 2i16, 2i16, 3i16, 3i16])
+shrink = array([2i16, 2i16])
+
+*** Testing with element type: uint16 ****
+init = array([2u16, 2u16, 2u16, 2u16, 2u16])
+generate = array([2u16, 2u16, 2u16, 2u16, 2u16])
+resize = array([2u16, 2u16, 2u16, 2u16, 2u16, 3u16, 3u16])
+shrink = array([2u16, 2u16])
+
+*** Testing with element type: int32 ****
+init = array([2i32, 2i32, 2i32, 2i32, 2i32])
+generate = array([2i32, 2i32, 2i32, 2i32, 2i32])
+resize = array([2i32, 2i32, 2i32, 2i32, 2i32, 3i32, 3i32])
+shrink = array([2i32, 2i32])
+
+*** Testing with element type: uint32 ****
+init = array([2u32, 2u32, 2u32, 2u32, 2u32])
+generate = array([2u32, 2u32, 2u32, 2u32, 2u32])
+resize = array([2u32, 2u32, 2u32, 2u32, 2u32, 3u32, 3u32])
+shrink = array([2u32, 2u32])
+
+*** Testing with element type: int64 ****
+init = array([2i64, 2i64, 2i64, 2i64, 2i64])
+generate = array([2i64, 2i64, 2i64, 2i64, 2i64])
+resize = array([2i64, 2i64, 2i64, 2i64, 2i64, 3i64, 3i64])
+shrink = array([2i64, 2i64])
+
+*** Testing with element type: uint64 ****
+init = array([2u64, 2u64, 2u64, 2u64, 2u64])
+generate = array([2u64, 2u64, 2u64, 2u64, 2u64])
+resize = array([2u64, 2u64, 2u64, 2u64, 2u64, 3u64, 3u64])
+shrink = array([2u64, 2u64])
+
+*** Testing with element type: int ****
+init = array([2, 2, 2, 2, 2])
+generate = array([2, 2, 2, 2, 2])
+resize = array([2, 2, 2, 2, 2, 3, 3])
+shrink = array([2, 2])
+
+*** Testing with element type: uint ****
+init = array([2u, 2u, 2u, 2u, 2u])
+generate = array([2u, 2u, 2u, 2u, 2u])
+resize = array([2u, 2u, 2u, 2u, 2u, 3u, 3u])
+shrink = array([2u, 2u])
+
+*** Testing with element type: float ****
+init = array([2.0, 2.0, 2.0, 2.0, 2.0])
+generate = array([2.0, 2.0, 2.0, 2.0, 2.0])
+resize = array([2.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0])
+shrink = array([2.0, 2.0])
+
+*** Testing with element type: string ****
+init = array(["foo", "foo", "foo", "foo", "foo"])
+generate = array(["foo", "foo", "foo", "foo", "foo"])
+resize = array(["foo", "foo", "foo", "foo", "foo", "bar", "bar"])
+shrink = array(["foo", "foo"])
+
diff --git a/tests/hard_coded/array_primitives.m b/tests/hard_coded/array_primitives.m
index e69de29..8df63ea 100644
--- a/tests/hard_coded/array_primitives.m
+++ b/tests/hard_coded/array_primitives.m
@@ -0,0 +1,76 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%---------------------------------------------------------------------------%
+% This is a regression test for the bug fixed in commit 65f683e. That bug was
+% an abort due to an InvalidCastException in the C# grades. The problem was
+% that the C# implementation of ML_new_array omitted the special case handling
+% of primitive unsigned integer types. More generally, several of the array
+% primitives (ML_new_array, ML_unsafe_new_array, ML_resize_array and
+% ML_shrink_array), all need to implement the special case handling of
+% primitive types, in both the C# and Java grades. This test checks that
+% special case handling for primitives is present for all of those operations.
+%
+%---------------------------------------------------------------------------%
+
+:- module array_primitives.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module array.
+:- import_module list.
+:- import_module string.
+:- import_module type_desc.
+
+%---------------------------------------------------------------------------%
+
+main(!IO) :-
+ do_test(2i8, 3i8, !IO),
+ do_test(2u8, 3u8, !IO),
+ do_test(2i16, 3i16, !IO),
+ do_test(2u16, 3u16, !IO),
+ do_test(2i32, 3i32, !IO),
+ do_test(2u32, 3u32, !IO),
+ do_test(2i64, 3i64, !IO),
+ do_test(2u64, 3u64, !IO),
+
+ do_test(2, 3, !IO),
+ do_test(2u, 3u, !IO),
+ do_test(2.0, 3.0, !IO),
+
+ do_test("foo", "bar", !IO).
+
+:- pred do_test(T::in, T::in, io::di, io::uo) is det.
+
+do_test(E, F, !IO) :-
+ TypeName = type_name(type_of(E)),
+
+ io.format("*** Testing with element type: %s ****\n", [s(TypeName)], !IO),
+ array.init(5, E, InitArray), % Test ML_new_array
+ io.write_string("init = ", !IO),
+ io.write_line(InitArray, !IO),
+
+ GenArray = array.generate(5, (func(_) = E)), % Test ML_unsafe_new_array
+ io.write_string("generate = ", !IO),
+ io.write_line(GenArray, !IO),
+
+ array.resize(7, F, InitArray, ResizedArray), % Test ML_array_resize
+ io.write_string("resize = ", !IO),
+ io.write_line(ResizedArray, !IO),
+
+ array.shrink(2, GenArray, ShrunkArray), % Test ML_shrink_array
+ io.write_string("shrink = ", !IO),
+ io.write_line(ShrunkArray, !IO),
+
+ io.nl(!IO).
+
+%---------------------------------------------------------------------------%
+:- end_module array_primitives.
+%---------------------------------------------------------------------------%
More information about the reviews
mailing list