[m-rev.] diff: fix failing test cases in the java grade

Julien Fischer jfischer at opturion.com
Sun Feb 7 16:01:09 AEDT 2016


Fix failing test cases in the java grade.

tests/general/environment.m:
     Catch the exception that is thrown if io.set_environment_var/4 cannot
     modify the environment -- this is always the case for Java -- and print
     out what the exception is.  This avoids the stack trace that would otherwise
     be printed.

     Update the coding style in this test.

tests/general/environment.exp2:
     Add an alternative expected output for systems that do not support
     modifying the environment.

tests/general/Mmakefile:
     Shift the 'environment' test case to the list of those that
     require catching exceptions to be supported.

tests/general/float_roundtrip.exp2:
tests/hard_coded/deep_copy.exp4:
     Add new expected outputs to account for differences in the way floats are
     printed.

tests/hard_coded/dir_test.exp4:
tests/warnings/singleton_test.exp3:
     Update these expected outputs.

Julien.

diff --git a/tests/general/Mmakefile b/tests/general/Mmakefile
index 6a84393..570584a 100644
--- a/tests/general/Mmakefile
+++ b/tests/general/Mmakefile
@@ -27,7 +27,6 @@ ORDINARY_PROGS = \
  	double_error			\
  	double_error2			\
  	duplicate_label			\
-	environment			\
  	fail_detism			\
  	float_roundtrip			\
  	float_test			\
@@ -82,6 +81,7 @@ ORDINARY_PROGS = \
  	unsafe_uniqueness

  EXCEPTION_PROGS = \
+	environment			\
  	map_corresponding 		\
  	unused_arg_determinism

diff --git a/tests/general/environment.exp2 b/tests/general/environment.exp2
new file mode 100644
index 0000000..d70456b
--- /dev/null
+++ b/tests/general/environment.exp2
@@ -0,0 +1,4 @@
+Variable "PATH" is set (passed)
+Variable "SHOULD_NOT_BE_SET" is set not set (passed)
+Cannot modify environment on this platform:
+software_error("Could not set environment variable `SHOULD_NOT_BE_SET\'")
diff --git a/tests/general/environment.m b/tests/general/environment.m
index d5db82b..67511ea 100644
--- a/tests/general/environment.m
+++ b/tests/general/environment.m
@@ -2,16 +2,22 @@
  % vim: ts=4 sw=4 et ft=mercury
  %---------------------------------------------------------------------------%
  %
-% Short series of tests for io__get_environment_var and
-% io__set_environment_var.
+% Short series of tests for io.get_environment_var and
+% io.set_environment_var.
  %
  % Author: bromage
+%
+%---------------------------------------------------------------------------%

  :- module environment.
-
  :- interface.
+
  :- import_module io.
-:- pred main(io__state :: di, io__state :: uo) is det.
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%

  :- implementation.

@@ -20,39 +26,54 @@
  :- import_module maybe.
  :- import_module string.

-:- pred environment__test(string, bool, bool, io__state, io__state).
-:- mode environment__test(in, in, in, di, uo) is det.
+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),

-environment__test(Var, ShouldBeSet, ShouldBePrinted) -->
-    io__get_environment_var(Var, MaybeValue),
-    io__write_strings(["Variable \"", Var, "\" is set "]),
-    ( { MaybeValue = yes(Value) } ->
-        ( { ShouldBePrinted = yes } ->
-            io__write_strings(["to \"", Value, "\" "])
+    ( try [io(!IO)] (
+        % So set it...
+        io.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.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 }
+        Ok = ShouldBeSet
      ;
-        io__write_string("not set "),
-        { bool__not(ShouldBeSet, Ok) }
+        MaybeValue = no,
+        io.write_string("not set ", !IO),
+        bool.not(ShouldBeSet, Ok)
      ),
-    ( { Ok = yes } ->
-        io__write_string("(passed)\n")
+    (
+        Ok = yes,
+        io.write_string("(passed)\n", !IO)
      ;
-        io__write_string("(failed)\n")
+        Ok = no,
+        io.write_string("(failed)\n", !IO)
      ).

-main -->
-    % PATH should be set on all Unix systems but may differ
-    % on the different machines that generate .exp and .out files
-    environment__test("PATH", yes, no),
-
-    % This one probably isn't. :-)
-    environment__test("SHOULD_NOT_BE_SET", no, yes),
-
-    % So set it...
-    io__set_environment_var("SHOULD_NOT_BE_SET", "Hello World!"),
-
-    % Did that work?
-    environment__test("SHOULD_NOT_BE_SET", yes, yes).
+%---------------------------------------------------------------------------%
+:- end_module environment.
+%---------------------------------------------------------------------------%
diff --git a/tests/general/float_roundtrip.exp2 b/tests/general/float_roundtrip.exp2
new file mode 100644
index 0000000..a7c62c4
--- /dev/null
+++ b/tests/general/float_roundtrip.exp2
@@ -0,0 +1,5 @@
+0.9092974           : success.
+0.123573124         : success.
+0.987654321012345   : success.
+0.12345678901234566 : success.
+1.8E-10             : success.
diff --git a/tests/hard_coded/deep_copy.exp4 b/tests/hard_coded/deep_copy.exp4
new file mode 100644
index 0000000..0e5b588
--- /dev/null
+++ b/tests/hard_coded/deep_copy.exp4
@@ -0,0 +1,113 @@
+TESTING DISCRIMINATED UNIONS
+two
+two
+two
+one
+one
+one
+three
+three
+three
+apple([9, 5, 1])
+apple([9, 5, 1])
+apple([9, 5, 1])
+banana([three, one, two])
+banana([three, one, two])
+banana([three, one, two])
+zop(3.3, 2.03)
+zop(3.3, 2.03)
+zop(3.3, 2.03)
+zip(3, 2)
+zip(3, 2)
+zip(3, 2)
+zap(3, -2.111)
+zap(3, -2.111)
+zap(3, -2.111)
+wombat
+wombat
+wombat
+foo
+foo
+foo
+tuple_a(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ["a", "b", "c"], 16, 17)
+tuple_a(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ["a", "b", "c"], 16, 17)
+tuple_a(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ["a", "b", "c"], 16, 17)
+tuple_b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ["a", "b", "c"], 16, ["x", "y", "z"])
+tuple_b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ["a", "b", "c"], 16, ["x", "y", "z"])
+tuple_b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ["a", "b", "c"], 16, ["x", "y", "z"])
+tuple_c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ["p", "q"], 17)
+tuple_c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ["p", "q"], 17)
+tuple_c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ["p", "q"], 17)
+tuple_d(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ["d", "e", "f"], 15, ["u", "v", "w"], 17)
+tuple_d(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ["d", "e", "f"], 15, ["u", "v", "w"], 17)
+tuple_d(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ["d", "e", "f"], 15, ["u", "v", "w"], 17)
+
+TESTING POLYMORPHISM
+poly_three(3.33, 4, poly_one(9.11))
+poly_three(3.33, 4, poly_one(9.11))
+poly_three(3.33, 4, poly_one(9.11))
+poly_two(3)
+poly_two(3)
+poly_two(3)
+poly_one([2399.3])
+poly_one([2399.3])
+poly_one([2399.3])
+
+TESTING BUILTINS
+""
+""
+""
+"Hello, world\n"
+"Hello, world\n"
+"Hello, world\n"
+"Foo%sFoo"
+"Foo%sFoo"
+"Foo%sFoo"
+"\""
+"\""
+"\""
+'a'
+'a'
+'a'
+'&'
+'&'
+'&'
+3.14159
+3.14159
+3.14159
+1.128324983E-21
+1.128324983E-21
+1.128324983E-21
+2.23954899E23
+2.23954899E23
+2.23954899E23
+-65
+-65
+-65
+4
+4
+4
+univ_cons(["hi! I\'m a univ!"])
+univ_cons(["hi! I\'m a univ!"])
+univ_cons(["hi! I\'m a univ!"])
+{1, "two", '3', {4, '5', "6"}}
+{1, "two", '3', {4, '5', "6"}}
+{1, "two", '3', {4, '5', "6"}}
+
+TESTING OTHER TYPES
+var(1)
+var(1)
+var(1)
+var_supply(0)
+var_supply(0)
+var_supply(0)
+var_supply(1)
+var_supply(1)
+var_supply(1)
+empty
+empty
+empty
+qwerty(4)
+qwerty(4)
+qwerty(4)
+
diff --git a/tests/hard_coded/dir_test.exp4 b/tests/hard_coded/dir_test.exp4
index e393954..2c8ea73 100644
--- a/tests/hard_coded/dir_test.exp4
+++ b/tests/hard_coded/dir_test.exp4
@@ -122,7 +122,7 @@ dir__path_name_is_root_directory("foo/bar") failed
  "C:\"/"foo" = "C:\/foo".
  "C:"/"C:" = "C:/C:".
  "C:"/"C:\foo" = "C:/C:\foo".
-"."/"/foo" threw exception: software_error("dir./: second argument is absolute")
+"."/"/foo" threw exception: software_error("function `dir./\'/2: Unexpected: second argument is absolute")
  "."/"\foo" = "./\foo".
  "foo"/"bar/baz" = "foo/bar/baz".
  "foo/"/"bar/baz" = "foo/bar/baz".
diff --git a/tests/warnings/singleton_test.exp3 b/tests/warnings/singleton_test.exp3
index 97bb11f..6a93075 100644
--- a/tests/warnings/singleton_test.exp3
+++ b/tests/warnings/singleton_test.exp3
@@ -1,30 +1,30 @@
-singleton_test.m:008: In function `my_append_func'/2:
-singleton_test.m:008:   warning: unresolved polymorphism.
-singleton_test.m:008:   The variables with unbound types were:
-singleton_test.m:008:     L2: V_1
-singleton_test.m:008:     L1: V_1
-singleton_test.m:008:   The unbound type variables will be implicitly bound to
-singleton_test.m:008:   the builtin type `void'.
-singleton_test.m:026: In clause for predicate `singleton_test.my_append'/3:
-singleton_test.m:026:   warning: variable `L2' occurs only once in this scope.
-singleton_test.m:030: In clause for function `singleton_test.my_append_func'/2:
-singleton_test.m:030:   warning: variables `L1, L2' occur only once in this
-singleton_test.m:030:   scope.
-singleton_test.m:031: In clause for function `singleton_test.my_append_func'/2:
-singleton_test.m:031:   warning: variable `T' occurs only once in this scope.
-singleton_test.m:041: In the Java code for predicate
-singleton_test.m:041:   `singleton_test.my_c_pred'/3:
-singleton_test.m:041:   warning: variable `Y' does not occur in the Java code.
-singleton_test.m:058: In the Java code for function
-singleton_test.m:058:   `singleton_test.my_c_func'/2:
-singleton_test.m:058:   warning: variable `X' does not occur in the Java code.
-singleton_test.m:079: In the Java code for predicate
-singleton_test.m:079:   `singleton_test.c_hello_world'/3:
-singleton_test.m:079:   warning: variable `Msg' does not occur in the Java
-singleton_test.m:079:   code.
-singleton_test.m:090: In clause for predicate `singleton_test.test_head'/6:
-singleton_test.m:090:   warning: variable `_D' occurs more than once in this
-singleton_test.m:090:   scope.
-singleton_test.m:090: In clause for predicate `singleton_test.test_head'/6:
-singleton_test.m:090:   warning: variables `A, B' occur only once in this
-singleton_test.m:090:   scope.
+singleton_test.m:013: In function `my_append_func'/2:
+singleton_test.m:013:   warning: unresolved polymorphism.
+singleton_test.m:013:   The variables with unbound types were:
+singleton_test.m:013:     L2: V_1
+singleton_test.m:013:     L1: V_1
+singleton_test.m:013:   The unbound type variables will be implicitly bound to
+singleton_test.m:013:   the builtin type `void'.
+singleton_test.m:031: In clause for predicate `singleton_test.my_append'/3:
+singleton_test.m:031:   warning: variable `L2' occurs only once in this scope.
+singleton_test.m:035: In clause for function `singleton_test.my_append_func'/2:
+singleton_test.m:035:   warning: variables `L1, L2' occur only once in this
+singleton_test.m:035:   scope.
+singleton_test.m:036: In clause for function `singleton_test.my_append_func'/2:
+singleton_test.m:036:   warning: variable `T' occurs only once in this scope.
+singleton_test.m:046: In the Java code for predicate
+singleton_test.m:046:   `singleton_test.my_c_pred'/3:
+singleton_test.m:046:   warning: variable `Y' does not occur in the Java code.
+singleton_test.m:063: In the Java code for function
+singleton_test.m:063:   `singleton_test.my_c_func'/2:
+singleton_test.m:063:   warning: variable `X' does not occur in the Java code.
+singleton_test.m:084: In the Java code for predicate
+singleton_test.m:084:   `singleton_test.c_hello_world'/3:
+singleton_test.m:084:   warning: variable `Msg' does not occur in the Java
+singleton_test.m:084:   code.
+singleton_test.m:095: In clause for predicate `singleton_test.test_head'/6:
+singleton_test.m:095:   warning: variable `_D' occurs more than once in this
+singleton_test.m:095:   scope.
+singleton_test.m:095: In clause for predicate `singleton_test.test_head'/6:
+singleton_test.m:095:   warning: variables `A, B' occur only once in this
+singleton_test.m:095:   scope.



More information about the reviews mailing list