2020-05-19 20:25:18 +03:00
|
|
|
module Main
|
|
|
|
|
|
|
|
import Data.Maybe
|
|
|
|
import Data.List
|
|
|
|
import Data.Strings
|
|
|
|
|
|
|
|
import System
|
|
|
|
import System.Directory
|
|
|
|
import System.File
|
2020-05-22 15:27:12 +03:00
|
|
|
import System.Info
|
2020-05-20 19:14:38 +03:00
|
|
|
import System.Path
|
2020-05-19 20:25:18 +03:00
|
|
|
|
|
|
|
%default covering
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- Test cases
|
|
|
|
|
|
|
|
ttimpTests : List String
|
|
|
|
ttimpTests
|
|
|
|
= ["basic001", "basic002", "basic003", "basic004", "basic005",
|
|
|
|
"basic006",
|
|
|
|
"coverage001", "coverage002",
|
|
|
|
"dot001",
|
|
|
|
"eta001", "eta002",
|
|
|
|
"lazy001",
|
|
|
|
"nest001", "nest002",
|
|
|
|
"perf001", "perf002", "perf003",
|
|
|
|
"record001", "record002", "record003",
|
2020-05-25 15:14:51 +03:00
|
|
|
"qtt001", "qtt003",
|
2020-05-19 20:31:52 +03:00
|
|
|
"total001", "total002", "total003"]
|
2020-05-19 20:25:18 +03:00
|
|
|
|
|
|
|
idrisTests : List String
|
|
|
|
idrisTests
|
|
|
|
= -- Fundamental language feturea
|
|
|
|
["basic001", "basic002", "basic003", "basic004", "basic005",
|
|
|
|
"basic006", "basic007", "basic008", "basic009", "basic010",
|
|
|
|
"basic011", "basic012", "basic013", "basic014", "basic015",
|
|
|
|
"basic016", "basic017", "basic018", "basic019", "basic020",
|
|
|
|
"basic021", "basic022", "basic023", "basic024", "basic025",
|
|
|
|
"basic026", "basic027", "basic028", "basic029", "basic030",
|
|
|
|
"basic031", "basic032", "basic033", "basic034", "basic035",
|
|
|
|
"basic036", "basic037", "basic038", "basic039", "basic040",
|
|
|
|
-- Coverage checking
|
|
|
|
"coverage001", "coverage002", "coverage003", "coverage004",
|
2020-05-24 14:52:07 +03:00
|
|
|
"coverage005", "coverage006", "coverage007", "coverage008",
|
2020-05-30 23:53:29 +03:00
|
|
|
"coverage009", "coverage010",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Error messages
|
|
|
|
"error001", "error002", "error003", "error004", "error005",
|
|
|
|
"error006", "error007", "error008", "error009", "error010",
|
|
|
|
-- Modules and imports
|
|
|
|
"import001", "import002", "import003", "import004",
|
|
|
|
-- Interactive editing support
|
|
|
|
"interactive001", "interactive002", "interactive003", "interactive004",
|
|
|
|
"interactive005", "interactive006", "interactive007", "interactive008",
|
|
|
|
"interactive009", "interactive010", "interactive011", "interactive012",
|
2020-05-20 19:07:40 +03:00
|
|
|
"interactive013",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Literate
|
|
|
|
"literate001", "literate002", "literate003", "literate004",
|
|
|
|
"literate005", "literate006", "literate007", "literate008",
|
|
|
|
"literate009", "literate010", "literate011", "literate012",
|
2020-06-10 17:29:53 +03:00
|
|
|
"literate013",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Interfaces
|
|
|
|
"interface001", "interface002", "interface003", "interface004",
|
|
|
|
"interface005", "interface006", "interface007", "interface008",
|
|
|
|
"interface009", "interface010", "interface011", "interface012",
|
2020-06-11 16:28:34 +03:00
|
|
|
"interface013", "interface014", "interface015", "interface016",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Miscellaneous REPL
|
2020-06-07 16:40:45 +03:00
|
|
|
"interpreter001", "interpreter002",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Implicit laziness, lazy evaluation
|
|
|
|
"lazy001",
|
|
|
|
-- QTT and linearity related
|
|
|
|
"linear001", "linear002", "linear003", "linear004", "linear005",
|
2020-05-25 15:14:51 +03:00
|
|
|
"linear006", "linear007", "linear008", "linear009",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Parameters blocks
|
|
|
|
"params001",
|
|
|
|
-- Performance: things which have been slow in the past, or which
|
|
|
|
-- pose interesting challenges for the elaborator
|
|
|
|
"perf001", "perf002", "perf003", "perf004",
|
|
|
|
-- Parse errors
|
|
|
|
"perror001", "perror002", "perror003", "perror004", "perror005",
|
|
|
|
"perror006",
|
|
|
|
-- Packages and ipkg files
|
2020-05-23 22:35:05 +03:00
|
|
|
"pkg001", "pkg002", "pkg003",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Larger programs arising from real usage. Typically things with
|
|
|
|
-- interesting interactions between features
|
|
|
|
"real001", "real002",
|
|
|
|
-- Records, access and dependent update
|
|
|
|
"record001", "record002", "record003", "record004",
|
2020-05-30 00:40:29 +03:00
|
|
|
-- Quotation and reflection
|
2020-06-01 17:01:52 +03:00
|
|
|
"reflection001", "reflection002", "reflection003", "reflection004",
|
2020-06-03 11:17:37 +03:00
|
|
|
"reflection005", "reflection006", "reflection007", "reflection008",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Miscellaneous regressions
|
|
|
|
"reg001", "reg002", "reg003", "reg004", "reg005", "reg006", "reg007",
|
|
|
|
"reg008", "reg009", "reg010", "reg011", "reg012", "reg013", "reg014",
|
2020-06-04 20:21:44 +03:00
|
|
|
"reg015", "reg016", "reg017", "reg018", "reg019", "reg020", "reg021",
|
2020-06-07 00:20:25 +03:00
|
|
|
"reg022", "reg023",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- Totality checking
|
|
|
|
"total001", "total002", "total003", "total004", "total005",
|
2020-05-21 18:03:00 +03:00
|
|
|
"total006", "total007", "total008",
|
2020-05-19 20:25:18 +03:00
|
|
|
-- The 'with' rule
|
2020-05-22 21:26:10 +03:00
|
|
|
"with001", "with002",
|
|
|
|
-- with-disambiguation
|
|
|
|
"with003"]
|
2020-05-19 20:25:18 +03:00
|
|
|
|
|
|
|
typeddTests : List String
|
|
|
|
typeddTests
|
|
|
|
= ["chapter01", "chapter02", "chapter03", "chapter04", "chapter05",
|
|
|
|
"chapter06", "chapter07", "chapter08", "chapter09", "chapter10",
|
|
|
|
"chapter11", "chapter12", "chapter13", "chapter14"]
|
|
|
|
|
|
|
|
chezTests : List String
|
|
|
|
chezTests
|
|
|
|
= ["chez001", "chez002", "chez003", "chez004", "chez005", "chez006",
|
|
|
|
"chez007", "chez008", "chez009", "chez010", "chez011", "chez012",
|
2020-05-19 23:02:15 +03:00
|
|
|
"chez013", "chez014", "chez015", "chez016", "chez017", "chez018",
|
2020-06-08 22:30:34 +03:00
|
|
|
"chez019", "chez020", "chez021", "chez022",
|
2020-05-19 23:02:15 +03:00
|
|
|
"reg001"]
|
2020-05-19 20:25:18 +03:00
|
|
|
|
|
|
|
ideModeTests : List String
|
|
|
|
ideModeTests
|
|
|
|
= [ "ideMode001", "ideMode002", "ideMode003" ]
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- Options
|
|
|
|
|
|
|
|
||| Options for the test driver.
|
|
|
|
record Options where
|
|
|
|
constructor MkOptions
|
|
|
|
||| Name of the idris2 executable
|
|
|
|
idris2 : String
|
|
|
|
||| Should we only run some specific cases?
|
|
|
|
onlyNames : List String
|
|
|
|
||| Should we run the test suite interactively?
|
|
|
|
interactive : Bool
|
|
|
|
|
|
|
|
usage : String
|
|
|
|
usage = "Usage: runtests <idris2 path> [--interactive] [--only [NAMES]]"
|
|
|
|
|
|
|
|
options : List String -> Maybe Options
|
|
|
|
options args = case args of
|
|
|
|
(_ :: idris2 :: rest) => go rest (MkOptions idris2 [] False)
|
|
|
|
_ => Nothing
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
go : List String -> Options -> Maybe Options
|
|
|
|
go rest opts = case rest of
|
|
|
|
[] => pure opts
|
|
|
|
("--interactive" :: xs) => go xs (record { interactive = True } opts)
|
|
|
|
("--only" :: xs) => pure $ record { onlyNames = xs } opts
|
|
|
|
_ => Nothing
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- Actual test runner
|
|
|
|
|
|
|
|
fail : String -> IO ()
|
|
|
|
fail err
|
|
|
|
= do putStrLn err
|
|
|
|
exitWith (ExitFailure 1)
|
|
|
|
|
2020-05-22 15:27:12 +03:00
|
|
|
-- on Windows, we just ignore backslashes and slashes when comparing,
|
|
|
|
-- similarity up to that is good enough. Leave errors that depend
|
|
|
|
-- on the confusion of slashes and backslashes to unix machines.
|
|
|
|
normalize : String -> String
|
|
|
|
normalize str =
|
|
|
|
if isWindows
|
|
|
|
then pack $ filter (\ch => ch /= '/' && ch /= '\\') (unpack str)
|
|
|
|
else str
|
|
|
|
|
2020-05-19 20:25:18 +03:00
|
|
|
runTest : Options -> String -> IO Bool
|
|
|
|
runTest opts testPath
|
|
|
|
= do changeDir testPath
|
|
|
|
isSuccess <- runTest'
|
|
|
|
changeDir "../.."
|
|
|
|
pure isSuccess
|
|
|
|
where
|
|
|
|
getAnswer : IO Bool
|
|
|
|
getAnswer = do
|
|
|
|
str <- getLine
|
|
|
|
case str of
|
|
|
|
"y" => pure True
|
|
|
|
"n" => pure False
|
|
|
|
_ => do putStrLn "Invalid Answer."
|
|
|
|
getAnswer
|
|
|
|
|
|
|
|
printExpectedVsOutput : String -> String -> IO ()
|
|
|
|
printExpectedVsOutput exp out = do
|
|
|
|
putStrLn "Expected:"
|
|
|
|
printLn exp
|
|
|
|
putStrLn "Given:"
|
|
|
|
printLn out
|
|
|
|
|
|
|
|
mayOverwrite : Maybe String -> String -> IO ()
|
|
|
|
mayOverwrite mexp out = do
|
|
|
|
the (IO ()) $ case mexp of
|
|
|
|
Nothing => putStr $ unlines
|
|
|
|
[ "Golden value missing. I computed the following result:"
|
|
|
|
, out
|
|
|
|
, "Accept new golden value? [yn]"
|
|
|
|
]
|
|
|
|
Just exp => do
|
|
|
|
putStrLn "Golden value differs from actual value."
|
2020-06-11 16:23:47 +03:00
|
|
|
code <- system "git diff --no-index --exit-code --word-diff=color expected output"
|
2020-06-05 15:29:46 +03:00
|
|
|
when (code < 0) $ printExpectedVsOutput exp out
|
2020-05-19 20:25:18 +03:00
|
|
|
putStrLn "Accept actual value as new golden value? [yn]"
|
|
|
|
b <- getAnswer
|
|
|
|
when b $ do Right _ <- writeFile "expected" out
|
|
|
|
| Left err => print err
|
2020-05-23 22:35:05 +03:00
|
|
|
pure ()
|
2020-05-19 20:25:18 +03:00
|
|
|
runTest' : IO Bool
|
|
|
|
runTest'
|
|
|
|
= do putStr $ testPath ++ ": "
|
|
|
|
system $ "sh ./run " ++ idris2 opts ++ " | tr -d '\\r' > output"
|
|
|
|
Right out <- readFile "output"
|
|
|
|
| Left err => do print err
|
|
|
|
pure False
|
|
|
|
Right exp <- readFile "expected"
|
|
|
|
| Left FileNotFound => do
|
|
|
|
if interactive opts
|
|
|
|
then mayOverwrite Nothing out
|
|
|
|
else print FileNotFound
|
|
|
|
pure False
|
|
|
|
| Left err => do print err
|
2020-05-23 22:35:05 +03:00
|
|
|
pure False
|
2020-05-22 15:27:12 +03:00
|
|
|
let result = normalize out == normalize exp
|
2020-06-08 00:47:41 +03:00
|
|
|
-- The issue #116 that made this necessary is fixed, but
|
|
|
|
-- please resist putting 'result' here until it's also
|
|
|
|
-- fixed in Idris2-boot!
|
2020-05-23 22:35:05 +03:00
|
|
|
if normalize out == normalize exp
|
2020-05-19 20:25:18 +03:00
|
|
|
then putStrLn "success"
|
|
|
|
else do
|
|
|
|
putStrLn "FAILURE"
|
|
|
|
if interactive opts
|
|
|
|
then mayOverwrite (Just exp) out
|
|
|
|
else printExpectedVsOutput exp out
|
|
|
|
|
2020-05-22 15:27:12 +03:00
|
|
|
pure result
|
2020-05-19 20:25:18 +03:00
|
|
|
|
|
|
|
exists : String -> IO Bool
|
|
|
|
exists f
|
|
|
|
= do Right ok <- openFile f Read
|
|
|
|
| Left err => pure False
|
|
|
|
closeFile ok
|
|
|
|
pure True
|
|
|
|
|
|
|
|
firstExists : List String -> IO (Maybe String)
|
|
|
|
firstExists [] = pure Nothing
|
|
|
|
firstExists (x :: xs) = if !(exists x) then pure (Just x) else firstExists xs
|
|
|
|
|
|
|
|
pathLookup : IO (Maybe String)
|
|
|
|
pathLookup = do
|
|
|
|
path <- getEnv "PATH"
|
2020-05-20 19:14:38 +03:00
|
|
|
let pathList = split (== pathSeparator) $ fromMaybe "/usr/bin:/usr/local/bin" path
|
2020-05-19 20:25:18 +03:00
|
|
|
let candidates = [p ++ "/" ++ x | p <- pathList,
|
2020-05-20 19:14:38 +03:00
|
|
|
x <- ["chez", "chezscheme9.5", "scheme", "scheme.exe"]]
|
2020-05-19 20:25:18 +03:00
|
|
|
firstExists candidates
|
|
|
|
|
|
|
|
findChez : IO (Maybe String)
|
|
|
|
findChez
|
|
|
|
= do Just chez <- getEnv "CHEZ" | Nothing => pathLookup
|
|
|
|
pure $ Just chez
|
|
|
|
|
|
|
|
runChezTests : Options -> List String -> IO (List Bool)
|
|
|
|
runChezTests opts tests
|
|
|
|
= do chexec <- findChez
|
|
|
|
maybe (do putStrLn "Chez Scheme not found"
|
|
|
|
pure [])
|
|
|
|
(\c => do putStrLn $ "Found Chez Scheme at " ++ c
|
|
|
|
traverse (runTest opts) tests)
|
|
|
|
chexec
|
|
|
|
|
|
|
|
filterTests : Options -> List String -> List String
|
|
|
|
filterTests opts = case onlyNames opts of
|
|
|
|
[] => id
|
|
|
|
xs => filter (\ name => any (`isInfixOf` name) xs)
|
|
|
|
|
|
|
|
main : IO ()
|
|
|
|
main
|
|
|
|
= do args <- getArgs
|
|
|
|
let (Just opts) = options args
|
|
|
|
| _ => do print args
|
|
|
|
putStrLn usage
|
|
|
|
let filteredNonCGTests =
|
|
|
|
filterTests opts $ concat
|
|
|
|
[ testPaths "ttimp" ttimpTests
|
|
|
|
, testPaths "idris2" idrisTests
|
|
|
|
, testPaths "typedd-book" typeddTests
|
|
|
|
, testPaths "ideMode" ideModeTests
|
|
|
|
]
|
|
|
|
let filteredChezTests = filterTests opts (testPaths "chez" chezTests)
|
|
|
|
nonCGTestRes <- traverse (runTest opts) filteredNonCGTests
|
|
|
|
chezTestRes <- if length filteredChezTests > 0
|
|
|
|
then runChezTests opts filteredChezTests
|
|
|
|
else pure []
|
|
|
|
let res = nonCGTestRes ++ chezTestRes
|
|
|
|
putStrLn (show (length (filter id res)) ++ "/" ++ show (length res)
|
|
|
|
++ " tests successful")
|
|
|
|
if (any not res)
|
|
|
|
then exitWith (ExitFailure 1)
|
|
|
|
else exitWith ExitSuccess
|
|
|
|
where
|
|
|
|
testPaths : String -> List String -> List String
|
|
|
|
testPaths dir tests = map (\test => dir ++ "/" ++ test) tests
|