on master help sign in
Merge pull request #3561 from jfdm/fix-user-doc-for-ipkg

Fix user doc for ipkg

commit4eee2602f0a9eb2c9ac291c5bf77d1f56c3a01a3 authorJan de Muijnck-Hughes <jfdm@users.noreply.github.com> dateWed 7 Dec 2016, 20:14 (10 years ago) parenta02bfecefd9950
6 files changed+107−109
docs/conf.py+1−1 docs/reference/misc.rst+1−1 docs/reference/packages.rst+4−2 docs/tutorial/index.rst−1 docs/tutorial/packages.rst+101−15 docs/tutorial/testing.rst−89
docs/conf.py+1−1
@@ -33,7 +33,7 @@ on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
3333# ones.
3434extensions = [
3535 'sphinx.ext.todo',
36− 'sphinx.ext.pngmath',
36+ 'sphinx.ext.imgmath',
3737 'sphinx.ext.ifconfig',
3838]
3939
docs/reference/misc.rst+1−1
@@ -273,7 +273,7 @@ That is, ``{x}`` behaves like ``{x=x}``.
273273
274274
275275Existence of an implementation
276−========================
276+==============================
277277
278278In order to show that an implementation of some interface is defined for some
279279type, one could use the ``%implementation`` keyword:
docs/reference/packages.rst+4−2
@@ -97,7 +97,7 @@ external ``C`` libraries, the following options are available:
9797 which must be present for the package to be usable.
9898
9999+ ``objs = <objs>``, which takes a comma separated list of additional
100− files to be installed (object files, headers), perhaps generated
100+ files to be installed (object files, headers), perhaps generated
101101 by the ``Makefile``.
102102
103103Testing
@@ -111,7 +111,7 @@ The following option is available:
111111
112112.. IMPORTANT::
113113 The modules containing the test functions must also be added to the list of modules.
114−
114+
115115Comments
116116---------
117117
@@ -132,6 +132,8 @@ Given an Idris package file ``text.ipkg`` it can be used with the Idris compiler
132132
133133+ ``idris --mkdoc test.ipkg`` will build HTML documentation for your package in the folder ``test_doc`` in your project's root directory.
134134
135++ ``idris --installdoc test.ipkg`` will install the packages documentation into Idris' central documentation folder located at ``idris --docdir``.
136+
135137+ ``idris --checkpkg test.ipkg`` will type check all modules in the package only. This differs from build that type checks **and** generates code.
136138
137139+ ``idris --testpkg test.ipkg`` will compile and run any embedded tests you have specified in the ``tests`` parameter.
docs/tutorial/index.rst−1
@@ -24,7 +24,6 @@ This is the Idris Tutorial. It will teach you about programming in the Idris Lan
2424 interfaces
2525 modules
2626 packages
27− testing
2827 interp
2928 views
3029 theorems
docs/tutorial/packages.rst+101−15
@@ -31,14 +31,18 @@ package file would be::
3131
3232
3333Other examples of package files can be found in the ``libs`` directory
34−of the main Idris repository, and in `third-party libraries <https://github.com/idris-lang/Idris-dev/wiki/Libraries>`_.
35−More details including a complete listing of available fields can be found in :ref:`ref-sect-packages`.
34+of the main Idris repository, and in `third-party libraries
35+<https://github.com/idris-lang/Idris-dev/wiki/Libraries>`_.
3636
3737
3838Using Package files
3939===================
4040
41−Given an Idris package file ``maths.ipkg`` it can be used with the Idris compiler as follows:
41+
42+Idris itself is aware about packages, and special commands are
43+available to help with, for example, building packages, installing
44+packages, and cleaning packages. For instance, given the ``maths``
45+package from earlier we can use Idris as follows:
4246
4347+ ``idris --build maths.ipkg`` will build all modules in the package
4448
@@ -48,20 +52,102 @@ Given an Idris package file ``maths.ipkg`` it can be used with the Idris compile
4852+ ``idris --clean maths.ipkg`` will delete all intermediate code and
4953 executable files generated when building.
5054
51−+ ``idris --mkdoc maths.ipkg`` will build HTML documentation for your
52− package in the folder ``maths_doc`` in your project's root
53− directory.
54−
55−+ ``idris --checkpkg maths.ipkg`` will type check all modules in the
56− package only. This differs from build that type checks **and**
57− generates code.
58−
59−+ ``idris --testpkg maths.ipkg`` will compile and run any embedded
60− tests you have specified in the ``tests`` parameter. More
61− information about testing is given in the next section.
62−
6355Once the maths package has been installed, the command line option
6456``--package maths`` makes it accessible (abbreviated to ``-p maths``).
6557For example::
6658
6759 idris -p maths Main.idr
60+
61+
62+Testing Idris Packages
63+======================
64+
65+The integrated build system includes a simple testing framework.
66+This framework collects functions listed in the ``ipkg`` file under ``tests``.
67+All test functions must return ``IO ()``.
68+
69+
70+When you enter ``idris --testpkg yourmodule.ipkg``,
71+the build system creates a temporary file in a fresh environment on your machine
72+by listing the ``tests`` functions under a single ``main`` function.
73+It compiles this temporary file to an executable and then executes it.
74+
75+
76+The tests themselves are responsible for reporting their success or failure.
77+Test functions commonly use ``putStrLn`` to report test results.
78+The test framework does not impose any standards for reporting and consequently
79+does not aggregate test results.
80+
81+
82+For example, lets take the following list of functions that are defined in a module called ``NumOps`` for a sample package ``maths``.
83+
84+.. name: Math/NumOps.idr
85+.. code-block:: idris
86+
87+ module Maths.NumOps
88+
89+ %access export -- to make functions under test visible
90+
91+ double : Num a => a -> a
92+ double a = a + a
93+
94+ triple : Num a => a -> a
95+ triple a = a + double a
96+
97+A simple test module, with a qualified name of ``Test.NumOps`` can be declared as
98+
99+.. name: Math/TestOps.idr
100+.. code-block:: idris
101+
102+ module Test.NumOps
103+
104+ import Maths.NumOps
105+
106+ %access export -- to make the test functions visible
107+
108+ assertEq : Eq a => (given : a) -> (expected : a) -> IO ()
109+ assertEq g e = if g == e
110+ then putStrLn "Test Passed"
111+ else putStrLn "Test Failed"
112+
113+ assertNotEq : Eq a => (given : a) -> (expected : a) -> IO ()
114+ assertNotEq g e = if not (g == e)
115+ then putStrLn "Test Passed"
116+ else putStrLn "Test Failed"
117+
118+ testDouble : IO ()
119+ testDouble = assertEq (double 2) 4
120+
121+ testTriple : IO ()
122+ testTriple = assertNotEq (triple 2) 5
123+
124+
125+The functions ``assertEq`` and ``assertNotEq`` are used to run expected passing, and failing, equality tests.
126+The actual tests are ``testDouble`` and ``testTriple``, and are declared in the ``maths.ipkg`` file as follows::
127+
128+ package maths
129+
130+ modules = Maths.NumOps
131+ , Test.NumOps
132+
133+ tests = Test.NumOps.testDouble
134+ , Test.NumOps.testTriple
135+
136+
137+The testing framework can then be invoked using ``idris --testpkg maths.ipkg``::
138+
139+ > idris --testpkg maths.ipkg
140+ Type checking ./Maths/NumOps.idr
141+ Type checking ./Test/NumOps.idr
142+ Type checking /var/folders/63/np5g0d5j54x1s0z12rf41wxm0000gp/T/idristests144128232716531729.idr
143+ Test Passed
144+ Test Passed
145+
146+Note how both tests have reported success by printing ``Test Passed``
147+as we arranged for with the ``assertEq`` and ``assertNoEq`` functions.
148+
149+More information
150+================
151+
152+More details, including a complete listing of available fields, can be
153+found in the reference manual in :ref:`ref-sect-packages`.
docs/tutorial/testing.rstdeleted−89
@@ -1,89 +0,0 @@
1−.. _tut-sect-testing:
2−
3−**********************
4−Testing Idris Packages
5−**********************
6−
7−The integrated build system includes a simple testing framework.
8−This framework collects functions listed in the ``ipkg`` file under ``tests``.
9−All test functions must return ``IO ()``.
10−
11−
12−When you enter ``idris --testpkg yourmodule.ipkg``,
13−the build system creates a temporary file in a fresh environment on your machine
14−by listing the ``tests`` functions under a single ``main`` function.
15−It compiles this temporary file to an executable and then executes it.
16−
17−
18−The tests themselves are responsible for reporting their success or failure.
19−Test functions commonly use ``putStrLn`` to report test results.
20−The test framework does not impose any standards for reporting and consequently
21−does not aggregate test results.
22−
23−
24−For example, lets take the following list of functions that are defined in a module called ``NumOps`` for a sample package ``maths``.
25−
26−.. name: Math/NumOps.idr
27−.. code-block:: idris
28−
29− module Maths.NumOps
30−
31− %access export -- to make functions under test visible
32−
33− double : Num a => a -> a
34− double a = a + a
35−
36− triple : Num a => a -> a
37− triple a = a + double a
38−
39−A simple test module, with a qualified name of ``Test.NumOps`` can be declared as
40−
41−.. name: Math/TestOps.idr
42−.. code-block:: idris
43−
44− module Test.NumOps
45−
46− import Maths.NumOps
47−
48− %access export -- to make the test functions visible
49−
50− assertEq : Eq a => (given : a) -> (expected : a) -> IO ()
51− assertEq g e = if g == e
52− then putStrLn "Test Passed"
53− else putStrLn "Test Failed"
54−
55− assertNotEq : Eq a => (given : a) -> (expected : a) -> IO ()
56− assertNotEq g e = if not (g == e)
57− then putStrLn "Test Passed"
58− else putStrLn "Test Failed"
59−
60− testDouble : IO ()
61− testDouble = assertEq (double 2) 4
62−
63− testTriple : IO ()
64− testTriple = assertNotEq (triple 2) 5
65−
66−
67−The functions ``assertEq`` and ``assertNotEq`` are used to run expected passing, and failing, equality tests.
68−The actual tests are ``testDouble`` and ``testTriple``, and are declared in the ``maths.ipkg`` file as follows::
69−
70− package maths
71−
72− modules = Maths.NumOps
73− , Test.NumOps
74−
75− tests = Test.NumOps.testDouble
76− , Test.NumOps.testTriple
77−
78−
79−The testing framework can then be invoked using ``idris --testpkg maths.ipkg``::
80−
81− > idris --testpkg maths.ipkg
82− Type checking ./Maths/NumOps.idr
83− Type checking ./Test/NumOps.idr
84− Type checking /var/folders/63/np5g0d5j54x1s0z12rf41wxm0000gp/T/idristests144128232716531729.idr
85− Test Passed
86− Test Passed
87−
88−Note how both tests have reported success by printing ``Test Passed``
89−as we arranged for with the ``assertEq`` and ``assertNoEq`` functions.