From 9435e96901b26a2c52e40a3ea7a993634b746c8b Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Fri, 11 Jan 2013 10:55:36 -0700 Subject: [PATCH] add ability to set TAP output file path by environment --- README.md | 45 ++++++++++++++++++++++++++++ readme.md | 21 ------------- src/main/scala/SbtTapReporting.scala | 4 ++- 3 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 README.md delete mode 100644 readme.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..50cd097 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +This sbt plug-in provides reporting of test success and failure for tests run by +[simple build tool](https://github.com/harrah/xsbt) +in [TAP](http://search.cpan.org/perldoc?Test%3A%3AHarness%3A%3ATAP) format. + +All the test results will be generated in one file, the path of which may be +specified in the `SBT_TAP_OUTPUT` environment variable. If unspecified in the +environment, the output file path defaults to `test-results/test.tap`. + +To use: + +1. Add this plug-in to your sbt project by creating a file + `project/project/Plugins.scala` that looks something like this: + + ```scala + import sbt._ + // sets up other project dependencies when building our root project + object Plugins extends Build { + lazy val root = Project("root", file(".")) dependsOn(tapListener) + lazy val tapListener = RootProject(uri("git://github.com/mkhettry/sbt-tap.git")) + } + ``` + +2. In your `build.sbt` file, add the `SbtTapListener` to the sequence of test + listeners. + + ```scala + testListeners += SbtTapReporting.tapListener + ``` + +3. Optionally, in a UNIX environment, you can set up a named pipe for + collecting the TAP report, for your test harness. + + ```sh + #!/bin/sh + + pipe="$PWD/test.tap" # set where to make the pipe + + rm -f "$pipe" # clear the path for the new pipe + mkfifo "$pipe" # make the pipe + cat "$pipe" & # redirect the report to stdout + + SBT_TAP_OUTPUT="$pipe" sbt test 2>&1 >/dev/null + + rm -f "$pipe" # all done - remove the pipe + ``` diff --git a/readme.md b/readme.md deleted file mode 100644 index ea900b8..0000000 --- a/readme.md +++ /dev/null @@ -1,21 +0,0 @@ -Provides reporting of test success and failure for tests run by -[simple build tool](https://github.com/harrah/xsbt) -in [TAP](http://en.wikipedia.org/wiki/Test_Anything_Protocol) format - -All the test results will be generated in one file: test-results/test.tap - -To use - -1. Add this plugin to your sbt project. Create project/project/Plugins.scala that looks like this: - - import sbt._ - // sets up other project dependencies when building our root project - object Plugins extends Build { - lazy val root = Project("root", file(".")) dependsOn(tapListener) - lazy val tapListener = RootProject(uri("git://github.com/mkhettry/sbt-tap.git")) - } - -2. In your build.sbt, add the SbtTapListener to the sequence of Test Listeners. - - testListeners += SbtTapReporting.tapListener - diff --git a/src/main/scala/SbtTapReporting.scala b/src/main/scala/SbtTapReporting.scala index 9345066..14b0576 100644 --- a/src/main/scala/SbtTapReporting.scala +++ b/src/main/scala/SbtTapReporting.scala @@ -23,7 +23,9 @@ class SbtTapListener extends TestsListener { override def doInit { new File("test-results").mkdirs() - fileWriter = new FileWriter("test-results/test.tap") + fileWriter = new FileWriter( + scala.util.Properties.envOrElse("SBT_TAP_OUTPUT", "test-results/test.tap") + ) } def startGroup(name: String) {} -- 2.43.0