summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sc1
-rw-r--r--integration/test/resources/caffeine/build.sc13
-rw-r--r--integration/test/src/mill/integration/CaffeineTests.scala1
-rw-r--r--scalalib/src/mill/scalalib/Lib.scala8
-rw-r--r--testng/src/mill/testng/EventRecorder.java8
-rw-r--r--testng/src/mill/testng/ResultEvent.java69
-rw-r--r--testng/src/mill/testng/TestNGFramework.java16
-rw-r--r--testng/src/mill/testng/TestNGInstance.java3
-rw-r--r--testng/src/mill/testng/TestNGRunner.java73
9 files changed, 122 insertions, 70 deletions
diff --git a/build.sc b/build.sc
index 55da37ec..8d1ea053 100755
--- a/build.sc
+++ b/build.sc
@@ -210,6 +210,7 @@ object integration extends MillModule{
def testArgs = T{
scalajslib.testArgs() ++
scalaworker.testArgs() ++
+ Seq("-DMILL_TESTNG=" + testng.runClasspath().map(_.path).mkString(",")) ++
(for((k, v) <- testRepos()) yield s"-D$k=$v")
}
def forkArgs = testArgs()
diff --git a/integration/test/resources/caffeine/build.sc b/integration/test/resources/caffeine/build.sc
index fccf2995..aa27eff9 100644
--- a/integration/test/resources/caffeine/build.sc
+++ b/integration/test/resources/caffeine/build.sc
@@ -18,9 +18,9 @@ trait CaffeineModule extends MavenModule{
MavenRepository("http://repo.spring.io/plugins-release")
)
trait Tests extends super.Tests{
- def testFrameworks = Seq("de.johoop.testnginterface.TestNGFramework")
+ def testFrameworks = Seq("com.novocode.junit.JUnitFramework")
def ivyDeps = Agg(
- ivy"de.johoop:sbt-testng-interface_2.12:3.1.1",
+ ivy"com.novocode:junit-interface:0.11",
libraries.guava,
testLibraries.mockito,
testLibraries.hamcrest,
@@ -82,7 +82,7 @@ object caffeine extends CaffeineModule {
testLibraries.jctools,
testLibraries.guavaTestLib,
) ++
- testLibraries.testng
+ testLibraries.testng
}
}
@@ -97,6 +97,11 @@ object guava extends CaffeineModule {
testLibraries.easymock,
testLibraries.guavaTestLib
)
+ def forkArgs = Seq(
+ "-Dguava.osgi.version=" + versions.guava,
+ "-Dcaffeine.osgi.jar=" + caffeine.jar().path,
+ "-Dcaffeine-guava.osgi.jar=" + guava.jar().path
+ )
}
}
@@ -111,7 +116,7 @@ object jcache extends CaffeineModule {
testLibraries.jcacheGuice,
testLibraries.guavaTestLib
) ++
- testLibraries.testng
+ testLibraries.testng
}
}
diff --git a/integration/test/src/mill/integration/CaffeineTests.scala b/integration/test/src/mill/integration/CaffeineTests.scala
index b206aa97..121a8701 100644
--- a/integration/test/src/mill/integration/CaffeineTests.scala
+++ b/integration/test/src/mill/integration/CaffeineTests.scala
@@ -10,6 +10,7 @@ class CaffeineTests(fork: Boolean) extends IntegrationTestSuite("MILL_CAFFEINE_R
// type inference issues during the compile
if (mill.client.ClientServer.isJava9OrAbove){
assert(eval(s"caffeine.test.compile"))
+ assert(eval(s"caffeine.test"))
assert(eval(s"guava.test.compile"))
assert(eval(s"jcache.test.compile"))
assert(eval(s"simulator.test.compile"))
diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala
index 07d88891..3e06ea37 100644
--- a/scalalib/src/mill/scalalib/Lib.scala
+++ b/scalalib/src/mill/scalalib/Lib.scala
@@ -3,6 +3,7 @@ package scalalib
import java.io.{File, FileInputStream}
import java.lang.annotation.Annotation
+import java.lang.reflect.Modifier
import java.util.zip.ZipInputStream
import javax.tools.ToolProvider
@@ -12,7 +13,6 @@ import coursier.{Cache, Dependency, Fetch, Repository, Resolution}
import mill.Agg
import mill.eval.{PathRef, Result}
import mill.modules.Jvm
-
import mill.util.Ctx
import sbt.testing._
@@ -293,14 +293,18 @@ object Lib{
case f: SubclassFingerprint =>
!cls.isInterface &&
(f.isModule == cls.getName.endsWith("$")) &&
- cl.loadClass(f.superclassName()).isAssignableFrom(cls)
+ cl.loadClass(f.superclassName()).isAssignableFrom(cls) &&
+ cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1
+
case f: AnnotatedFingerprint =>
val annotationCls = cl.loadClass(f.annotationName()).asInstanceOf[Class[Annotation]]
(f.isModule == cls.getName.endsWith("$")) &&
+ cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1 &&
(
cls.isAnnotationPresent(annotationCls) ||
cls.getDeclaredMethods.exists(_.isAnnotationPresent(annotationCls))
)
+
}.map { f => (cls, f) }
}
}
diff --git a/testng/src/mill/testng/EventRecorder.java b/testng/src/mill/testng/EventRecorder.java
index 3400bf6d..59af5927 100644
--- a/testng/src/mill/testng/EventRecorder.java
+++ b/testng/src/mill/testng/EventRecorder.java
@@ -1,16 +1,16 @@
package mill.testng;
-import org.scalatools.testing.Event;
+import sbt.testing.Event;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
-import org.scalatools.testing.EventHandler;
-import org.scalatools.testing.Logger;
+import sbt.testing.EventHandler;
+import sbt.testing.Logger;
import java.util.HashMap;
public class EventRecorder extends TestListenerAdapter {
- private HashMap<String, java.util.List<Event>> basket = new HashMap<>();
+ private final HashMap<String, java.util.List<Event>> basket = new HashMap<>();
String initKey(ITestResult result){
String key = ResultEvent.classNameOf(result);
diff --git a/testng/src/mill/testng/ResultEvent.java b/testng/src/mill/testng/ResultEvent.java
index 7c943a17..215723cd 100644
--- a/testng/src/mill/testng/ResultEvent.java
+++ b/testng/src/mill/testng/ResultEvent.java
@@ -1,40 +1,45 @@
package mill.testng;
-import org.scalatools.testing.Event;
-import org.scalatools.testing.Result;
+import sbt.testing.*;
import org.testng.ITestResult;
-public class ResultEvent implements Event {
- public Result result;
- public String testName;
- public String description;
- public Throwable error;
-
- public ResultEvent(Result result, String testName, String description, Throwable error) {
- this.result = result;
- this.testName = testName;
- this.description = description;
- this.error = error;
- }
-
-
- public Result result(){ return result; }
- public String testName(){ return testName; }
- public String description(){ return description; }
- public Throwable error(){ return error; }
-
- static ResultEvent failure(ITestResult result){ return event(Result.Failure, result); }
- static ResultEvent skipped(ITestResult result){ return event(Result.Skipped, result); }
- static ResultEvent success(ITestResult result){ return event(Result.Success, result); }
-
- static ResultEvent event(Result result, ITestResult testNGResult) {
- return new ResultEvent(
- result,
- testNGResult.getName(),
- testNGResult.getName(),
- result != Result.Success ? testNGResult.getThrowable() : null
- );
+public class ResultEvent {
+ static Event failure(ITestResult result){ return event(Status.Failure, result); }
+ static Event skipped(ITestResult result){ return event(Status.Skipped, result); }
+ static Event success(ITestResult result){ return event(Status.Success, result); }
+
+ static Event event(Status result, ITestResult testNGResult) {
+ return new Event() {
+ public String fullyQualifiedName() {
+ return testNGResult.getTestClass().getName();
+ }
+
+ public Fingerprint fingerprint() {
+ return Annotated.instance;
+ }
+
+ public Selector selector() {
+ return new SuiteSelector();
+ }
+
+ public Status status() {
+ return result;
+ }
+
+ public OptionalThrowable throwable() {
+ if (result != Status.Success){
+ return new OptionalThrowable(testNGResult.getThrowable());
+ }else {
+ return new OptionalThrowable();
+ }
+ }
+
+ @Override
+ public long duration() {
+ return testNGResult.getEndMillis() - testNGResult.getStartMillis();
+ }
+ };
}
static String classNameOf(ITestResult result){ return result.getTestClass().getName(); }
} \ No newline at end of file
diff --git a/testng/src/mill/testng/TestNGFramework.java b/testng/src/mill/testng/TestNGFramework.java
index bc278caa..50041440 100644
--- a/testng/src/mill/testng/TestNGFramework.java
+++ b/testng/src/mill/testng/TestNGFramework.java
@@ -2,25 +2,27 @@ package mill.testng;
-import org.scalatools.testing.*;
+import sbt.testing.*;
public class TestNGFramework implements Framework {
public String name(){ return "TestNG"; }
- public Fingerprint[] tests(){
- return new Fingerprint[]{
- new Annotated("org.testng.annotations.Test")
- };
+
+ public Fingerprint[] fingerprints() {
+ return new Fingerprint[]{Annotated.instance};
}
- public Runner testRunner(ClassLoader testClassLoader, Logger[] loggers){
- return new TestNGRunner(testClassLoader, loggers, sharedState);
+ @Override
+ public Runner runner(String[] args, String[] remoteArgs, ClassLoader classLoader) {
+ return new TestNGRunner(args, remoteArgs, classLoader, sharedState);
}
+
private TestRunState sharedState = new TestRunState();
}
class Annotated implements AnnotatedFingerprint{
+ final public static Annotated instance = new Annotated("org.testng.annotations.Test");
String annotationName;
public Annotated(String annotationName) {
this.annotationName = annotationName;
diff --git a/testng/src/mill/testng/TestNGInstance.java b/testng/src/mill/testng/TestNGInstance.java
index f1e52870..afb1e8f7 100644
--- a/testng/src/mill/testng/TestNGInstance.java
+++ b/testng/src/mill/testng/TestNGInstance.java
@@ -1,8 +1,7 @@
package mill.testng;
-import org.scalatools.testing.EventHandler;
-import org.scalatools.testing.Logger;
+import sbt.testing.Logger;
import org.testng.CommandLineArgs;
import org.testng.TestNG;
diff --git a/testng/src/mill/testng/TestNGRunner.java b/testng/src/mill/testng/TestNGRunner.java
index d59c60da..0ad6caa7 100644
--- a/testng/src/mill/testng/TestNGRunner.java
+++ b/testng/src/mill/testng/TestNGRunner.java
@@ -1,37 +1,72 @@
package mill.testng;
-import org.scalatools.testing.Fingerprint;
-import org.scalatools.testing.Logger;
-import org.scalatools.testing.Runner2;
-import org.scalatools.testing.EventHandler;
+import sbt.testing.*;
-public class TestNGRunner extends Runner2 {
- ClassLoader testClassLoader;
- Logger[] loggers;
- TestRunState state;
- public TestNGRunner(ClassLoader testClassLoader, Logger[] loggers, TestRunState state) {
- this.testClassLoader = testClassLoader;
- this.loggers = loggers;
- this.state = state;
+class TestNGTask implements Task {
+
+ TaskDef taskDef;
+ TestNGRunner runner;
+ public TestNGTask(TaskDef taskDef, TestNGRunner runner){
+ this.taskDef = taskDef;
+ this.runner = runner;
}
- public void run(String testClassname, Fingerprint fingerprint, EventHandler eventHandler, String[] testOptions) {
+
+ @Override
+ public String[] tags() {
+ return new String[0];
+ }
+
+ @Override
+ public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
if (TestRunState.permissionToExecute.tryAcquire()) {
TestNGInstance.start(
TestNGInstance.loggingTo(loggers)
- .loadingClassesFrom(testClassLoader)
- .using(testOptions)
- .storingEventsIn(state.recorder)
+ .loadingClassesFrom(runner.testClassLoader)
+ .using(runner.args())
+ .storingEventsIn(runner.state.recorder)
);
- state.testCompletion.countDown();
+ runner.state.testCompletion.countDown();
}
try{
- state.testCompletion.await();
+ runner.state.testCompletion.await();
}catch(InterruptedException e){
throw new RuntimeException(e);
}
- state.recorder.replayTo(eventHandler, testClassname, loggers);
+ runner.state.recorder.replayTo(eventHandler, taskDef.fullyQualifiedName(), loggers);
+ return new Task[0];
+ }
+
+ @Override
+ public TaskDef taskDef() {
+ return taskDef;
+ }
+}
+public class TestNGRunner implements Runner {
+ ClassLoader testClassLoader;
+ TestRunState state;
+ String[] args;
+ String[] remoteArgs;
+ public TestNGRunner(String[] args, String[] remoteArgs, ClassLoader testClassLoader, TestRunState state) {
+ this.testClassLoader = testClassLoader;
+ this.state = state;
+ this.args = args;
+ this.remoteArgs = remoteArgs;
+ }
+
+ public Task[] tasks(TaskDef[] taskDefs) {
+ Task[] out = new Task[taskDefs.length];
+ for (int i = 0; i < taskDefs.length; i += 1) {
+ out[i] = new TestNGTask(taskDefs[i], this);
+ }
+ return out;
}
+
+ public String done() { return null; }
+
+ public String[] remoteArgs() { return remoteArgs; }
+
+ public String[] args() { return args; }
}