Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Apr 16, 2022
1 parent 8558ab1 commit 50cd80a
Show file tree
Hide file tree
Showing 56 changed files with 749 additions and 214 deletions.
16 changes: 13 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ inThisBuild(
)
),
scalaVersion := scala213,
useSuperShell := false
useSuperShell := false,
semanticdbEnabled := true,
semanticdbVersion := "4.4.28"
)
)

Expand Down Expand Up @@ -202,6 +204,7 @@ lazy val junit = project
sbtPlugin := false,
crossScalaVersions := List(allScalaVersions.head),
libraryDependencies ++= List(
"org.junit.platform" % "junit-platform-engine" % "1.8.1",
"junit" % "junit" % junitVersion,
"org.scala-sbt" % "test-interface" % "1.0"
),
Expand All @@ -210,6 +213,7 @@ lazy val junit = project
)

lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.enablePlugins(BuildInfoPlugin)
.settings(
sharedSettings,
Compile / unmanagedSourceDirectories ++=
Expand Down Expand Up @@ -245,10 +249,12 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.jvmSettings(
sharedJVMSettings,
libraryDependencies ++= List(
"junit" % "junit" % "4.13.1"
"org.junit.platform" % "junit-platform-engine" % "1.8.1",
"org.junit.platform" % "junit-platform-launcher" % "1.8.1",
"org.scala-sbt" % "test-interface" % "1.0"
)
)
.jvmConfigure(_.dependsOn(junit))
// .jvmConfigure(_.dependsOn(junit))
lazy val munitJVM = munit.jvm
lazy val munitJS = munit.js
lazy val munitNative = munit.native
Expand Down Expand Up @@ -322,6 +328,10 @@ lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.jsSettings(sharedJSSettings)
.jvmSettings(
sharedJVMSettings,
libraryDependencies ++= List(
"org.junit.vintage" % "junit-vintage-engine" % "5.8.1",
"org.junit.jupiter" % "junit-jupiter-engine" % "5.8.1"
),
fork := true,
Test / parallelExecution := true,
Test / testOptions += Tests.Argument(TestFrameworks.MUnit, "+b")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package munit.internal.junitinterface;

import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.EngineDescriptor;

public class MUnitEngineDescriptor extends EngineDescriptor {
public MUnitEngineDescriptor(UniqueId uniqueId) {
super(uniqueId, "MUnit");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package munit.internal.junitinterface;

import org.junit.platform.engine.EngineExecutionListener;
import org.junit.runner.Description;
import org.junit.runner.notification.RunListener;

public class MUnitRunListener extends RunListener {
private final EngineExecutionListener listener;

public MUnitRunListener(EngineExecutionListener listener) {
this.listener = listener;
}

@Override
public void testSuiteFinished(Description description) throws Exception {
System.out.println("STARTED SUITE" + description);
super.testSuiteFinished(description);
}

@Override
public void testStarted(Description description) throws Exception {
System.out.println("STARTED TEST" + description);
super.testStarted(description);
}

@Override
public void testFinished(Description description) throws Exception {
System.out.println("FINISHED TEST" + description);
super.testFinished(description);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
munit.MUnitTestEngine
25 changes: 0 additions & 25 deletions munit/jvm/src/main/scala/munit/Framework.scala

This file was deleted.

16 changes: 16 additions & 0 deletions munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package munit.internal

import scala.concurrent.Future
import munit.MUnitRunner
import sbt.testing.Task
import sbt.testing.EventHandler
import sbt.testing.Logger
Expand All @@ -10,6 +11,8 @@ import scala.concurrent.Promise
import scala.concurrent.ExecutionContext
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import sbt.testing.TaskDef
import scala.util.Try

object PlatformCompat {
private val sh = Executors.newSingleThreadScheduledExecutor()
Expand Down Expand Up @@ -70,6 +73,19 @@ object PlatformCompat {
def isNative: Boolean = false
def getThisClassLoader: ClassLoader = this.getClass().getClassLoader()

def setThisClassLoader(loader: ClassLoader): Unit = () // Do nothing
def newRunner(
taskDef: TaskDef,
classLoader: ClassLoader
): Option[MUnitRunner] =
Try {
val cls = classLoader.loadClass(taskDef.fullyQualifiedName())
new MUnitRunner(
cls.asInstanceOf[Class[_ <: munit.Suite]],
() => cls.newInstance().asInstanceOf[munit.Suite]
)
}.toOption

type InvocationTargetException = java.lang.reflect.InvocationTargetException
type UndeclaredThrowableException =
java.lang.reflect.UndeclaredThrowableException
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.junit.platform.engine

class ConfigurationParameters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.junit.platform.engine

trait DiscoveryFilter[T]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.junit.platform.engine

trait DiscoverySelector
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.junit.platform.engine

class EngineDiscoveryListener
object EngineDiscoveryListener {
val NOOP = new EngineDiscoveryListener
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.junit.platform.engine

import org.junit.platform.engine.DiscoverySelector
import java.{util => ju}
import org.junit.platform.engine.DiscoveryFilter
import org.junit.platform.engine.ConfigurationParameters
import org.junit.platform.engine.EngineDiscoveryListener

trait EngineDiscoveryRequest {
def getSelectorsByType[T <: DiscoverySelector](
selectorType: Class[T]
): ju.List[T]
def getFiltersByType[T <: DiscoveryFilter[_]](
selectorType: Class[T]
): ju.List[T]
def getConfigurationParameters(): ConfigurationParameters
def getDiscoveryListener(): EngineDiscoveryListener =
EngineDiscoveryListener.NOOP
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.junit.platform.engine

import org.junit.platform.engine.reporting.ReportEntry

trait EngineExecutionListener {
def dynamicTestRegisterd(testDescriptor: TestDescriptor): Unit = ()
def executionSkipped(testDescriptor: TestDescriptor, reason: String): Unit =
()
def executionStarted(testDescriptor: TestDescriptor): Unit = ()
def executionFinished(
testDescriptor: TestDescriptor,
testExecutionResult: TestExecutionResult
): Unit = ()
def reportingEntryPublished(
testDescriptor: TestDescriptor,
entry: ReportEntry
): Unit = ()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.junit.platform.engine

class ExecutionRequest
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.junit.platform.engine

import java.{util => ju}

trait TestDescriptor {
def getUniqueId(): UniqueId
def getDisplayName(): String
def getTags(): ju.Set[TestTag]
def getSource(): ju.Optional[TestSource]
def getParent(): ju.Optional[TestDescriptor]
def setParent(parent: TestDescriptor): Unit
def getChildren(): ju.Set[_ <: TestDescriptor]
def addChild(descriptor: TestDescriptor): Unit
def removeChild(descriptor: TestDescriptor): Unit
def isRoot(): Boolean = !getParent().isPresent()
def getType(): TestDescriptor.Type
}

object TestDescriptor {
abstract class Type extends Serializable {
def isContainer: Boolean =
this == Type.CONTAINER || this == Type.CONTAINER_AND_TEST
def isTest: Boolean =
this == Type.TEST || this == Type.CONTAINER_AND_TEST
}
object Type {
case object CONTAINER extends Type
case object TEST extends Type
case object CONTAINER_AND_TEST extends Type
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.junit.platform.engine

import java.util.Optional

trait TestEngine {
def getId: String
def discover(
request: EngineDiscoveryRequest,
uniqueId: UniqueId
): TestDescriptor
def execute(request: ExecutionRequest): Unit
def getArtifactId: Optional[String] = Optional.empty()
def getGroupId: Optional[String] = Optional.empty()
def getVersion: Optional[String] = Optional.empty()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.junit.platform.engine

import java.util.Optional

class TestExecutionResult(
status: TestExecutionResult.Status,
throwable: Throwable
) {
def getStatus(): TestExecutionResult.Status = status
def getThrowable(): Optional[Throwable] = Optional.ofNullable(throwable)
override def toString(): String =
s"TestExectionResult [status = ${status}, throwable = ${throwable}]"
}
object TestExecutionResult {
private val SUCCESSFUL_RESULT = new TestExecutionResult(SUCCESSFUL, null)
def successful(): TestExecutionResult =
SUCCESSFUL_RESULT
def aborted(throwable: Throwable): TestExecutionResult =
new TestExecutionResult(ABORTED, throwable)
def failed(throwable: Throwable): TestExecutionResult =
new TestExecutionResult(FAILED, throwable)

sealed abstract class Status extends Serializable
case object SUCCESSFUL extends Status
case object ABORTED extends Status
case object FAILED extends Status
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.junit.platform.engine

abstract class TestSource
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.junit.platform.engine
class TestTag(name: String) {
def getName(): String = name
}
object TestTag {
def create(name: String): TestTag = new TestTag(name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.junit.platform.engine

class UniqueId(kind: String, name: String)
object UniqueId {
def root(kind: String, name: String): UniqueId = new UniqueId(kind, name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.junit.platform.engine.reporting

import java.{util => ju}

final class ReportEntry {
val timestamp = new java.util.Date()
val keyValuePairs = new ju.LinkedHashMap[String, String]
private def add(key: String, value: String): Unit =
keyValuePairs.put(key, value)
def getKeyValuePairs(): ju.Map[String, String] =
ju.Collections.unmodifiableMap(keyValuePairs)
override def toString(): String =
s"ReportEntry [timestamp = $timestamp${}, keyValuePairs = ${keyValuePairs}]"
}
object ReportEntry {
def from(keyValuePairs: ju.Map[String, String]): ReportEntry = {
val reportEntry = new ReportEntry
keyValuePairs.forEach((a, b) => reportEntry.add(a, b))
reportEntry
}
def from(key: String, value: String): ReportEntry = {
val reportEntry = new ReportEntry
reportEntry.add(key, value)
reportEntry
}
}
Loading

0 comments on commit 50cd80a

Please sign in to comment.