1
0
forked from GitHub/gf-core

make it possible to run specific tests

This commit is contained in:
krangelov
2021-09-22 18:14:18 +02:00
parent bcbf9efa5f
commit 18e54abf12

View File

@@ -6,13 +6,17 @@ import System.Process(readProcess)
import System.Directory(doesFileExist,getDirectoryContents) import System.Directory(doesFileExist,getDirectoryContents)
import System.FilePath((</>),(<.>),takeExtension) import System.FilePath((</>),(<.>),takeExtension)
import System.Exit(exitSuccess,exitFailure) import System.Exit(exitSuccess,exitFailure)
import System.Environment
type TestResult = (FilePath, RunResult) type TestResult = (FilePath, RunResult)
type RunResult = (String, (String, String, String)) -- (message, (input commands, gold output, actual output)) type RunResult = (String, (String, String, String)) -- (message, (input commands, gold output, actual output))
main :: IO () main :: IO ()
main = main =
do res <- walk "testsuite" do args <- getArgs
res <- case args of
[] -> walk "testsuite"
args -> fmap concat $ mapM walk args
let cnt = length res let cnt = length res
(good,bad) = partition ((=="OK").fst.snd) res (good,bad) = partition ((=="OK").fst.snd) res
ok = length good + length (filter ((=="FAIL (expected)").fst.snd) bad) ok = length good + length (filter ((=="FAIL (expected)").fst.snd) bad)
@@ -27,22 +31,20 @@ main =
-- | Recurse through files in path, running a test for all .gfs files -- | Recurse through files in path, running a test for all .gfs files
walk :: FilePath -> IO [TestResult] walk :: FilePath -> IO [TestResult]
walk path = fmap concat . mapM (walkFile . (path </>)) =<< ls path walk fpath = do
where exists <- doesFileExist fpath
walkFile :: FilePath -> IO [TestResult] if exists
walkFile fpath = do then if takeExtension fpath == ".gfs"
exists <- doesFileExist fpath then do let in_file = fpath
if exists gold_file = fpath <.> ".gold"
then if takeExtension fpath == ".gfs" out_file = fpath <.> ".out"
then do let in_file = fpath putStr $ in_file++": "; hFlush stdout
gold_file = fpath <.> ".gold" res <- runTest in_file out_file gold_file
out_file = fpath <.> ".out" putStrLn $ fst res
putStr $ in_file++": "; hFlush stdout return [(in_file,res)]
res <- runTest in_file out_file gold_file else return []
putStrLn $ fst res else do files <- filter (`notElem` [".",".."]) `fmap` getDirectoryContents fpath
return [(in_file,res)] fmap concat $ mapM (walk . (fpath </>)) files
else return []
else walk fpath
-- | Run an individual test -- | Run an individual test
runTest :: FilePath -> FilePath -> FilePath -> IO RunResult runTest :: FilePath -> FilePath -> FilePath -> IO RunResult
@@ -102,10 +104,6 @@ defaultGF = "gf"<.>exeExtension
Platform arch Windows -> "exe" Platform arch Windows -> "exe"
_ -> "" _ -> ""
-- | List files, excluding "." and ".."
ls :: FilePath -> IO [String]
ls path = filter (`notElem` [".",".."]) `fmap` getDirectoryContents path
-- | Avoid failures caused by Win32/Unix text file incompatibility -- | Avoid failures caused by Win32/Unix text file incompatibility
compatReadFile :: FilePath -> IO String compatReadFile :: FilePath -> IO String
compatReadFile path = compatReadFile path =