@@ -5,7 +5,7 @@ import System.Process
5import System.Directory
5import System.Directory
6import System.Exit
6import System.Exit
7import System.IO
7import System.IO
8−import System.FilePath ((</>), addTrailingPathSeparator, takeFileName, takeDirectory)
8+import System.FilePath ((</>), addTrailingPathSeparator, takeFileName, takeDirectory, normalise)
9import System.Directory (createDirectoryIfMissing, copyFile)
9import System.Directory (createDirectoryIfMissing, copyFile)
11import Util.System
11import Util.System
@@ -159,6 +159,42 @@ documentPkg fp =
159 Left msg -> do putStrLn msg
159 Left msg -> do putStrLn msg
160 exitWith (ExitFailure 1)
160 exitWith (ExitFailure 1)
162+-- | Build a package with a sythesized main function that runs the tests
163+testPkg :: FilePath -> IO ()
165+ = do pkgdesc <- parseDesc fp
166+ ok <- mapM (testLib True (pkgname pkgdesc)) (libdeps pkgdesc)
168+ do dir <- getCurrentDirectory
169+ setCurrentDirectory $ dir </> sourcedir pkgdesc
170+ make (makefile pkgdesc)
171+ -- Get a temporary file to save the tests' source in
172+ (tmpn, tmph) <- tempIdr
174+ "module Test_______\n" ++
175+ concat ["import " ++ show m ++ "\n"
176+ | m <- modules pkgdesc] ++
177+ "namespace Main\n" ++
178+ " main : IO ()\n" ++
180+ concat [show t ++ "\n "
181+ | t <- idris_tests pkgdesc]
183+ (tmpn', tmph') <- tempfile
185+ m_ist <- idris (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
187+ setCurrentDirectory dir
189+ Nothing -> exitWith (ExitFailure 1)
191+ -- Quit with error code if problem building
193+ Just _ -> exitWith (ExitFailure 1)
195+ where tempIdr :: IO (FilePath, Handle)
196+ tempIdr = do dir <- getTemporaryDirectory
197+ openTempFile (normalise dir) "idristests.idr"
163-- | Install package
199-- | Install package
164installPkg :: PkgDesc -> IO ()
200installPkg :: PkgDesc -> IO ()