]> hydra-www.ietfng.org Git - dyna2/commitdiff
Switch python selftests to run compiler themselves
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 30 May 2013 20:29:00 +0000 (16:29 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 30 May 2013 20:29:00 +0000 (16:29 -0400)
And only run the interpreter as a captive process.  This change is made with
the intent of more accurately reflecting code coverage when we start
tracking that within self-tests.

Makefile
dyna.cabal
src/Dyna/Backend/Python/Selftest.hs
src/Dyna/Backend/Python/interpreter.py

index 2d58658f02e23d7df4d0a4c2c110505943f7dcb7..a29d773995cc7518ae4f141cb213b4724268d6b0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ tests:
 
 .PHONY: clean veryclean
 clean:
-       rm -rf examples/*.dyna.plan  \
+       rm -rf examples/*.dyna.*.plan  \
            examples/*.dyna.*.out \
            examples/*.dyna.d
        rm -f tags TAGS
index 7a50ec900078056e0ace8c1176edffd21a0a15cc..270c91dfb572a20243b5a35d858f4a210d8ed8ff 100644 (file)
@@ -138,6 +138,7 @@ Test-suite dyna-selftests
                         bytestring >=0.9,
                         charset >=0.3,
                         containers >=0.4,
+                        directory >= 1.0,
                         either >= 3.4,
                         ghc-prim,
                         HUnit >=1.2,
index c35eb942c8faf6e68e9b105ce50a1e9fe4cbbf5a..084cf369d9689558f512e5dd11fbab86dc023a82 100644 (file)
@@ -3,11 +3,16 @@
 -- code through the interpreter.
 
 -- Header material                                                      {{{
+{-# LANGUAGE ImplicitParams #-}
 module Dyna.Backend.Python.Selftest where
 
 import           Control.Exception (throw)
+import qualified Dyna.Backend.Python.Backend         as DP
+import qualified Dyna.Main.Driver                    as D
+import           System.Directory (removeFile)
 import           System.Exit (ExitCode(..))
 import           System.IO
+import           System.IO.Error
 import           System.Process
 import qualified Test.Framework                      as TF
 import           Test.Golden
@@ -18,38 +23,48 @@ import           Test.Golden
 -- XXX There's something wrong here -- if we encounter an ExitFailure and
 -- throw an exception, we fail to fail the test or even time out.  This
 -- might be my fault, or it might be upstream.
-runDynaPy :: String -> String -> IO ()
-runDynaPy f out = do
-  devnull <- openFile "/dev/null" ReadWriteMode
+runDynaPy :: FilePath -> FilePath -> FilePath -> IO ()
+runDynaPy f pl out = do
+  _ <- tryIOError $ removeFile pl
+  _ <- tryIOError $ removeFile out
 
-  (Nothing,Nothing,Nothing,ph) <- createProcess $ CreateProcess
-     { cmdspec = RawCommand "/usr/bin/env"
-                            [ "python"
-                            , "src/Dyna/Backend/Python/interpreter.py"
-                            , "-o", out
-                            , f
-                            ]
-     , cwd = Nothing
-     , env = Nothing
-     , std_in = UseHandle devnull
-     , std_out = UseHandle devnull
-     , std_err = UseHandle devnull
-     , close_fds = True
-     , create_group = False
-     }
-  ec <- waitForProcess ph
-  case ec of
-   ExitSuccess -> return ()
-   ExitFailure _ -> throw ec
+  let ?dcfg = D.defaultDynacConfig
+           { D.dcfg_backend = DP.pythonBackend
+           , D.dcfg_outFile = Just pl
+           }
+   in D.processFile f
+
+  withFile "/dev/null" ReadWriteMode $ \devnull -> do
+   (Nothing,Nothing,Nothing,ph) <- createProcess $ CreateProcess
+      { cmdspec = RawCommand "/usr/bin/env"
+                             [ "python"
+                             , "src/Dyna/Backend/Python/interpreter.py"
+                             , "--plan"
+                             , "-o", out
+                             , pl
+                             ]
+      , cwd = Nothing
+      , env = Nothing
+      , std_in = UseHandle devnull
+      , std_out = UseHandle devnull
+      , std_err = UseHandle devnull
+      , close_fds = True
+      , create_group = False
+      }
+   ec <- waitForProcess ph
+   case ec of
+    ExitSuccess -> return ()
+    ExitFailure _ -> throw ec
 
 ------------------------------------------------------------------------}}}
 -- Tests                                                                {{{
 
 mkExample :: String -> TF.Test
 mkExample name =
-  let (dy,out,ex) = names in goldenVsFile dy ex out (runDynaPy dy out)
+  let (dy,pl,out,ex) = names in goldenVsFile dy ex out (runDynaPy dy pl out)
  where
   names = ( "examples/"          ++ name ++ ".dyna"
+          , "examples/"          ++ name ++ ".dyna.py.plan"
           , "examples/"          ++ name ++ ".dyna.py.out"
           , "examples/expected/" ++ name ++ ".py.out")
 
index 0fa14418fda6b70a24e624860309674f9f9bb648..5b980c90a966e12fbd4bf3c55585df91303e3f2f 100644 (file)
@@ -325,7 +325,7 @@ def go():
 
 
 def dynac(f):
-    out = "%s.plan.py" % f
+    out = "%s.py.plan" % f
     cmd = '%s/dist/build/dyna/dyna -B python -o "%s" "%s"' % (dynahome, out, f)
     assert 0 == os.system(cmd), 'command failed:\n\t' + cmd
     return out
@@ -378,7 +378,7 @@ if argv.plan:
 else:
     plan = dynac(argv.source)
 
-do(argv.source)
+do(plan)
 
 if argv.interactive:
     ip()