Skip to content

Commit 11122c4

Browse files
committed
Caffeine junit & testng suites seem to pass
1 parent db8d967 commit 11122c4

File tree

9 files changed

+92
-107
lines changed

9 files changed

+92
-107
lines changed

ci/test-mill-2.sh

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ set -eux
55
# Starting from scratch...
66
git clean -xdf
77

8+
mill testng.publishLocal # Needed for CaffeineTests
89
# Run tests
910
mill integration.test "mill.integration.local.{AcyclicTests,AmmoniteTests,CaffeineTests}"

integration/test/resources/caffeine/build.sc

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ trait CaffeineModule extends MavenModule{
2121
def testFrameworks = Seq("com.novocode.junit.JUnitFramework")
2222
def ivyDeps = Agg(
2323
ivy"com.novocode:junit-interface:0.11",
24+
ivy"com.lihaoyi:mill-testng:0.1.7-79-91f790",
2425
libraries.guava,
2526
testLibraries.mockito,
2627
testLibraries.hamcrest,
@@ -73,6 +74,7 @@ object caffeine extends CaffeineModule {
7374
}
7475

7576
object test extends Tests{
77+
def testFrameworks = Seq("mill.testng.TestNGFramework")
7678
def ivyDeps = super.ivyDeps() ++ Agg(
7779
libraries.ycsb,
7880
libraries.fastutil,

integration/test/src/mill/integration/CaffeineTests.scala

+15-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ class CaffeineTests(fork: Boolean) extends IntegrationTestSuite("MILL_CAFFEINE_R
99
// Caffeine only can build using Java 9 or up. Java 8 results in weird
1010
// type inference issues during the compile
1111
if (mill.client.ClientServer.isJava9OrAbove){
12-
assert(eval(s"caffeine.test.compile"))
13-
assert(eval(s"caffeine.test"))
14-
assert(eval(s"guava.test.compile"))
15-
assert(eval(s"jcache.test.compile"))
16-
assert(eval(s"simulator.test.compile"))
12+
assert(eval("caffeine.test.compile"))
13+
assert(eval("guava.test"))
14+
val suites = Seq(
15+
"com.github.benmanes.caffeine.SingleConsumerQueueTest",
16+
"com.github.benmanes.caffeine.cache.AsyncTest",
17+
"com.github.benmanes.caffeine.cache.CaffeineTest",
18+
"com.github.benmanes.caffeine.cache.TimerWheelTest"
19+
)
20+
assert(eval(
21+
"caffeine.test",
22+
"-testclass", suites.mkString(",")
23+
))
24+
assert(eval("guava.test.compile"))
25+
assert(eval("jcache.test.compile"))
26+
assert(eval("simulator.test.compile"))
1727
}
1828
}
1929

scalalib/src/mill/scalalib/Lib.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ object Lib{
294294
!cls.isInterface &&
295295
(f.isModule == cls.getName.endsWith("$")) &&
296296
cl.loadClass(f.superclassName()).isAssignableFrom(cls) &&
297-
cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1
297+
(f.isModule || cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1)
298298

299299
case f: AnnotatedFingerprint =>
300300
val annotationCls = cl.loadClass(f.annotationName()).asInstanceOf[Class[Annotation]]
301301
(f.isModule == cls.getName.endsWith("$")) &&
302-
cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1 &&
302+
(f.isModule || cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1)
303303
(
304304
cls.isAnnotationPresent(annotationCls) ||
305305
cls.getDeclaredMethods.exists(_.isAnnotationPresent(annotationCls))

testng/src/mill/testng/EventRecorder.java

-40
This file was deleted.

testng/src/mill/testng/TestNGFramework.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ public Fingerprint[] fingerprints() {
1414

1515
@Override
1616
public Runner runner(String[] args, String[] remoteArgs, ClassLoader classLoader) {
17-
return new TestNGRunner(args, remoteArgs, classLoader, sharedState);
17+
return new TestNGRunner(args, remoteArgs, classLoader);
1818
}
19-
20-
21-
private TestRunState sharedState = new TestRunState();
2219
}
2320

2421
class Annotated implements AnnotatedFingerprint{
@@ -29,4 +26,4 @@ public Annotated(String annotationName) {
2926
}
3027
public String annotationName(){return annotationName;}
3128
public boolean isModule(){return false;}
32-
}
29+
}
+56-24
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
11
package mill.testng;
22

33

4+
import org.testng.*;
5+
import sbt.testing.EventHandler;
46
import sbt.testing.Logger;
57

6-
import org.testng.CommandLineArgs;
7-
import org.testng.TestNG;
8-
98
import com.beust.jcommander.JCommander;
109

11-
public class TestNGInstance {
12-
Logger[] loggers;
13-
ConfigurableTestNG configurableTestNG = new ConfigurableTestNG();
14-
public TestNGInstance(Logger[] loggers){
15-
this.loggers = loggers;
10+
import java.net.URLClassLoader;
11+
import java.util.Arrays;
12+
13+
class TestNGListener implements ITestListener{
14+
EventHandler basket;
15+
String lastName = "";
16+
public TestNGListener(EventHandler basket){
17+
this.basket = basket;
1618
}
17-
TestNGInstance loadingClassesFrom(ClassLoader testClassLoader){
18-
configurableTestNG.addClassLoader(testClassLoader);
19-
return TestNGInstance.this;
19+
public void onTestStart(ITestResult iTestResult) {
20+
String newName = iTestResult.getTestClass().getName() + " " + iTestResult.getName() + " ";
21+
if(!newName.equals(lastName)){
22+
if (!lastName.equals("")){
23+
System.out.println();
24+
}
25+
lastName = newName;
26+
System.out.print(lastName);
27+
}
2028
}
21-
TestNGInstance using(String[] testOptions){
22-
CommandLineArgs args = new CommandLineArgs();
23-
new JCommander(args, testOptions); // args is an output parameter of the constructor!
24-
configurableTestNG.configure(args);
25-
return TestNGInstance.this;
29+
30+
public void onTestSuccess(ITestResult iTestResult) {
31+
System.out.print('+');
32+
basket.handle(ResultEvent.success(iTestResult));
33+
}
34+
35+
public void onTestFailure(ITestResult iTestResult) {
36+
System.out.print('X');
37+
basket.handle(ResultEvent.failure(iTestResult));
2638
}
2739

28-
TestNGInstance storingEventsIn(EventRecorder basket){
29-
configurableTestNG.addListener(basket);
30-
return TestNGInstance.this;
40+
public void onTestSkipped(ITestResult iTestResult) {
41+
System.out.print('-');
42+
basket.handle(ResultEvent.skipped(iTestResult));
3143
}
3244

33-
static void start(TestNGInstance testNG){
34-
testNG.configurableTestNG.run();
45+
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {
46+
basket.handle(ResultEvent.failure(iTestResult));
3547
}
36-
static TestNGInstance loggingTo(Logger[] loggers){ return new TestNGInstance(loggers); }
48+
49+
public void onStart(ITestContext iTestContext) {}
50+
51+
public void onFinish(ITestContext iTestContext) {}
3752
}
3853

54+
public class TestNGInstance extends TestNG{
55+
public TestNGInstance(Logger[] loggers,
56+
ClassLoader testClassLoader,
57+
String[] testOptions,
58+
String suiteName,
59+
EventHandler eventHandler) {
60+
addClassLoader(testClassLoader);
3961

40-
class ConfigurableTestNG extends TestNG{ // the TestNG method we need is protected
41-
public void configure(CommandLineArgs args) { super.configure(args); }
62+
try{
63+
this.setTestClasses(new Class[]{Class.forName(suiteName)});
64+
}catch(ClassNotFoundException e){
65+
throw new RuntimeException(e);
66+
}
67+
this.addListener(new TestNGListener(eventHandler));
68+
CommandLineArgs args = new CommandLineArgs();
69+
new JCommander(args, testOptions); // args is an output parameter of the constructor!
70+
configure(args);
71+
}
4272
}
73+
74+

testng/src/mill/testng/TestNGRunner.java

+14-21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import sbt.testing.*;
44

5+
import java.util.Arrays;
6+
import java.util.Collections;
7+
58
class TestNGTask implements Task {
69

710
TaskDef taskDef;
@@ -18,24 +21,14 @@ public String[] tags() {
1821

1922
@Override
2023
public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
21-
if (TestRunState.permissionToExecute.tryAcquire()) {
22-
TestNGInstance.start(
23-
TestNGInstance.loggingTo(loggers)
24-
.loadingClassesFrom(runner.testClassLoader)
25-
.using(runner.args())
26-
.storingEventsIn(runner.state.recorder)
27-
);
28-
29-
runner.state.testCompletion.countDown();
30-
}
31-
32-
try{
33-
runner.state.testCompletion.await();
34-
}catch(InterruptedException e){
35-
throw new RuntimeException(e);
36-
}
37-
38-
runner.state.recorder.replayTo(eventHandler, taskDef.fullyQualifiedName(), loggers);
24+
System.out.println("Executing " + taskDef.fullyQualifiedName());
25+
new TestNGInstance(
26+
loggers,
27+
runner.testClassLoader,
28+
runner.args(),
29+
taskDef.fullyQualifiedName(),
30+
eventHandler
31+
).run();
3932
return new Task[0];
4033
}
4134

@@ -44,19 +37,19 @@ public TaskDef taskDef() {
4437
return taskDef;
4538
}
4639
}
40+
4741
public class TestNGRunner implements Runner {
4842
ClassLoader testClassLoader;
49-
TestRunState state;
5043
String[] args;
5144
String[] remoteArgs;
52-
public TestNGRunner(String[] args, String[] remoteArgs, ClassLoader testClassLoader, TestRunState state) {
45+
public TestNGRunner(String[] args, String[] remoteArgs, ClassLoader testClassLoader) {
5346
this.testClassLoader = testClassLoader;
54-
this.state = state;
5547
this.args = args;
5648
this.remoteArgs = remoteArgs;
5749
}
5850

5951
public Task[] tasks(TaskDef[] taskDefs) {
52+
System.out.println("TestNGRunner#tasks " + Arrays.toString(taskDefs));
6053
Task[] out = new Task[taskDefs.length];
6154
for (int i = 0; i < taskDefs.length; i += 1) {
6255
out[i] = new TestNGTask(taskDefs[i], this);

testng/src/mill/testng/TestRunState.java

-10
This file was deleted.

0 commit comments

Comments
 (0)