Skip to content

Commit 9295d52

Browse files
committed
caffeine core and guava tests seem to pass
1 parent 11122c4 commit 9295d52

File tree

12 files changed

+76
-50
lines changed

12 files changed

+76
-50
lines changed

build.sc

+4-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ object integration extends MillModule{
210210
def testArgs = T{
211211
scalajslib.testArgs() ++
212212
scalaworker.testArgs() ++
213-
Seq("-DMILL_TESTNG=" + testng.runClasspath().map(_.path).mkString(",")) ++
213+
Seq(
214+
"-DMILL_TESTNG=" + testng.runClasspath().map(_.path).mkString(","),
215+
"-DMILL_VERSION=" + build.publishVersion()._2
216+
) ++
214217
(for((k, v) <- testRepos()) yield s"-D$k=$v")
215218
}
216219
def forkArgs = testArgs()

ci/test-mill-2.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ git clean -xdf
77

88
mill testng.publishLocal # Needed for CaffeineTests
99
# Run tests
10-
mill integration.test "mill.integration.local.{AcyclicTests,AmmoniteTests,CaffeineTests}"
10+
mill integration.test "mill.integration.local.{AcyclicTests,AmmoniteTests}"

ci/test-mill-release.sh

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ rm -rf ~/.mill
1515

1616
# Run tests
1717
~/mill-release -i integration.test "mill.integration.forked.{AcyclicTests,UpickleTests,PlayJsonTests}"
18+
19+
~/mill-release -i integration.test "mill.integration.local.CaffeineTests"

integration/test/resources/caffeine/build.sc

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +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",
24+
ivy"com.lihaoyi:mill-testng:${sys.props("MILL_VERSION")}",
2525
libraries.guava,
2626
testLibraries.mockito,
2727
testLibraries.hamcrest,
@@ -85,6 +85,8 @@ object caffeine extends CaffeineModule {
8585
testLibraries.guavaTestLib,
8686
) ++
8787
testLibraries.testng
88+
89+
def allSourceFiles = super.allSourceFiles().filter(_.path.last != "OSGiTest.java")
8890
}
8991
}
9092

@@ -99,6 +101,7 @@ object guava extends CaffeineModule {
99101
testLibraries.easymock,
100102
testLibraries.guavaTestLib
101103
)
104+
def allSourceFiles = super.allSourceFiles().filter(_.path.last != "OSGiTest.java")
102105
def forkArgs = Seq(
103106
"-Dguava.osgi.version=" + versions.guava,
104107
"-Dcaffeine.osgi.jar=" + caffeine.jar().path,

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CaffeineTests(fork: Boolean) extends IntegrationTestSuite("MILL_CAFFEINE_R
1010
// type inference issues during the compile
1111
if (mill.client.ClientServer.isJava9OrAbove){
1212
assert(eval("caffeine.test.compile"))
13-
assert(eval("guava.test"))
13+
1414
val suites = Seq(
1515
"com.github.benmanes.caffeine.SingleConsumerQueueTest",
1616
"com.github.benmanes.caffeine.cache.AsyncTest",
@@ -22,8 +22,11 @@ class CaffeineTests(fork: Boolean) extends IntegrationTestSuite("MILL_CAFFEINE_R
2222
"-testclass", suites.mkString(",")
2323
))
2424
assert(eval("guava.test.compile"))
25+
assert(eval("guava.test"))
26+
2527
assert(eval("jcache.test.compile"))
2628
assert(eval("simulator.test.compile"))
29+
2730
}
2831
}
2932

main/test/src/mill/util/ScriptTestSuite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{
1010
def scriptSourcePath: Path
1111

1212
val workspacePath = pwd / 'target / 'workspace / workspaceSlug
13-
// val stdOutErr = new PrintStream(new ByteArrayOutputStream())
14-
val stdOutErr = new PrintStream(System.out)
13+
val stdOutErr = new PrintStream(new ByteArrayOutputStream())
14+
// val stdOutErr = new PrintStream(System.out)
1515
val stdIn = new ByteArrayInputStream(Array())
1616
lazy val runner = new mill.main.MainRunner(
1717
ammonite.main.Cli.Config(wd = workspacePath),

scalalib/src/mill/scalalib/Lib.scala

+28-17
Original file line numberDiff line numberDiff line change
@@ -289,27 +289,38 @@ object Lib{
289289
if (!exists(base)) Nil
290290
else listClassFiles(base).flatMap { path =>
291291
val cls = cl.loadClass(path.stripSuffix(".class").replace('/', '.'))
292-
fingerprints.find {
293-
case f: SubclassFingerprint =>
294-
!cls.isInterface &&
295-
(f.isModule == cls.getName.endsWith("$")) &&
296-
cl.loadClass(f.superclassName()).isAssignableFrom(cls) &&
297-
(f.isModule || cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1)
298-
299-
case f: AnnotatedFingerprint =>
300-
val annotationCls = cl.loadClass(f.annotationName()).asInstanceOf[Class[Annotation]]
301-
(f.isModule == cls.getName.endsWith("$")) &&
302-
(f.isModule || cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1)
303-
(
304-
cls.isAnnotationPresent(annotationCls) ||
305-
cls.getDeclaredMethods.exists(_.isAnnotationPresent(annotationCls))
306-
)
307-
308-
}.map { f => (cls, f) }
292+
val publicConstructorCount =
293+
cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers))
294+
295+
if (Modifier.isAbstract(cls.getModifiers) || cls.isInterface || publicConstructorCount > 1) {
296+
None
297+
} else {
298+
(cls.getName.endsWith("$"), publicConstructorCount == 0) match{
299+
case (true, true) => matchFingerprints(cl, cls, fingerprints, isModule = true)
300+
case (false, false) => matchFingerprints(cl, cls, fingerprints, isModule = false)
301+
case _ => None
302+
}
303+
}
309304
}
310305
}
311306

312307
testClasses
313308
}
309+
def matchFingerprints(cl: ClassLoader, cls: Class[_], fingerprints: Array[Fingerprint], isModule: Boolean) = {
310+
fingerprints.find {
311+
case f: SubclassFingerprint =>
312+
f.isModule == isModule &&
313+
cl.loadClass(f.superclassName()).isAssignableFrom(cls)
314+
315+
case f: AnnotatedFingerprint =>
316+
val annotationCls = cl.loadClass(f.annotationName()).asInstanceOf[Class[Annotation]]
317+
f.isModule == isModule &&
318+
(
319+
cls.isAnnotationPresent(annotationCls) ||
320+
cls.getDeclaredMethods.exists(_.isAnnotationPresent(annotationCls))
321+
)
322+
323+
}.map { f => (cls, f) }
324+
}
314325

315326
}

scalaworker/src/mill/scalaworker/ScalaWorker.scala

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ object ScalaWorker{
6060
args = arguments
6161
)(ctx)
6262

63+
// Clear interrupted state in case some badly-behaved test suite
64+
// dirtied the thread-interrupted flag and forgot to clean up. Otherwise
65+
// that flag causes writing the results to disk to fail
66+
Thread.interrupted()
6367
ammonite.ops.write(Path(outputPath), upickle.default.write(result))
6468
}catch{case e: Throwable =>
6569
println(e)

testng/src/mill/testng/ResultEvent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public String fullyQualifiedName() {
1616
}
1717

1818
public Fingerprint fingerprint() {
19-
return Annotated.instance;
19+
return TestNGFingerprint.instance;
2020
}
2121

2222
public Selector selector() {

testng/src/mill/testng/TestNGFramework.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class TestNGFramework implements Framework {
99
public String name(){ return "TestNG"; }
1010

1111
public Fingerprint[] fingerprints() {
12-
return new Fingerprint[]{Annotated.instance};
12+
return new Fingerprint[]{TestNGFingerprint.instance};
1313
}
1414

1515
@Override
@@ -18,12 +18,8 @@ public Runner runner(String[] args, String[] remoteArgs, ClassLoader classLoader
1818
}
1919
}
2020

21-
class Annotated implements AnnotatedFingerprint{
22-
final public static Annotated instance = new Annotated("org.testng.annotations.Test");
23-
String annotationName;
24-
public Annotated(String annotationName) {
25-
this.annotationName = annotationName;
26-
}
27-
public String annotationName(){return annotationName;}
21+
class TestNGFingerprint implements AnnotatedFingerprint{
22+
final public static TestNGFingerprint instance = new TestNGFingerprint();
23+
public String annotationName(){return "org.testng.annotations.Test";}
2824
public boolean isModule(){return false;}
2925
}

testng/src/mill/testng/TestNGInstance.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,12 @@ public void onFinish(ITestContext iTestContext) {}
5454
public class TestNGInstance extends TestNG{
5555
public TestNGInstance(Logger[] loggers,
5656
ClassLoader testClassLoader,
57-
String[] testOptions,
58-
String suiteName,
57+
CommandLineArgs args,
5958
EventHandler eventHandler) {
6059
addClassLoader(testClassLoader);
6160

62-
try{
63-
this.setTestClasses(new Class[]{Class.forName(suiteName)});
64-
}catch(ClassNotFoundException e){
65-
throw new RuntimeException(e);
66-
}
6761
this.addListener(new TestNGListener(eventHandler));
68-
CommandLineArgs args = new CommandLineArgs();
69-
new JCommander(args, testOptions); // args is an output parameter of the constructor!
62+
7063
configure(args);
7164
}
7265
}

testng/src/mill/testng/TestNGRunner.java

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package mill.testng;
22

3+
import com.beust.jcommander.JCommander;
4+
import org.testng.CommandLineArgs;
35
import sbt.testing.*;
46

7+
import java.util.ArrayList;
58
import java.util.Arrays;
69
import java.util.Collections;
10+
import java.util.List;
711

812
class TestNGTask implements Task {
913

1014
TaskDef taskDef;
1115
TestNGRunner runner;
12-
public TestNGTask(TaskDef taskDef, TestNGRunner runner){
16+
CommandLineArgs cliArgs;
17+
public TestNGTask(TaskDef taskDef,
18+
TestNGRunner runner,
19+
CommandLineArgs cliArgs){
1320
this.taskDef = taskDef;
1421
this.runner = runner;
22+
this.cliArgs = cliArgs;
1523
}
1624

1725
@Override
@@ -21,12 +29,10 @@ public String[] tags() {
2129

2230
@Override
2331
public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
24-
System.out.println("Executing " + taskDef.fullyQualifiedName());
2532
new TestNGInstance(
2633
loggers,
2734
runner.testClassLoader,
28-
runner.args(),
29-
taskDef.fullyQualifiedName(),
35+
cliArgs,
3036
eventHandler
3137
).run();
3238
return new Task[0];
@@ -49,12 +55,17 @@ public TestNGRunner(String[] args, String[] remoteArgs, ClassLoader testClassLoa
4955
}
5056

5157
public Task[] tasks(TaskDef[] taskDefs) {
52-
System.out.println("TestNGRunner#tasks " + Arrays.toString(taskDefs));
53-
Task[] out = new Task[taskDefs.length];
54-
for (int i = 0; i < taskDefs.length; i += 1) {
55-
out[i] = new TestNGTask(taskDefs[i], this);
58+
CommandLineArgs cliArgs = new CommandLineArgs();
59+
new JCommander(cliArgs, args); // args is an output parameter of the constructor!
60+
if(cliArgs.testClass == null){
61+
String[] names = new String[taskDefs.length];
62+
for(int i = 0; i < taskDefs.length; i += 1){
63+
names[i] = taskDefs[i].fullyQualifiedName();
64+
}
65+
cliArgs.testClass = String.join(",", names);
5666
}
57-
return out;
67+
if (taskDefs.length == 0) return new Task[]{};
68+
else return new Task[]{new TestNGTask(taskDefs[0], this, cliArgs)};
5869
}
5970

6071
public String done() { return null; }

0 commit comments

Comments
 (0)