Commit b97711b1 authored by Michael Hanus 's avatar Michael Hanus

Options --statfile and --statdir added

parent 4637c6ad
......@@ -11,6 +11,7 @@
"cass-analysis" : ">= 2.0.0",
"cass" : ">= 2.0.0",
"contracts" : ">= 0.0.1",
"csv" : ">= 1.0.0",
"currypath" : ">= 0.0.1",
"easycheck" : ">= 0.0.1",
"flatcurry" : ">= 2.0.0",
......
......@@ -29,6 +29,8 @@ data Options = Options
, optTime :: Bool
, optColor :: Bool
, optMainProg :: String
, optStatFile :: String
, optStatDir :: String
}
-- Default command line options.
......@@ -50,6 +52,8 @@ defaultOptions = Options
, optTime = False
, optColor = True
, optMainProg = ""
, optStatFile = ""
, optStatDir = ""
}
--- Options for equivalence tests.
......@@ -105,7 +109,13 @@ options =
"do not use colors when showing tests"
, Option "" ["mainprog"]
(ReqArg (\s opts -> opts { optMainProg = s }) "<prog>")
"name of generated main program\n(default: TEST<pid>.curry)"
"name of generated main program\n(default: TEST<pid>)"
, Option "" ["statfile"]
(ReqArg (\s opts -> opts { optStatFile = s }) "<file>")
"write test statistics in CSV format into <file>"
, Option "" ["statdir"]
(ReqArg (\s opts -> opts { optStatDir = s }) "<dir>")
"write statistics as CSV file into directory <dir>"
]
where
safeReadNat opttrans s opts =
......
......@@ -18,12 +18,14 @@
-------------------------------------------------------------------------
import Char ( toUpper )
import Directory ( createDirectoryIfMissing )
import Distribution ( curryCompiler, installDir )
import FilePath ( (</>), pathSeparator, takeDirectory )
import GetOpt
import List
import Maybe ( fromJust, isJust )
import System ( system, exitWith, getArgs, getPID, setEnviron )
import Time
import AbstractCurry.Types
import AbstractCurry.Files ( readCurryWithParseOptions, readUntypedCurry )
......@@ -41,6 +43,7 @@ import System.Console.ANSI.Codes
import System.CurryPath ( modNameToPath, lookupModuleSourceInLoadPath
, stripCurrySuffix )
import System.FrontendExec ( defaultParams, setQuiet )
import Text.CSV ( writeCSVFile )
import Text.Pretty ( pPrint )
import CC.AnalysisHelpers ( getTerminationInfos, getProductivityInfos
......@@ -62,7 +65,7 @@ ccBanner :: String
ccBanner = unlines [bannerLine,bannerText,bannerLine]
where
bannerText = "CurryCheck: a tool for testing Curry programs (Version " ++
packageVersion ++ " of 29/04/2019)"
packageVersion ++ " of 18/03/2020)"
bannerLine = take (length bannerText) (repeat '-')
-- Help text
......@@ -1569,21 +1572,44 @@ cleanup opts mainmod modules =
system $ "rm -f " ++ srcfilename
done )
-- Show some statistics about number of tests:
showTestStatistics :: Options -> [Test] -> String
showTestStatistics opts tests =
-- Print or store some statistics about number of tests.
printTestStatistics :: Options -> [String] -> String -> Int -> [Test] -> IO ()
printTestStatistics opts mods testmodname retcode tests = do
let numtests = sumOf (const True)
unittests = sumOf isUnitTest
proptests = sumOf isPropTest
equvtests = sumOf isEquivTest
iotests = sumOf isIOTest
in "TOTAL NUMBER OF TESTS: " ++ show numtests ++
" (UNIT: " ++ show unittests ++ ", PROPERTIES: " ++
show proptests ++ ", EQUIVALENCE: " ++ show equvtests ++
(if optIOTest opts then ", IO: " ++ show iotests else "") ++ ")"
outs = "TOTAL NUMBER OF TESTS: " ++ show numtests ++
" (UNIT: " ++ show unittests ++ ", PROPERTIES: " ++
show proptests ++ ", EQUIVALENCE: " ++ show equvtests ++
(if optIOTest opts then ", IO: " ++ show iotests else "") ++ ")"
csvheader = ["Return code", "Total", "Unit", "Prop", "Equiv", "IO",
"Modules"]
csvdata = [retcode,numtests,unittests,proptests,equvtests,iotests]
unless (isQuiet opts || retcode /= 0) $ putStrLn $ withColor opts green outs
let statdir = optStatDir opts
unless (null statdir) $ createDirectoryIfMissing True statdir
tstring <- getTimeString
let statfile = if null (optStatFile opts)
then if null statdir
then ""
else statdir </>
testmodname ++ "_" ++ tstring ++ ".csv"
else optStatFile opts
unless (null statfile) $ writeCSVFile statfile
[csvheader, map show csvdata ++ [unwords mods]]
putStrIfDetails opts $ "Statistics written to '" ++ show statfile ++ "'."
where
sumOf p = length . filter p $ tests
getTimeString = do
ltime <- getLocalTime
return $ concatMap (\f -> show2 (f ltime))
[ctYear, ctMonth, ctDay, ctHour, ctMin, ctSec]
where show2 n = if n < 10 then '0' : show n
else show n
-------------------------------------------------------------------------
main :: IO ()
main = do
......@@ -1629,8 +1655,7 @@ main = do
putStrLnIfDebug opts $ "Executing command:\n" ++ runcmd
ret <- system runcmd
cleanup opts testmodname finaltestmodules
unless (isQuiet opts || ret /= 0) $
putStrLn $ withColor opts green $ showTestStatistics opts finaltests
printTestStatistics opts mods testmodname ret finaltests
exitWith ret
where
showStaticErrors opts errs = putStrLn $ withColor opts red $
......
Markdown is supported
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