2023-01-08 17:13:31 +08:00
/*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* license agreements ; and to You under the Apache License , version 2.0 :
*
* https : //www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project , derived from Akka .
*/
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 ] ] (
2022-12-02 04:53:48 -08:00
"Names of tests to be excluded. Not supported by MultiJVM tests. Example usage: -Dpekko.test.names.exclude=TimingSpec" )
2021-02-01 15:38:29 +00:00
val excludeTestTags = settingKey [ Set [ String ] ] (
2022-12-02 04:53:48 -08:00
"Tags of tests to be excluded. It will not be used if you specify -Dpekko.test.tags.only. Example usage: -Dpekko.test.tags.exclude=long-running" )
2021-02-01 15:38:29 +00:00
val onlyTestTags =
2022-12-02 04:53:48 -08:00
settingKey [ Set [ String ] ] ( "Tags of tests to be ran. Example usage: -Dpekko.test.tags.only=long-running" )
2019-12-13 11:29:20 +01:00
2023-05-27 10:16:47 +02: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 {
2023-02-17 10:49:40 +01:00
val testNamesExclude = systemPropertyAsSeq ( "pekko.test.names.exclude" ) . toSet
val testTagsExlcude = systemPropertyAsSeq ( "pekko.test.tags.exclude" ) . toSet
val testTagsOnly = systemPropertyAsSeq ( "pekko.test.tags.only" ) . toSet
2014-05-12 15:36:49 +02:00
}
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 =>
2022-11-03 09:46:22 +01: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 (
2023-01-05 11:10:50 +01:00
"The java JavaExtension.java" -> "actor-tests/target/test-reports/TEST-org.apache.pekko.actor.JavaExtension.xml" )
2021-09-03 13:13:13 +02:00
val jdk9Only = List (
2023-01-05 11:10:50 +01:00
"The jdk9-only FlowPublisherSinkSpec.scala" -> "stream-tests/target/test-reports/TEST-org.apache.pekko.stream.scaladsl.FlowPublisherSinkSpec.xml" ,
"The jdk9-only JavaFlowSupportCompileTest.java" -> "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
}
}
}