testwrap.hs revision 69b3701bf367eacfedd3efef1b95f697228e592a
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannModule : $Header$
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannCopyright : (c) Andy Gimblett and Markus Roggenbach and Uni Bremen 2004
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannMaintainer : a.m.gimblett@swan.ac.uk
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannStability : provisional
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannPortability : portable
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannTest case wrapper for CspCASL specs and fragments.
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannThis is a standalone `main' wrapper for CspCASL-related tests
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannperformed locally to the CspCASL codebase. It's probably only of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmanninterest to the CspCASL maintainers.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann testwrap [options] targets
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann -t Don't parse any .cspcasl files; useful for just running tests.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann -c Don't run any tests; useful for just parsing .cspcasl files.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Obviously, specifying both of these options stops this program from
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann doing anything useful.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann targets - a list of targets, where each target can be:
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann - a .cspcasl file; parse the file as a Core-CspCASL specification,
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann unparse the parse tree, and print out the result of the unparse.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann In case of parse error, report the error.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann - a .testcase file; execute the test and report the outcome. A
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann testcase file specifies one test case, whose source is contained
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann in another file, and whose output we will check against expected
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann contents. See below for the file format.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann - a .testcases file; execute the tests and report their outcomes.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann A testcases file specifies multiple test cases, with source
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann integrated with each test case, and outputs we will check
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann against expected contents. See below for the file format.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann - a directory; find all .cspcasl, .testcase and .testcases files
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann in the directory (recursively) and operate on them as described
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannPostive & negative tests:
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann A positive test is one where we expect the parse to succeed; here
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann the expected output is the result of unparsing the resultant parse
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann tree. The test can fail with a parse error, or with unexpected
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann A negative test is one where we expect the parse to fail; here the
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann expected output is the error message produced. The test can fail
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann with a successful parse, or with unexpected output.
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannFormat of .testcase files:
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann A .testcase file contains a single test case. The first line is the
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann path to the file containing the source to be parsed/tested, relative
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann to the .testcase file; it also acts as the name of the test case.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann The second line identifies the test sense ("++" is positive, "--" is
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann negative). The third line is the name of the parser to be used. The
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann remaining lines contain the expected output of the test.
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannFormat of .testcases files:
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann A .testcases file contains multiple test cases including their
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann source. Individual test cases are separated by lines containing
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann twenty '-' characters and nothing else. The format of an individual
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann test case is similar but not identical to the format of a standalone
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann test case (above). The first line is the name of the test (used for
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann reporting). The second line identifies the test sense ("++" is
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann positive, "--" is negative). The third line is the name of the
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann parser to be used. This is followed by the expected outcome of the
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann test and the source (input) of the test, in that order, both of
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann which may span multiple lines; they are separated by a line
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann containing ten '-' characters and nothing else.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannmodule Main where
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Distribution.Compat.FilePath (dirName, joinPaths)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Common.AnnoState (emptyAnnos)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport CspCASL.Parse_CspCASL(basicCspCaslSpec)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport CspCASL.Parse_CspCASL_Process(csp_casl_process)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannmain = do args <- getArgs
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann dirs <- filterM doesDirectoryExist args
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann dir_contents <- (liftM concat) (mapM listFilesR dirs)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann files <- filterM doesFileExist (sort $ nub (args ++ dir_contents))
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann doIf ("-t" `notElem` args) (parseCspCASLs (filter isCspCASL files))
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann doIf ("-c" `notElem` args) (performTests (filter isTest files))
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann where isCspCASL = (".cspcasl" `isSuffixOf`)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann isTest f = (isSuffixOf ".testcase" f) || (isSuffixOf ".testcases" f)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann doIf c f = if c then f else putStr ""
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- | Given a list of paths to .cspcasl files, parse each in turn,
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-- printing results as you go.
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannparseCspCASLs :: [FilePath] -> IO ()
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannparseCspCASLs [] = do putStr ""
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannparseCspCASLs (f:fs) = do putStrLn dash20
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann prettyCspCASLFromFile f
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann parseCspCASLs fs
-- fail/non-parse (parse fails); 3) positive test error (unparse not
-- fail/parse (parse succeeds); 6) negative test error (error not as
-- abstract the parser out from the code to run it and collect/unparse
-- | A function inspired by python's string.split(). A list is split
-- | String strip in style of python string.strip()