在 shake build 失败的情况下检测错误并生成报告

Detect errors and build report in case of failure in shake build

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

我的问题是:

a) 我需要检测哪个测试 运行s 或失败。实际上我是在使用 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

谢谢。

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

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