[m-rev.] diff: improve test coverage for foreign_{decl, code} pragmas

Julien Fischer jfischer at opturion.com
Thu May 26 13:01:46 AEST 2016


I'll be improving the actual content of these in a later change.

--------------------

Improve test coverage for foreign_{decl,code} pragmas.

tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
     Test for the error messages caused by syntax errors.

tests/invalid/Mmakefile:
      Include the new tests.

Julien.

diff --git a/tests/invalid/Mmakefile b/tests/invalid/Mmakefile
index 7efb373..6f570bf 100644
--- a/tests/invalid/Mmakefile
+++ b/tests/invalid/Mmakefile
@@ -49,6 +49,8 @@ SINGLEMODULE= \
  	bad_consider_used \
  	bad_detism \
  	bad_end_module \
+	bad_foreign_code \
+	bad_foreign_decl \
  	bad_foreign_enum \
  	bad_foreign_export \
  	bad_foreign_export_enum \
diff --git a/tests/invalid/bad_foreign_code.err_exp b/tests/invalid/bad_foreign_code.err_exp
new file mode 100644
index 0000000..73942af
--- /dev/null
+++ b/tests/invalid/bad_foreign_code.err_exp
@@ -0,0 +1,14 @@
+bad_foreign_code.m:017: Error: invalid `:- pragma foreign_code' declaration:
+bad_foreign_code.m:017:   wrong number of arguments.
+bad_foreign_code.m:021: Error: invalid `:- pragma foreign_code' declaration:
+bad_foreign_code.m:021:   wrong number of arguments.
+bad_foreign_code.m:025: Error: invalid `:- pragma foreign_code' declaration:
+bad_foreign_code.m:025:   invalid language parameter.
+bad_foreign_code.m:029: Error: invalid `:- pragma foreign_code' declaration:
+bad_foreign_code.m:029:   expected string for foreign code.
+bad_foreign_code.m:033: Error: invalid `:- pragma foreign_code' declaration:
+bad_foreign_code.m:033:   expected string for foreign code.
+bad_foreign_code.m:043: Error: invalid `:- pragma foreign_code' declaration:
+bad_foreign_code.m:043:   invalid language parameter.
+bad_foreign_code.m:044: Error: invalid `:- pragma foreign_code' declaration:
+bad_foreign_code.m:044:   expected string for foreign code.
diff --git a/tests/invalid/bad_foreign_code.m b/tests/invalid/bad_foreign_code.m
new file mode 100644
index 0000000..f79ba2d
--- /dev/null
+++ b/tests/invalid/bad_foreign_code.m
@@ -0,0 +1,45 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+%
+% Test for error messages produced by syntax errors in 'foreign_code' pragmas.
+%
+
+:- module bad_foreign_code.
+:- interface.
+
+:- type foo ---> foo.
+
+:- implementation.
+
+    % Too few arguments.
+    %
+:- pragma foreign_code("C").
+
+    % Too many arguments.
+    %
+:- pragma foreign_code("C", "", "").
+
+    % Invalid foreign language.
+    %
+:- pragma foreign_code("InvalidLanguage", "").
+
+    % Code argument is not a string or include_file.
+    %
+:- pragma foreign_code("C", 2222).
+
+    % Argument of include_file is not a string.
+    %
+:- pragma foreign_code("C", include_file(3333)).
+
+    % Argument of include_file is the empty string.
+    %
+:- pragma foreign_code("C", include_file("")).
+
+    % Check that the correct contexts are associated with errors
+    % for each argument.
+    %
+:- pragma foreign_code(
+    "InvalidLanguage",
+    6666
+).
diff --git a/tests/invalid/bad_foreign_decl.err_exp b/tests/invalid/bad_foreign_decl.err_exp
new file mode 100644
index 0000000..6e4a2c7
--- /dev/null
+++ b/tests/invalid/bad_foreign_decl.err_exp
@@ -0,0 +1,18 @@
+bad_foreign_decl.m:017: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:017:   foreign_decl("C").
+bad_foreign_decl.m:021: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:021:   foreign_decl("C", local, "", "").
+bad_foreign_decl.m:025: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:025:   invalid language parameter.
+bad_foreign_decl.m:029: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:029:   expected string or include_file for foreign
+bad_foreign_decl.m:029:   declaration code.
+bad_foreign_decl.m:033: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:033:   foreign_decl("C", lcoal, "").
+bad_foreign_decl.m:037: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:037:   foreign_decl("C", 4444, "").
+bad_foreign_decl.m:041: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:041:   expected string or include_file for foreign
+bad_foreign_decl.m:041:   declaration code.
+bad_foreign_decl.m:050: Error: invalid `:- pragma foreign_decl' declaration:
+bad_foreign_decl.m:050:   foreign_decl("InvalidLanguage", lcoal, 7777).
diff --git a/tests/invalid/bad_foreign_decl.m b/tests/invalid/bad_foreign_decl.m
new file mode 100644
index 0000000..8c32d54
--- /dev/null
+++ b/tests/invalid/bad_foreign_decl.m
@@ -0,0 +1,54 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+%
+% Test for error messages produced by syntax errors in 'foreign_decl' pragmas.
+%
+
+:- module bad_foreign_decl.
+:- interface.
+
+:- type foo ---> foo.
+
+:- implementation.
+
+    % Too few arguments.
+    %
+:- pragma foreign_decl("C").
+
+    % Too many arguments.
+    %
+:- pragma foreign_decl("C", local, "", "").
+
+    % Invalid foreign language.
+    %
+:- pragma foreign_decl("InvalidLanguage", "").
+
+    % DeclCode argument is not a string or include_file.
+    %
+:- pragma foreign_decl("C", 1234).
+
+    % 'local' is misspelled.
+    %
+:- pragma foreign_decl("C", lcoal, "").
+
+    % 'local' is an integer.
+    %
+:- pragma foreign_decl("C", 4444, "").
+
+    % Argument of include file is not a string.
+    %
+:- pragma foreign_decl("C", include_file(5555)).
+
+    % Argument of include_file is an empty string.
+    % XXX The compiler currently accepts this.
+:- pragma foreign_decl("C", include_file("")).
+
+    % Check that the correct contexts are associated with errors
+    % for each argument.  (XXX they're currently not!)
+    %
+:- pragma foreign_decl(
+    "InvalidLanguage",
+    lcoal,
+    7777
+).


More information about the reviews mailing list