Prolog Coding Guidelines: Difference between revisions

Line 19: Line 19:
:- module_info(group,kernel).
:- module_info(group,kernel).
:- module_info(description,'This module does wonderful things').
:- module_info(description,'This module does wonderful things').
:- module_info(revision,'$Rev: 9558 $').
:- module_info(lastchanged,'$LastChangedDate: 2011-11-17 12:09:15 +0100 (Thu, 17 Nov 2011) $').
</pre>
</pre>
Afterwards run
<pre>
  svn propset svn:keywords "Date Revision" MYMODULE.pl
</pre>
so that svn can automatically update the revision and last changed information.
This is important for the [http://nightly.cobra.cs.uni-duesseldorf.de/coverage/html/ automatically generated coverage reports].


= Unit Tests =
= Unit Tests =

Revision as of 10:02, 6 March 2013

General Guidelines

Please ensure that there are no compilation errors or warnings when checking in. Also, try to ensure that there are no errors when loading the files in Spider (Eclipse). Ideally, try to get rid of warnings as well.

Have a look at the paper by [Covington et al.] on Prolog coding guidelines.

Module Information

Every module should be annotated with module information. This is used by our coverage analysis tool.

:- module(MYMODULE, [  exported_predicate/arity, ... ]).

:- use_module(tools).

:- module_info(group,kernel).
:- module_info(description,'This module does wonderful things').

Unit Tests

Unit tests should be setup using the self_check module.

:- use_module(self_check).

Afterwards you can use the following to add new unit tests:

:- assert_must_succeed((bsets_clp:empty_sequence([]))).
:- assert_must_fail((bsets_clp:empty_sequence([int(1)]))).

These tests can be run manually from the ProB Tcl/Tk version, from the command-line using the -self_check command. They will also be automatically run on our jenkins server after committing.

Errors

Errors should be raised using one of the add_error predicates in the error_manager module. This will ensure that the errors are brought to the attention of the user in an appropriate way, depending on whether the Rodin, the Tcl/Tk, the command-line version is run and also depending on whether the tool is in testing and/or batch mode.

Preferences

Preferences should be declared in the preferences</pl> module. Each preference must have a default value, a textual description, a type and category. Optionally, a short string for setting the preference from the command-line can be given (using the -p PREF VALUE switch).