Commit 694efe67 authored by Camil Staps's avatar Camil Staps

makecleantest: add options to compile and run

parent d44d21d3
......@@ -13,9 +13,11 @@ import Data.GenDefault
import Data.List
import Data.Maybe
import System.CommandLine
import System.Directory
import System.File
import System.FilePath
import System.Options
import System.Process
import Text
import CloogleDBFactory
......@@ -29,17 +31,23 @@ import TypeUtil
, output :: !FilePath
, print_options :: ![String]
, test_options :: ![String]
, compile :: !Bool
, clm_args :: ![String]
, run :: !Bool
}
gDefault{|Bool|} = False
derive gDefault Options
Start w
// Command line
# ([prog:args],w) = getCommandLine w
# opts = parseOptions optionDescription args gDefault{|*|}
| isError opts = exit (join "\n" $ fromError opts) w
# opts = fromOk opts
| any ((==) "") [opts.Options.name, opts.input, opts.output]
= exit ("Usage: " +++ prog +++ " -n NAME -i FILE -o FILE") w
// Find properties
# (funs,macros,_,_,_,_,_,_,(_,mod,_),w) = findModuleContents False (dropExtension opts.input) w
# props = generatePropertyModule
opts.Options.name
......@@ -47,8 +55,20 @@ Start w
opts.test_options
mod
[f \\ (_,f,_) <- funs ++ macros]
// Write properties
# (dir,_) = splitFileName opts.output
# (ok,w) = assertDirectory dir w
| isError ok = exit (snd (fromError ok) <+ " " +++ opts.output) w
# (ok,w) = writeFile opts.output props w
| isError ok = exit (fromError ok <+ " " +++ opts.output) w
// Compile tests
| not opts.compile = w
# (ok,w) = callProcess "clm" (opts.clm_args ++ ["-nr",opts.Options.name,"-o",opts.Options.name]) Nothing w
| isError ok = exit (snd (fromError ok) <+ " during compilation") w
// Run tests
| not opts.run = w
# (ok,w) = callProcess ("." </> opts.Options.name) [] Nothing w
| isError ok = exit (snd (fromError ok) <+ " while running the tests") w
= w
where
exit :: String *World -> *World
......@@ -81,8 +101,31 @@ where
(\po opts -> Ok {opts & test_options=opts.test_options ++ [po]})
"OPT"
"Add OPT to the test options (see Gast's Testoption type)"
, Shorthand "-c" "--compile" $ Flag
"--compile"
(\opts -> Ok {opts & compile=True})
"Compile the tests after generation"
, Shorthand "-C" "--clm-arg" $ Option
"--clm-arg"
(\arg opts -> Ok {opts & clm_args=opts.clm_args ++ [arg]})
"ARG"
"Add ARG to the command line arguments for clm"
, Shorthand "-r" "--run" $ Flag
"--run"
(\opts -> Ok {opts & compile=True, run=True})
"Run the tests after generation (implies --compile)"
]
assertDirectory :: !FilePath !*World -> *(!MaybeOSError (), !*World)
assertDirectory "" w = (Ok (), w)
assertDirectory fp w
# (ex,w) = fileExists fp w
| ex = (Ok (), w)
# (base,_) = splitFileName fp
# (err,w) = assertDirectory base w
| isError err = (err, w)
= createDirectory fp w
generatePropertyModule :: !String ![String] ![String] !ModuleEntry ![FunctionEntry] -> String
generatePropertyModule name print_options test_options me fes = join "\n\n"
[ "module " +++ name
......
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