on master help sign in
Updates

+ Moved package listings to reference manual. + Added compact package description to tutorial. + Added section on testing idris packages.

commit9f042575e190b4b2b30085edabfa6b5ff7f560b2 authorJan de Muijnck-Hughes <jfdm@st-andrews.ac.uk> dateTue 23 Jun 2015, 12:25 (11 years ago) parent8b46d8f
6 files changed+201−68
docs/index.rst+2 docs/reference/index.rst+1−2 docs/reference/packages.rst+101 docs/tutorial/index.rst+1 docs/tutorial/packages.rst+30−66 docs/tutorial/testing.rst+66
docs/index.rst+2
@@ -39,6 +39,7 @@ The Idris Tutorial
3939 tutorial/classes
4040 tutorial/modules
4141 tutorial/packages
42+ tutorial/testing
4243 tutorial/interp
4344 tutorial/views
4445 tutorial/theorems
@@ -101,6 +102,7 @@ Language Reference
101102 :maxdepth: 1
102103
103104 reference/documenting
105+ reference/packages
104106 reference/uniqueness-types
105107 reference/ffi
106108 reference/erasure
docs/reference/index.rst+1−2
@@ -21,6 +21,7 @@ This will tell you how Idris works, for using it you should read the Idris Tutor
2121 :maxdepth: 1
2222
2323 documenting
24+ packages
2425 uniqueness-types
2526 ffi
2627 erasure
@@ -33,5 +34,3 @@ This will tell you how Idris works, for using it you should read the Idris Tutor
3334 language-extensions
3435 elaborator-reflection
3536 misc
36−
37−
docs/reference/packages.rstnew file+101
@@ -0,0 +1,101 @@
1+.. _ref-sect-packages:
2+
3+********
4+Packages
5+********
6+
7+Idris includes a simple system for building packages from a
8+package description file. These files can be used with the Idris
9+compiler to manage the development process of your Idris
10+programmes and packages.
11+
12+Package Descriptions
13+====================
14+
15+A package description includes the following:
16+
17++ A header, consisting of the keyword package followed by the package name.
18++ Fields describing package contents, ``<field> = <value>``
19+
20+At least one field must be the modules field, where the value is a
21+comma separated list of modules. For example, a library test which
22+has two modules ``foo.idr`` and ``bar.idr`` as source files would be
23+written as follows::
24+
25+ package foo
26+
27+ modules = foo, bar
28+
29+Other examples of package files can be found in the ``libs`` directory
30+of the main Idris repository, and in `third-party libraries <https://github.com/idris-lang/Idris-dev/wiki/Libraries>`_.
31+
32+Common Fields
33+-------------
34+
35+Other common fields which may be present in an ``ipkg`` file are:
36+
37++ ``sourcedir = <dir>``, which takes the directory (relative to the
38+ current directory) which contains the source. Default is the current
39+ directory.
40+
41++ ``executable = <output>``, which takes the name of the executable
42+ file to generate.
43+
44++ ``main = <module>``, which takes the name of the main module, and
45+ must be present if the executable field is present.
46+
47++ ``opts = "<idris options>"``, which allows options (such as other
48+ packages) to be passed to Idris.
49+
50+Binding to C
51+------------
52+
53+In more advanced cases, particularly to support creating bindings to
54+external ``C`` libraries, the following options are available:
55+
56++ ``makefile = <file>``, which specifies a ``Makefile``, to be built
57+ before the Idris modules, for example to support linking with a
58+ ``C`` library.
59+
60++ ``libs = <libs>``, which takes a comma separated list of libraries
61+ which must be present for the package to be usable.
62+
63++ ``objs = <objs>``, which takes a comma separated list of additional
64+ object files to be installed, perhaps generated by the ``Makefile``.
65+
66+Testing
67+--------
68+
69+For testing Idris packages there is a rudimentary testing harness, run in the ``IO`` context.
70+The ``iPKG`` file is used to specify the functions used for testing.
71+The following option is available:
72+
73++ ``tests = <test functions>``, which takes the qualified names of all test functions to be run.
74+
75+.. IMPORTANT::
76+ The modules containing the test functions must also be added to the list of modules.
77+
78+Using Package files
79+===================
80+
81+Given an Idris package file ``text.ipkg`` it can be used with the Idris compiler as follows:
82+
83++ ``idris --build test.ipkg`` will build all modules in the package
84+
85++ ``idris --install test.ipkg`` will install the package, making it
86+ accessible by other Idris libraries and programs.
87+
88++ ``idris --clean test.ipkg`` will delete all intermediate code and
89+ executable files generated when building.
90+
91++ ``idris --mkdoc test.ipkg`` will build HTML documentation for your package in the folder ``test_doc`` in your project's root directory.
92+
93++ ``idris --checkpkg test.ipkg`` will type check all modules in the package only. This differs from build that type checks **and** generates code.
94+
95++ ``idris --testpkg test.ipkg`` will compile and run any embedded tests you have specified in the ``tests`` paramater.
96+
97+Once the test package has been installed, the command line option
98+``--package test`` makes it accessible (abbreviated to ``-p test``).
99+For example::
100+
101+ idris -p test Main.idr
docs/tutorial/index.rst+1
@@ -24,6 +24,7 @@ The is the Idris Tutorial. It will teach you about programming in the Idris Lang
2424 classes
2525 modules
2626 packages
27+ testing
2728 interp
2829 views
2930 theorems
docs/tutorial/packages.rst+30−66
@@ -1,13 +1,10 @@
1−.. _sect-packages:
2−
31********
42Packages
53********
64
7−Idris includes a simple system for building packages from a
8−package description file. These files can be used with the Idris
9−compiler to manage the development process of your Idris
10−programmes and packages.
5+
6+Idris includes a simple build system for building packages and executables from a named package description file.
7+These files can be used with the Idris compiler to manage the development process .
118
129Package Descriptions
1310====================
@@ -18,84 +15,51 @@ A package description includes the following:
1815+ Fields describing package contents, ``<field> = <value>``
1916
2017At least one field must be the modules field, where the value is a
21−comma separated list of modules. For example, a library test which
22−has two modules ``foo.idr`` and ``bar.idr`` as source files would be
23−written as follows::
18+comma separated list of modules. For example, given an idris package
19+``maths`` that has modules ``Maths.idr``, ``Maths.NumOps.idr``,
20+``Maths.BinOps.idr``, and ``Maths.HexOps.idr``, the corresponding
21+package file would be::
22+
23+ package maths
2424
25− package foo
25+ modules = Maths
26+ , Maths.NumOps
27+ , Maths.BinOps
28+ , Maths.HexOps
2629
27− modules = foo, bar
2830
2931Other examples of package files can be found in the ``libs`` directory
3032of the main Idris repository, and in `third-party libraries <https://github.com/idris-lang/Idris-dev/wiki/Libraries>`_.
33+More details including a complete listing of available fields can be found in :ref:`ref-sect-packages`.
3134
32−Common Fields
33−-------------
34−
35−Other common fields which may be present in an ``ipkg`` file are:
36−
37−+ ``sourcedir = <dir>``, which takes the directory (relative to the
38− current directory) which contains the source. Default is the current
39− directory.
40−
41−+ ``executable = <output>``, which takes the name of the executable
42− file to generate.
43−
44−+ ``main = <module>``, which takes the name of the main module, and
45− must be present if the executable field is present.
46−
47−+ ``opts = "<idris options>"``, which allows options (such as other
48− packages) to be passed to Idris.
49−
50−Binding to C
51−------------
52−
53−In more advanced cases, particularly to support creating bindings to
54−external ``C`` libraries, the following options are available:
55−
56−+ ``makefile = <file>``, which specifies a ``Makefile``, to be built
57− before the Idris modules, for example to support linking with a
58− ``C`` library.
59−
60−+ ``libs = <libs>``, which takes a comma separated list of libraries
61− which must be present for the package to be usable.
62−
63−+ ``objs = <objs>``, which takes a comma separated list of additional
64− object files to be installed, perhaps generated by the ``Makefile``.
65−
66−Testing
67−--------
68−
69−For testing Idris packages, there is a rudimentary testing harness, which is run in the ``IO`` context, built into Idris.
70−This allows for testing modules containting functions that test aspects of your package to be run automatically in a fresh environment on your computer.
71−All test functions must return ``IO ()``, and are listed in the ``ipkg`` file using the field:
72−
73−+ ``tests = <test functions>``, which takes the qualified names of all test functions to be run.
74−
75−.. IMPORTANT::
76− The modules containing the test functions must also be added to the list of modules.
7735
7836Using Package files
7937===================
8038
81−Given an Idris package file ``text.ipkg`` it can be used with the Idris compiler as follows:
39+Given an Idris package file ``maths.ipkg`` it can be used with the Idris compiler as follows:
8240
83−+ ``idris --build test.ipkg`` will build all modules in the package
41++ ``idris --build maths.ipkg`` will build all modules in the package
8442
85−+ ``idris --install test.ipkg`` will install the package, making it
43++ ``idris --install maths.ipkg`` will install the package, making it
8644 accessible by other Idris libraries and programs.
8745
88−+ ``idris --clean test.ipkg`` will delete all intermediate code and
46++ ``idris --clean maths.ipkg`` will delete all intermediate code and
8947 executable files generated when building.
9048
91−+ ``idris --mkdoc test.ipkg`` will build HTML documentation for your package in the folder ``test_doc`` in your project's root directory.
49++ ``idris --mkdoc maths.ipkg`` will build HTML documentation for your
50+ package in the folder ``maths_doc`` in your project's root
51+ directory.
9252
93−+ ``idris --checkpkg test.ipkg`` will type check all modules in the package only. This differs from build that type checks **and** generates code.
53++ ``idris --checkpkg maths.ipkg`` will type check all modules in the
54+ package only. This differs from build that type checks **and**
55+ generates code.
9456
95−+ ``idris --testpkg test.ipkg`` will compile and run any embedded tests you have specified in the ``tests`` paramater.
57++ ``idris --mathspkg maths.ipkg`` will compile and run any embedded
58+ mathss you have specified in the ``tests`` paramater. More
59+ information about mathsing is given in the next section.
9660
97−Once the test package has been installed, the command line option
98−``--package test`` makes it accessible (abbreviated to ``-p test``).
61+Once the maths package has been installed, the command line option
62+``--package maths`` makes it accessible (abbreviated to ``-p maths``).
9963For example::
10064
101− idris -p test Main.idr
65+ idris -p maths Main.idr
docs/tutorial/testing.rstnew file+66
@@ -0,0 +1,66 @@
1+.. _tut-sect-testing:
2+
3+**********************
4+Testing Idris Packages
5+**********************
6+
7+As part of the integrated build system a simple testing framework is provided.
8+This framework will collect a list of named functions and construct an Idris executable in a fresh environment on your machine.
9+This executable lists the named functions under a single ``main`` function, and imports the complete list of modules for the package.
10+
11+
12+It is up to the developer to ensure the correct reporting of test results, and the structure and nature of how the tests are run.
13+Further, all test functions must return ``IO ()``, and must be listed in the ``ipkg`` file under ``tests``, and rhe modules containing the test functions must also be listed in the modules section of the ``iPKG`` file.
14+
15+
16+For example, lets take the following list of functions that are defined in a module called ``NumOps`` for a sample package ``maths``.
17+
18+.. code-block:: idris
19+
20+ module Maths.NumOps
21+
22+ double : Num a => a -> a
23+ double a = a + a
24+
25+ triple : Num a => a -> a
26+ triple a = a + double a
27+
28+A simple test module, with a qualified name of ``Test.NumOps`` can be declared as
29+
30+.. code-block:: idris
31+
32+ module Test.NumOps
33+
34+ import Maths.NumOps
35+
36+ assertTrue : Eq a => (given : a) -> (expected : a) -> IO ()
37+ assertTrue g e = if g == e
38+ then putStrLn "Test Passed"
39+ else putStrLn "Test failed"
40+
41+ assertFalse : Eq a => (given : a) -> (expected : a) -> IO ()
42+ assertFalse g e = if not (g == e)
43+ then putStrLn "Test Passed"
44+ else putStrLn "Test failed"
45+
46+ testDouble : IO ()
47+ testDouble = assertTrue (double 2) 4
48+
49+ testTriple : IO ()
50+ testTriple = assertFalse (triple 2) 5
51+
52+
53+The functions ``assertTrue`` and ``assertFalse`` are used to run expected passing, and expected failing tests.
54+The actual tests are ``testDouble`` and ``testTriple``.
55+These tests are specified in the ``maths.ipkg`` file as follows::
56+
57+ module maths
58+
59+ module = Maths.NumOps
60+ , Test.NumOps
61+
62+ tests = Test.NumOps.testDouble
63+ , Test.NumOps.testTriple
64+
65+
66+The testing framework can be innvoked using: ``idris --testpkg maths.ipkg``.