1

我正在使用抖动作为测试套件。我有多个独立测试表示为一组Rule. 如果这些规则中的任何一个失败,则测试失败。最后,我生成一份包含所有测试状态的报告。

我的问题是:

a) 我需要检测哪些测试运行或失败。实际上我在使用 作弊actionOnException,但是每个规则中的每个命令都有很多样板,这很复杂(我必须编写状态文件或使用IORef来存储失败状态)。

b) 我想写 Shake 报告作为我最终报告的一部分,但是shakeReport不写文件以防出错,我唯一的解决方案是再次运行构建使用--no-build --report out.html这不方便。

编辑:实际上测试正在运行并构建它们的依赖项。构建大致如下:

main = do
  -- when this fails, `dumpTests` is called,
  -- but the shake report is not written
  _ <- (try shakeMain) :: IO (Either SomeException ())

  -- This write my test report from the success informations it can gather
  -- in the directory hierarchy
  dumpTests

smakeMain = shakeArgs {shakeStaunch=True, shakeReport=["report.html"]} $ do

   "tests" ~> need ["test1/done", "test2/done", ...]

   -- this rules completly runs a test
   "*/done" %> \done -> do
       let test = takeDirectory done
       -- clear all the leftover to be sure that there is nothing useless left. This is important because I use theses outputs to know which command succeeds or fails.
       liftIO $ removeFiles test ["stdout.log", "*/image/*.exr", "*/image/*.png", "done"]

       need [test </> "stdout.log"]

       results <- getDirectoryFiles (test </> "image") ["*.exr"]

       need (map (-<.> "png") results)

       writeFile' done "done"

   "*/stdout.log" %> \log -> do
        let path = takeDirectory log </> "test"
        need [path]

        aCmd path -- this builds stdout.log and all exrs

   "*/image/*.png" %> \png -> do
         need [(png -<.> "exr")]
         toExr png

谢谢你。

4

1 回答 1

0

问题 b 最容易回答。如果构建引发错误,它不会写出报告 - 可以更改是合理的(我可以看到两种方式的论点)。但是,您可以--no-build通过两次main调用来自动执行该部分shake- 第一次像现在一样,第二次使用withArgs或使用shake shakeOptions{shakeReport=...} mempty. 本质上,您完全“手动”地完成了您现在正在做的事情,但是将其放入main函数中,因此它是自动的。

对于主要问题,我怀疑答案是您应该标记失败,而不是例外,而是结果值。例如,test1/done可以记录一个 TRUE/FALSE,说明测试是否有效。然后,您可以拥有alldone取决于所有*/done值并编写一个报告。这样,您的构建将始终通过(除非您遇到根本性错误),但通过的结果将是“TESTS PASS”或“TESTS FAIL”。

于 2016-04-28T14:32:50.310 回答