-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runner Discovered Suites #2319
Merged
cheeseng
merged 5 commits into
scalatest:main
from
cheeseng:feature-runner-discovered-suites
Jun 8, 2024
Merged
Runner Discovered Suites #2319
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
33c768e
Work in progress publishing discovered suites in Runner.
cheeseng 2b5716e
Added Runner implementation for scala-native implementation.
cheeseng d7df551
Removed println code for testing in AnyFunSuiteSpec.scala.
cheeseng 46a811b
Removed another println for testing in AnyFunSpecSpec.scala.
cheeseng 0ff2439
Merge branch 'main' of https://github.com/scalatest/scalatest into fe…
cheeseng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2001-2024 Artima, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.scalatest.tools | ||
|
||
import java.util.concurrent.atomic.AtomicReference | ||
import scala.scalajs.reflect.annotation.EnableReflectiveInstantiation | ||
|
||
@EnableReflectiveInstantiation | ||
object Runner { | ||
|
||
private[scalatest] val internalDiscoveredSuites: AtomicReference[Option[Set[String]]] = new AtomicReference(None) | ||
|
||
def discoveredSuites: Option[Set[String]] = internalDiscoveredSuites.get | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
native/core/src/main/scala/org/scalatest/tools/Runner.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2001-2024 Artima, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.scalatest.tools | ||
|
||
import java.util.concurrent.atomic.AtomicReference | ||
import scala.scalanative.reflect.annotation.EnableReflectiveInstantiation | ||
import java.io.{File, PrintWriter} | ||
import org.scalatest.{Retries, Succeeded, Failed} | ||
import org.scalatest.time.Span | ||
import org.scalatest.time.Second | ||
|
||
@EnableReflectiveInstantiation | ||
object Runner { | ||
|
||
private[scalatest] val masterFun: AtomicReference[Option[String => Unit]] = new AtomicReference(None) | ||
|
||
def setMasterFun(fun: String => Unit): Unit = { | ||
masterFun.set(Some(fun)) | ||
} | ||
|
||
def setDiscoveredSuites(suites: Set[String]): Unit = { | ||
System.setProperty("scalatest.DiscoveredSuites", suites.mkString(",")) | ||
} | ||
|
||
def discoveredSuites: Option[Set[String]] = { | ||
masterFun.get match { | ||
case Some(fun) => | ||
val tempFile = File.createTempFile("scalatest-", "-getDiscoveredSuites") | ||
// Tell the master runner to write the discovered suites to the temp file. | ||
fun(s"getDiscoveredSuites-${tempFile.getAbsolutePath}") | ||
// The above is asynchronous, so we need to wait until the temp file is written. | ||
// Bad idea to block, but I think that's the only way to do it here, and we do not expect discoveredSuites to be called often. | ||
while (tempFile.length() == 0) | ||
Thread.sleep(500) | ||
val source = scala.io.Source.fromFile(tempFile) | ||
try { | ||
Some(source.mkString.split(",").toSet) | ||
} finally { | ||
source.close() | ||
tempFile.delete() | ||
} | ||
case None => | ||
val discoveredSuites = System.getProperty("scalatest.DiscoveredSuites") | ||
if (discoveredSuites == null || discoveredSuites.trim.isEmpty) None | ||
else Some(discoveredSuites.split(",").toSet) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cheeseng Why is this line of code commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bvenners The discovered suites are set in line 170 already, I think I just forgot to remove this commented line, this feature is supported on native as well.