Commit a07a5e36 authored by Michael Hanus's avatar Michael Hanus
Browse files

CPM updated

parent 4b0f4b7d
......@@ -859,7 +859,17 @@ in the directory \code{src}.
A test suite can also contain a field \code{options}
which defines a string of options passed to the call to CurryCheck.
One can also specify test suites for more than one directory.
If a test suite contains a specific test script instead
modules to be tested with CurryCheck, then one can specify the name
of this test script in the field \code{script}.
In this case, this script is executed in the test directory
(with the possible \code{options} value added).
The script should return the exit code \code{0} if the test is
successful, otherwise a non-zero exit code.
Note that one has to specify either a (non-empty) list of modules
or a test script name in a test suite, but not both.
One can also specify several test suites for a package.
In this case, the \code{testsuite} value is an array
of JSON objects as described above.
For instance, a test suite specification for tests in the
......@@ -870,7 +880,8 @@ directories \code{test} and \code{examples} could be as follows:
...,
"testsuite": [
{ "src-dir": "test",
"modules": [ "testDataConversion", "testIO" ]
"options": "-v",
"script": [ "test.sh" ]
},
{ "src-dir": "examples",
"options": "-m80",
......
......@@ -44,7 +44,7 @@ cpmBanner :: String
cpmBanner = unlines [bannerLine,bannerText,bannerLine]
where
bannerText =
"Curry Package Manager <curry-language.org/tools/cpm> (version of 31/03/2017)"
"Curry Package Manager <curry-language.org/tools/cpm> (version of 02/04/2017)"
bannerLine = take (length bannerText) (repeat '-')
main :: IO ()
......@@ -731,30 +731,35 @@ test opts cfg getRepo getGC =
where
currycheck = curryExec cfg ++ " check"
execTest apkgdir (PackageTest dir mods ccopts) = do
putStrLn $ "Running CurryCheck (" ++ currycheck ++
(if null ccopts then "" else " " ++ ccopts) ++ ")\n" ++
"(in directory '" ++ dir ++
"', showing raw output) on modules:\n" ++
unwords mods ++ "\n"
execTest apkgdir (PackageTest dir mods ccopts script) = do
let scriptcmd = "." </> script ++ if null ccopts then "" else ' ' : ccopts
checkcmd = currycheck ++ if null ccopts then "" else ' ' : ccopts
unless (null mods) $ putStrLn $
"Running CurryCheck (" ++ checkcmd ++ ")\n" ++
"(in directory '" ++ dir ++ "', showing raw output) on modules:\n" ++
unwords mods ++ "\n"
unless (null script) $ putStrLn $
"Executing test script '" ++ scriptcmd ++ "'\n" ++
"(in directory '" ++ dir ++ "', showing raw output):\n"
let currysubdir = apkgdir </> addCurrySubdir dir
testcmd = if not (null mods)
then unwords (checkcmd : mods)
else scriptcmd
debugMessage $ "Removing directory: " ++ currysubdir
system (unwords ["rm", "-rf", currysubdir])
inDirectory (apkgdir </> dir) $
execWithPkgDir
(ExecOptions (unwords (currycheck : ccopts : mods)) [])
cfg getRepo getGC apkgdir
execWithPkgDir (ExecOptions testcmd []) cfg getRepo getGC apkgdir
testsuites spec mainprogs = case testModules opts of
Nothing -> maybe (let exports = exportedModules spec
in if null exports
then if null mainprogs
then []
else [PackageTest "src" mainprogs ""]
else [PackageTest "src" exports ""])
else [PackageTest "src" mainprogs "" ""]
else [PackageTest "src" exports "" ""])
id
(testSuite spec)
Just ms -> [PackageTest "src" ms ""]
Just ms -> [PackageTest "src" ms "" ""]
--- Get the names of all Curry modules containing in a directory.
--- Modules in subdirectories are returned as hierarchical modules.
......@@ -855,7 +860,7 @@ cleanPackage ll =
srcdirs = map (specDir </>) (sourceDirsOf pkg)
testdirs = map (specDir </>)
(maybe []
(map (\ (PackageTest m _ _) -> m))
(map (\ (PackageTest m _ _ _) -> m))
(testSuite pkg))
rmdirs = dotcpm : map addCurrySubdir (srcdirs ++ testdirs)
in log ll ("Removing directories: " ++ unwords rmdirs) |>
......
......@@ -96,11 +96,14 @@ data PackageId = PackageId String Version
data PackageExecutable = PackageExecutable String String
--- The specification of a single test suite for a package.
--- It consists of a directory, a list of modules and options.
--- Thi structure specifies a test which is performed in the given directory
--- It consists of a directory, a list of modules, options (for CurryCheck),
--- and a name of a test script in this directory.
--- The test script can be empty, but then a non-empty list of modules must be
--- provided.
--- This structure specifies a test which is performed in the given directory
--- by running CurryCheck on the given list of modules where the option
--- string is passed to CurryCheck.
data PackageTest = PackageTest String [String] String
data PackageTest = PackageTest String [String] String String
--- A source where the contents of a package can be acquired.
--- @cons Http - URL to a ZIP file
......@@ -614,9 +617,19 @@ testSuiteFromJObject :: [(String, JValue)] -> Either String [PackageTest]
testSuiteFromJObject kv =
mandatoryString "src-dir" kv $ \dir ->
optionalString "options" kv $ \opts ->
case getOptStringList False "module" kv of
optionalString "script" kv $ \scriptval ->
let script = maybe "" id scriptval in
case getOptStringList (not (null script)) "module" kv of
Left e -> Left e
Right mods -> Right [PackageTest dir mods (maybe "" id opts)]
Right mods -> if null script && null mods
then Left emptyError
else if not (null script) && not (null mods)
then Left doubleError
else Right [PackageTest dir mods (maybe "" id opts)
script]
where
emptyError = "'script' and 'modules' cannot be both empty in 'testsuite'"
doubleError = "'script' and 'modules' cannot be both non-empty in 'testsuite'"
--- Reads the list of testsuites from a list of JValues (testsuite objects).
testSuiteFromJArray :: [JValue] -> Either String [PackageTest]
......@@ -630,7 +643,7 @@ testSuiteFromJArray a =
JObject o -> testSuiteFromJObject o
_ -> Left "Array element must be a testsuite object"
--- Reads an (optional) key with a string list value.
--- Reads an (optional, if first argument = True) key with a string list value.
getOptStringList :: Bool -> String -> [(String, JValue)]
-> Either String [String]
getOptStringList optional key kv = case lookup (key++"s") kv of
......
......@@ -244,14 +244,21 @@ renderPackageInfo allinfos _ gc pkg = pPrint doc
testsuites = case testSuite pkg of
Nothing -> []
Just tests ->
map (\ (PackageTest dir mods opts) ->
bold (text "Test suite") <$$>
indent 4 (bold (text "Directory ") <+> text dir) <$$>
(if null opts
then empty
else indent 4 (bold (text "Check options") <+> text opts)) <$$>
indent 4 (bold (text "Test modules ") <+>
align (fillSep (map text mods))))
map (\ (PackageTest dir mods opts script) ->
let check = if null script then "Check" else "Test" in
bold (text "Test suite") <$$>
indent 4 (bold (text "Directory ") <+> text dir) <$$>
(if null script
then empty
else indent 4 (bold (text "Test script ") <+> text script)) <$$>
(if null opts
then empty
else indent 4 (bold (text $ check++" options") <+>
text opts)) <$$>
(if null mods
then empty
else indent 4 (bold (text "Test modules ") <+>
align (fillSep (map text mods)))))
tests
descr = showParaField description "Description"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment