2019-01-02 18:55:26 +08:00
/*
2022-02-04 12:36:44 +01:00
* Copyright ( C ) 2016 - 2022 Lightbend Inc . < https : //www.lightbend.com>
2016-02-23 12:58:39 +01:00
*/
2018-03-13 23:45:55 +09:00
2022-11-12 10:21:24 +01:00
package org.apache.pekko
2014-04-17 16:38:48 +02:00
2016-04-27 09:45:58 +02:00
import sbt.Keys._
2014-04-17 16:38:48 +02:00
import sbt._
object TestExtras {
2021-09-03 13:13:13 +02:00
import JdkOptions.isJdk8
2014-05-07 14:49:35 +02:00
object Filter {
object Keys {
2021-02-01 15:38:29 +00:00
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" )
2019-12-13 11:29:20 +01:00
val checkTestsHaveRun = taskKey [ Unit ] ( "Verify a number of notable tests have actually run" ) ;
2014-05-07 14:49:35 +02:00
}
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
2021-05-25 12:50:51 +02:00
Test / testOptions ++= excludeTestNames . value . toSeq . map ( exclude =>
2021-02-01 15:38:29 +00:00
Tests . Filter ( test => ! test . contains ( exclude ) ) ) ,
2014-05-07 14:49:35 +02:00
// add arguments for tests excluded by tag
2021-05-25 12:50:51 +02:00
Test / testOptions ++= {
2017-03-15 14:36:25 +01:00
val tags = excludeTestTags . value
2014-05-07 14:49:35 +02:00
if ( tags . isEmpty ) Seq . empty else Seq ( Tests . Argument ( "-l" , tags . mkString ( " " ) ) )
} ,
// add arguments for running only tests by tag
2021-05-25 12:50:51 +02:00
Test / testOptions ++= {
2017-03-15 14:36:25 +01:00
val tags = onlyTestTags . value
2014-05-07 14:49:35 +02:00
if ( tags . isEmpty ) Seq . empty else Seq ( Tests . Argument ( "-n" , tags . mkString ( " " ) ) )
2019-12-13 11:29:20 +01:00
} ,
checkTestsHaveRun : = {
2020-08-04 13:47:38 +02:00
def shouldExist ( description : String , filename : String ) : Unit =
require ( file ( filename ) . exists , s" $description should be run as part of the build " )
2021-09-03 13:13:13 +02:00
val baseList =
List (
2022-11-12 10:21:24 +01:00
"The java JavaExtension.java" -> "akka-actor-tests/target/test-reports/TEST-org.apache.pekko.actor.JavaExtension.xml" )
2021-09-03 13:13:13 +02:00
val jdk9Only = List (
2022-11-12 10:21:24 +01:00
"The jdk9-only FlowPublisherSinkSpec.scala" -> "akka-stream-tests/target/test-reports/TEST-org.apache.pekko.stream.scaladsl.FlowPublisherSinkSpec.xml" ,
"The jdk9-only JavaFlowSupportCompileTest.java" -> "akka-stream-tests/target/test-reports/TEST-org.apache.pekko.stream.javadsl.JavaFlowSupportCompileTest.xml" )
2021-09-03 13:13:13 +02:00
val testsToCheck =
if ( isJdk8 ) baseList
else baseList : :: jdk9Only
testsToCheck . foreach ( ( shouldExist _ ) . tupled )
2021-02-01 15:38:29 +00:00
} )
2014-05-07 14:49:35 +02:00
}
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
}
}
}