on master help sign in
Merge branch 'master' of github.com:idris-lang/Idris-dev
commita02bfec13cbb6a49d553d33b61ca44ff2d83c9a7 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateWed 7 Dec 2016, 19:45 (10 years ago) parent58c3bb7e3fa3cd
18 files changed+139−15
.travis.yml+2 CHANGELOG.md+4 docs/reference/packages.rst+5 docs/tutorial/testing.rst+4 idris.cabal+8−1 libs/base/Debug/Error.idr+1−2 libs/base/System.idr+35−4 libs/effects/Effect/Exception.idr+1−2 src/IRTS/System.hs+6−1 src/Idris/IdrisDoc.hs+2−2 src/Idris/Info.hs+5 src/Idris/Package.hs+3−2 test/TestData.hs+2−1 test/pkg008/expected+13 test/pkg008/maths.ipkg+9 test/pkg008/run+9 test/pkg008/src/NumOps.idr+9 test/pkg008/src/Test.idr+21
.travis.yml+2
@@ -66,6 +66,8 @@ before_install:
6666 fi
6767
6868install:
69+ - which cabal
70+ - which ghc
6971 - cabal --version
7072 - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
7173 - if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];
CHANGELOG.md+4
@@ -10,7 +10,11 @@
1010 + `FirstClassReflection`, which must be enabled to define a `%reflection`
1111 function
1212
13+## Library Updates
1314
15++ Terminating programs has been improved with more appropriate
16+ functions (`exitWith`, `exitFailure`, and `exitSuccess`) and a data
17+ structure (`ExitCode`) to capture a program's return code.
1418
1519# New in 0.99:
1620
docs/reference/packages.rst+5
@@ -111,6 +111,11 @@ 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+
115+Comments
116+---------
117+
118+Package files support comments using the standard Idris singleline ``--`` and multiline ``{- -}`` format.
114119
115120Using Package files
116121===================
docs/tutorial/testing.rst+4
@@ -27,6 +27,8 @@ For example, lets take the following list of functions that are defined in a mod
2727.. code-block:: idris
2828
2929 module Maths.NumOps
30+
31+ %access export -- to make functions under test visible
3032
3133 double : Num a => a -> a
3234 double a = a + a
@@ -42,6 +44,8 @@ A simple test module, with a qualified name of ``Test.NumOps`` can be declared a
4244 module Test.NumOps
4345
4446 import Maths.NumOps
47+
48+ %access export -- to make the test functions visible
4549
4650 assertEq : Eq a => (given : a) -> (expected : a) -> IO ()
4751 assertEq g e = if g == e
idris.cabal+8−1
@@ -289,7 +289,6 @@ Library
289289 , vector < 0.12
290290 , vector-binary-instances < 0.3
291291 , zip-archive > 0.2.3.5 && < 0.4
292− , safe == 0.3.9
293292 , fsnotify >= 0.2 && < 2.2
294293 , async < 2.2
295294
@@ -302,6 +301,14 @@ Library
302301 else
303302 build-depends: process < 1.5
304303
304+ -- safe 0.3.10 is having issues with cabal 1.20 and ghc 7.6.3, the
305+ -- hvr ghc ppa doesn't provide a new enough cabal library. Temporary
306+ -- fix until hvr ghc ppa is fixed or we deprecate support for 7.6.3.
307+ if impl(ghc < 7.8.4)
308+ build-depends: safe == 0.3.9
309+ else
310+ build-depends: safe >= 0.3.9
311+
305312 Extensions: MultiParamTypeClasses
306313 , DeriveFoldable
307314 , DeriveTraversable
libs/base/Debug/Error.idr+1−2
@@ -12,9 +12,8 @@ error : {default (%runElab sourceLocation) loc : SourceLocation} ->
1212 (message : String) ->
1313 a
1414error {loc = FileLoc filename (line, col) _} message =
15− believe_me . unsafePerformIO $
15+ unsafePerformIO $
1616 do let place = filename ++ " line " ++ show line ++ " column " ++ show col
1717 let message' = place ++ ": " ++ message
1818 putStrLn message'
1919 exit 1
20−
libs/base/System.idr+35−4
@@ -1,5 +1,7 @@
11module System
22
3+import Data.So
4+
35%include C "unistd.h"
46%default partial
57%access public export
@@ -52,11 +54,41 @@ getEnvironment = getAllPairs 0 []
5254 then pure $ reverse $ map splitEq acc
5355 else getAllPairs (n + 1) (envPair :: acc)
5456
57+||| Programs can either terminate successfully, or end in a caught
58+||| failure.
59+data ExitCode : Type where
60+ ||| Terminate successfully.
61+ ExitSuccess : ExitCode
62+ ||| Program terminated for some prescribed reason.
63+ |||
64+ ||| @errNo A non-zero numerical value indicating failure.
65+ ||| @prf Proof that the int value is non-zero.
66+ ExitFailure : (errNo : Int)
67+ -> {auto prf : So (not $ errNo == 0)}
68+ -> ExitCode
69+
5570||| Quit with a particular exit code
56−exit : Int -> IO ()
57−exit code = foreign FFI_C "exit" (Int -> IO ()) code
71+exit : Int -> IO a
72+exit code = believe_me $ foreign FFI_C "exit" (Int -> IO ()) code
73+
74+||| Terminate the program with an `ExitCode`. This code indicates the
75+||| success of the program's execution, and returns the success code
76+||| to the program's caller.
77+|||
78+||| @code The `ExitCode` for program.
79+exitWith : (code : ExitCode) -> IO a
80+exitWith ExitSuccess = exit 0
81+exitWith (ExitFailure errNo) = exit errNo
5882
59−||| Get the numbers of seconds since 1st January 1970, 00:00 UTC
83+||| Exit the program indicating failure.
84+exitFailure : IO a
85+exitFailure = exitWith (ExitFailure 1)
86+
87+||| Exit the program after a successful run.
88+exitSuccess : IO a
89+exitSuccess = exitWith ExitSuccess
90+
91+||| Get the numbers of seconds since 1st January 1970, 00:00 UTC
6092time : IO Integer
6193time = do MkRaw t <- foreign FFI_C "idris_time" (IO (Raw Integer))
6294 pure t
@@ -66,4 +98,3 @@ usleep i = foreign FFI_C "usleep" (Int -> IO ()) i
6698
6799system : String -> IO Int
68100system cmd = foreign FFI_C "system" (String -> IO Int) cmd
69−
libs/effects/Effect/Exception.idr+1−2
@@ -17,7 +17,7 @@ implementation Handler (Exception a) List where
1717
1818implementation Show a => Handler (Exception a) IO where
1919 handle _ (Raise e) k = do printLn e
20− believe_me (exit 1)
20+ (exit 1)
2121
2222implementation Handler (Exception a) (IOExcept a) where
2323 handle _ (Raise e) k = ioe_fail e
@@ -30,4 +30,3 @@ EXCEPTION t = MkEff () (Exception t)
3030
3131raise : a -> Eff b [EXCEPTION a]
3232raise err = call $ Raise err
33−
src/IRTS/System.hs+6−1
@@ -6,7 +6,7 @@ License : BSD3
66Maintainer : The Idris Community.
77-}
88{-# LANGUAGE CPP #-}
9−module IRTS.System( getDataFileName
9+module IRTS.System( getIdrisDataFileByName
1010 , getCC
1111 , getLibFlags
1212 , getIdrisDataDir
@@ -42,6 +42,11 @@ getIdrisDataDir = do
4242 return ddir
4343 Just ddir -> return ddir
4444
45+getIdrisDataFileByName :: String -> IO FilePath
46+getIdrisDataFileByName fn = do
47+ dir <- getIdrisDataDir
48+ return $ dir </> fn
49+
4550overrideIdrisSubDirWith :: String -- ^ Sub directory in `getDataDir` location.
4651 -> String -- ^ Environment variable to get new location from.
4752 -> IO FilePath
src/Idris/IdrisDoc.hs+2−2
@@ -19,7 +19,7 @@ import Idris.Docs
1919import Idris.Docstrings (nullDocstring)
2020import qualified Idris.Docstrings as Docstrings
2121import Idris.Parser.Helpers (opChars)
22−import IRTS.System (getDataFileName)
22+import IRTS.System (getIdrisDataFileByName)
2323
2424import Control.Applicative ((<|>))
2525import Control.Monad (forM_)
@@ -708,5 +708,5 @@ copyDependencies :: FilePath -- ^ The base directory to which
708708 -- dependencies should be written
709709 -> IO ()
710710copyDependencies dir =
711− do styles <- getDataFileName $ "idrisdoc" </> "styles.css"
711+ do styles <- getIdrisDataFileByName $ "idrisdoc" </> "styles.css"
712712 copyFile styles (dir </> "styles.css")
src/Idris/Info.hs+5
@@ -22,6 +22,7 @@ module Idris.Info
2222 , getIdrisHistoryFile
2323 , getIdrisInstalledPackages
2424 , getIdrisLoggingCategories
25+ , getIdrisDataFileByName
2526 ) where
2627
2728import Idris.AbsSyntax (loggingCatsStr)
@@ -34,6 +35,7 @@ import Version_idris (gitHash)
3435import Data.Version
3536import System.Directory
3637import System.FilePath
38+
3739getIdrisDataDir :: IO String
3840getIdrisDataDir = S.getIdrisDataDir
3941
@@ -88,3 +90,6 @@ getIdrisInstalledPackages = installedPackages
8890
8991getIdrisLoggingCategories :: IO [String]
9092getIdrisLoggingCategories = return $ words loggingCatsStr
93+
94+getIdrisDataFileByName :: String -> IO FilePath
95+getIdrisDataFileByName = S.getIdrisDataFileByName
src/Idris/Package.hs+3−2
@@ -145,7 +145,7 @@ replPkg copts fp = do
145145 case mergeOptions copts (idris_opts pkgdesc) of
146146 Left emsg -> ifail emsg
147147 Right opts -> do
148−
148+
149149 putIState orig
150150 dir <- runIO getCurrentDirectory
151151 runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
@@ -266,7 +266,8 @@ testPkg copts fp = do
266266 exitWith (ExitFailure 1)
267267 Right opts -> do
268268 m_ist <- idris opts
269− exitCode <- rawSystem tmpn' []
269+ let texe = if isWindows then addExtension tmpn' ".exe" else tmpn'
270+ exitCode <- rawSystem texe []
270271 return (m_ist, exitCode)
271272 case m_ist of
272273 Nothing -> exitWith (ExitFailure 1)
test/TestData.hs+2−1
@@ -178,7 +178,8 @@ testFamiliesData = [
178178 ( 4, ANY ),
179179 ( 5, ANY ),
180180 ( 6, ANY ),
181− ( 7, ANY )]),
181+ ( 7, ANY ),
182+ ( 8, ANY )]),
182183 ("prelude", "Prelude",
183184 [ ( 1, ANY )]),
184185 ("primitives", "Primitive types",
test/pkg008/expectednew file+13
@@ -0,0 +1,13 @@
1+Entering directory `./src'
2+Type checking ./NumOps.idr
3+Type checking ./Test.idr
4+Leaving directory `./src'
5+Test Passed
6+Test Passed
7+Entering directory `./src'
8+Leaving directory `./src'
9+Entering directory `./src'
10+Removed: NumOps.ibc
11+Removed: Test.ibc
12+Removed: 00maths-idx.ibc
13+Leaving directory `./src'
test/pkg008/maths.ipkgnew file+9
@@ -0,0 +1,9 @@
1+package maths
2+
3+sourcedir = src
4+
5+modules = NumOps
6+ , Test
7+
8+tests = Test.testDouble
9+ , Test.testTriple
test/pkg008/runnew file+9
@@ -0,0 +1,9 @@
1+#!/usr/bin/env bash
2+
3+${IDRIS:-idris} $@ --build maths.ipkg
4+${IDRIS:-idris} $@ --testpkg maths.ipkg | grep -v -e "idris"
5+
6+# Idris only appears in the randomly generated name of test so we grep
7+# to remove it to make output consistent.
8+
9+${IDRIS:-idris} $@ --clean maths.ipkg
test/pkg008/src/NumOps.idrnew file+9
@@ -0,0 +1,9 @@
1+module NumOps
2+
3+%access export -- to make functions under test visible
4+
5+double : Num a => a -> a
6+double a = a + a
7+
8+triple : Num a => a -> a
9+triple a = a + double a
test/pkg008/src/Test.idrnew file+21
@@ -0,0 +1,21 @@
1+module Test
2+
3+import NumOps
4+
5+%access export -- to make the test functions visible
6+
7+assertEq : Eq a => (given : a) -> (expected : a) -> IO ()
8+assertEq g e = if g == e
9+ then putStrLn "Test Passed"
10+ else putStrLn "Test Failed"
11+
12+assertNotEq : Eq a => (given : a) -> (expected : a) -> IO ()
13+assertNotEq g e = if not (g == e)
14+ then putStrLn "Test Passed"
15+ else putStrLn "Test Failed"
16+
17+testDouble : IO ()
18+testDouble = assertEq (double 2) 4
19+
20+testTriple : IO ()
21+testTriple = assertNotEq (triple 2) 5