on master help sign in
add automated test for any .tutd files in the scripts directory

resolves #9

commit463a1557200fec8e9b1bd0a954b656aa77577d11 authorAgentM <agentm@themactionfaction.com> dateThu 21 Jul 2016, 12:56 (10 years ago) parentb38932d
2 files changed+39
project-m36.cabal+13 test/scripts.hs+26
project-m36.cabal+13
@@ -575,4 +575,17 @@ Executable Example-PersistClient
575575 C-sources: ProjectM36/DirectoryFsync.c
576576 Build-Depends: unix
577577
578+Test-Suite test-scripts
579+ Default-Language: Haskell2010
580+ type: exitcode-stdio-1.0
581+ main-is: test/scripts.hs
582+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, parsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t
583+ GHC-Options: -Wall
584+ CPP-Options: -DPROJECTM36_VERSION="v0.1"
585+ if os(windows)
586+ Build-Depends: Win32 >= 2.3 && < 2.4
587+ Other-Modules: ProjectM36.Win32Handle
588+ else
589+ C-sources: ProjectM36/DirectoryFsync.c
590+ Build-Depends: unix
578591
test/scripts.hsnew file+26
@@ -0,0 +1,26 @@
1+-- read each .tutd file in the /scripts directory and execute it with the tutd interpreter
2+import Test.HUnit
3+import TutorialD.Interpreter.Import.TutorialD
4+import System.Directory
5+import Data.List (isSuffixOf)
6+import System.Exit
7+
8+testList :: IO Test
9+testList = do
10+ let scriptsDir = "scripts/"
11+ dirFiles <- getDirectoryContents scriptsDir
12+ let scriptList = map (scriptsDir ++) $ filter (".tutd" `isSuffixOf`) dirFiles
13+ pure (TestList $ map testScript scriptList)
14+
15+main :: IO ()
16+main = do
17+ tests <- testList
18+ tcounts <- runTestTT tests
19+ if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
20+
21+testScript :: FilePath -> Test
22+testScript tutdFile = TestCase $ do
23+ eImport <- importTutorialD tutdFile
24+ case eImport of
25+ Left err -> assertFailure ("tutd import failure in " ++ tutdFile ++ ": " ++ show err)
26+ Right _ -> pure ()