在 SBT 中为测试失败执行任务依赖 [英] Executing a task dependency for test failure in SBT

查看:38
本文介绍了在 SBT 中为测试失败执行任务依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

位于我的 build.sbt 中的以下代码在我的测试成功完成时执行.它播放了一个美妙的小调,告诉我我的测试成功完成,让我不再像肮脏的哈利一样盯着终端.

The following piece of code, which resides in my build.sbt, executes if my tests complete successfully. It plays a nice little tune to tell me that my tests completed successfully, freeing me from staring the terminal down like Dirty Harry.

test <<= (test in Test) map { result =>
  import java.io.File
  import javax.sound.sampled._
  val clip = AudioSystem.getClip();
  val soundfile = new File("success.wav")
  val inputStream = AudioSystem.getAudioInputStream(soundfile);
  clip.open(inputStream);
  clip.start();
  result
}

所以我用 ~test 开始我的测试,然后就开始了.每次我在编辑器中点击保存,测试就会自动神奇地重新运行,如果它们通过,你就来了.

So I start my tests with ~test and off it goes. Every-time I hit save in the editor, the tests auto-magically re-runs and if they pass, you here the jingle.

问题是:如果测试失败,我该如何播放声音?目前它只是对失败保持沉默.

Question is: how can I go about playing a sound if the tests fail? Currently it just keeps quiet on failure.

推荐答案

参见 处理失败.例如,

... test in Test mapR {
  case Inc(inc: Incomplete) =>
     ... play failure sound ...
     throw inc
  case Value(v) =>
     ... play success sound ...
     v
}

这篇关于在 SBT 中为测试失败执行任务依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆