2014-04-17 16:38:48 +02:00
package akka
import sbt._
import Keys._
2014-05-05 16:45:48 +02:00
import com.timgroup.statsd. { StatsDClientErrorHandler , NonBlockingStatsDClient }
2014-04-17 16:38:48 +02:00
import sbt.testing. { TestSelector , Status , Event }
import scala.util.Try
2014-05-05 16:45:48 +02:00
import java.io. { InputStreamReader , BufferedReader , DataOutputStream , OutputStreamWriter }
import java.net. { InetAddress , URLEncoder , HttpURLConnection , Socket }
import com.typesafe.sbt.SbtGit
import com.typesafe.sbt.SbtGit.GitKeys._
2014-04-17 16:38:48 +02:00
object TestExtras {
object JUnitFileReporting {
val settings = Seq (
// we can enable junit-style reports everywhere with this
testOptions += Tests . Argument ( TestFrameworks . JUnit , "-v" , "-a" , "-u" , ( target . value / "test-reports" ) . getAbsolutePath ) ,
testOptions += Tests . Argument ( TestFrameworks . ScalaTest , "-u" , ( target . value / "test-reports" ) . getAbsolutePath )
)
}
2014-05-07 14:49:35 +02:00
object Filter {
object Keys {
val excludeTestNames = settingKey [ Set [ String ] ] ( "Names of tests to be excluded. Not supported by MultiJVM tests. Example usage: -Dakka.test.names.exclude=TimingSpec" )
val excludeTestTags = settingKey [ Set [ String ] ] ( "Tags of tests to be excluded. It will not be used if you specify -Dakka.test.tags.only. Example usage: -Dakka.test.tags.exclude=long-running" )
val onlyTestTags = settingKey [ Set [ String ] ] ( "Tags of tests to be ran. Example usage: -Dakka.test.tags.only=long-running" )
}
import Keys._
2014-05-12 15:36:49 +02:00
private [ Filter ] object Params {
val testNamesExclude = systemPropertyAsSeq ( "akka.test.names.exclude" ) . toSet
val testTagsExlcude = systemPropertyAsSeq ( "akka.test.tags.exclude" ) . toSet
val testTagsOnly = systemPropertyAsSeq ( "akka.test.tags.only" ) . toSet
}
2014-05-07 14:49:35 +02:00
def settings = {
Seq (
2014-05-12 15:36:49 +02:00
excludeTestNames : = Params . testNamesExclude ,
2014-05-07 14:49:35 +02:00
excludeTestTags : = {
2014-05-12 15:36:49 +02:00
if ( onlyTestTags . value . isEmpty ) Params . testTagsExlcude
2014-05-07 14:49:35 +02:00
else Set . empty
} ,
2014-05-12 15:36:49 +02:00
onlyTestTags : = Params . testTagsOnly ,
2014-05-07 14:49:35 +02:00
// add filters for tests excluded by name
testOptions in Test <++= excludeTestNames map { _ . toSeq . map ( exclude => Tests . Filter ( test => ! test . contains ( exclude ) ) ) } ,
// add arguments for tests excluded by tag
testOptions in Test <++= excludeTestTags map { tags =>
if ( tags . isEmpty ) Seq . empty else Seq ( Tests . Argument ( "-l" , tags . mkString ( " " ) ) )
} ,
// add arguments for running only tests by tag
testOptions in Test <++= onlyTestTags map { tags =>
if ( tags . isEmpty ) Seq . empty else Seq ( Tests . Argument ( "-n" , tags . mkString ( " " ) ) )
}
)
}
2014-05-12 15:36:49 +02:00
def containsOrNotExcludesTag ( tag : String ) = {
Params . testTagsOnly . contains ( tag ) || ! Params . testTagsExlcude ( tag )
}
2014-05-07 14:49:35 +02:00
def systemPropertyAsSeq ( name : String ) : Seq [ String ] = {
val prop = sys . props . get ( name ) . getOrElse ( "" )
if ( prop . isEmpty ) Seq . empty else prop . split ( "," ) . toSeq
}
}
}