Skip to content

Commit

Permalink
caffeine core and guava tests seem to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Apr 9, 2018
1 parent 11122c4 commit 9295d52
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 50 deletions.
5 changes: 4 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ object integration extends MillModule{
def testArgs = T{
scalajslib.testArgs() ++
scalaworker.testArgs() ++
Seq("-DMILL_TESTNG=" + testng.runClasspath().map(_.path).mkString(",")) ++
Seq(
"-DMILL_TESTNG=" + testng.runClasspath().map(_.path).mkString(","),
"-DMILL_VERSION=" + build.publishVersion()._2
) ++
(for((k, v) <- testRepos()) yield s"-D$k=$v")
}
def forkArgs = testArgs()
Expand Down
2 changes: 1 addition & 1 deletion ci/test-mill-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ git clean -xdf

mill testng.publishLocal # Needed for CaffeineTests
# Run tests
mill integration.test "mill.integration.local.{AcyclicTests,AmmoniteTests,CaffeineTests}"
mill integration.test "mill.integration.local.{AcyclicTests,AmmoniteTests}"
2 changes: 2 additions & 0 deletions ci/test-mill-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ rm -rf ~/.mill

# Run tests
~/mill-release -i integration.test "mill.integration.forked.{AcyclicTests,UpickleTests,PlayJsonTests}"

~/mill-release -i integration.test "mill.integration.local.CaffeineTests"
5 changes: 4 additions & 1 deletion integration/test/resources/caffeine/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait CaffeineModule extends MavenModule{
def testFrameworks = Seq("com.novocode.junit.JUnitFramework")
def ivyDeps = Agg(
ivy"com.novocode:junit-interface:0.11",
ivy"com.lihaoyi:mill-testng:0.1.7-79-91f790",
ivy"com.lihaoyi:mill-testng:${sys.props("MILL_VERSION")}",
libraries.guava,
testLibraries.mockito,
testLibraries.hamcrest,
Expand Down Expand Up @@ -85,6 +85,8 @@ object caffeine extends CaffeineModule {
testLibraries.guavaTestLib,
) ++
testLibraries.testng

def allSourceFiles = super.allSourceFiles().filter(_.path.last != "OSGiTest.java")
}
}

Expand All @@ -99,6 +101,7 @@ object guava extends CaffeineModule {
testLibraries.easymock,
testLibraries.guavaTestLib
)
def allSourceFiles = super.allSourceFiles().filter(_.path.last != "OSGiTest.java")
def forkArgs = Seq(
"-Dguava.osgi.version=" + versions.guava,
"-Dcaffeine.osgi.jar=" + caffeine.jar().path,
Expand Down
5 changes: 4 additions & 1 deletion integration/test/src/mill/integration/CaffeineTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CaffeineTests(fork: Boolean) extends IntegrationTestSuite("MILL_CAFFEINE_R
// type inference issues during the compile
if (mill.client.ClientServer.isJava9OrAbove){
assert(eval("caffeine.test.compile"))
assert(eval("guava.test"))

val suites = Seq(
"com.github.benmanes.caffeine.SingleConsumerQueueTest",
"com.github.benmanes.caffeine.cache.AsyncTest",
Expand All @@ -22,8 +22,11 @@ class CaffeineTests(fork: Boolean) extends IntegrationTestSuite("MILL_CAFFEINE_R
"-testclass", suites.mkString(",")
))
assert(eval("guava.test.compile"))
assert(eval("guava.test"))

assert(eval("jcache.test.compile"))
assert(eval("simulator.test.compile"))

}
}

Expand Down
4 changes: 2 additions & 2 deletions main/test/src/mill/util/ScriptTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{
def scriptSourcePath: Path

val workspacePath = pwd / 'target / 'workspace / workspaceSlug
// val stdOutErr = new PrintStream(new ByteArrayOutputStream())
val stdOutErr = new PrintStream(System.out)
val stdOutErr = new PrintStream(new ByteArrayOutputStream())
// val stdOutErr = new PrintStream(System.out)
val stdIn = new ByteArrayInputStream(Array())
lazy val runner = new mill.main.MainRunner(
ammonite.main.Cli.Config(wd = workspacePath),
Expand Down
45 changes: 28 additions & 17 deletions scalalib/src/mill/scalalib/Lib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,38 @@ object Lib{
if (!exists(base)) Nil
else listClassFiles(base).flatMap { path =>
val cls = cl.loadClass(path.stripSuffix(".class").replace('/', '.'))
fingerprints.find {
case f: SubclassFingerprint =>
!cls.isInterface &&
(f.isModule == cls.getName.endsWith("$")) &&
cl.loadClass(f.superclassName()).isAssignableFrom(cls) &&
(f.isModule || 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("$")) &&
(f.isModule || cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers)) == 1)
(
cls.isAnnotationPresent(annotationCls) ||
cls.getDeclaredMethods.exists(_.isAnnotationPresent(annotationCls))
)

}.map { f => (cls, f) }
val publicConstructorCount =
cls.getConstructors.count(c => c.getParameterCount == 0 && Modifier.isPublic(c.getModifiers))

if (Modifier.isAbstract(cls.getModifiers) || cls.isInterface || publicConstructorCount > 1) {
None
} else {
(cls.getName.endsWith("$"), publicConstructorCount == 0) match{
case (true, true) => matchFingerprints(cl, cls, fingerprints, isModule = true)
case (false, false) => matchFingerprints(cl, cls, fingerprints, isModule = false)
case _ => None
}
}
}
}

testClasses
}
def matchFingerprints(cl: ClassLoader, cls: Class[_], fingerprints: Array[Fingerprint], isModule: Boolean) = {
fingerprints.find {
case f: SubclassFingerprint =>
f.isModule == isModule &&
cl.loadClass(f.superclassName()).isAssignableFrom(cls)

case f: AnnotatedFingerprint =>
val annotationCls = cl.loadClass(f.annotationName()).asInstanceOf[Class[Annotation]]
f.isModule == isModule &&
(
cls.isAnnotationPresent(annotationCls) ||
cls.getDeclaredMethods.exists(_.isAnnotationPresent(annotationCls))
)

}.map { f => (cls, f) }
}

}
4 changes: 4 additions & 0 deletions scalaworker/src/mill/scalaworker/ScalaWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ object ScalaWorker{
args = arguments
)(ctx)

// Clear interrupted state in case some badly-behaved test suite
// dirtied the thread-interrupted flag and forgot to clean up. Otherwise
// that flag causes writing the results to disk to fail
Thread.interrupted()
ammonite.ops.write(Path(outputPath), upickle.default.write(result))
}catch{case e: Throwable =>
println(e)
Expand Down
2 changes: 1 addition & 1 deletion testng/src/mill/testng/ResultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public String fullyQualifiedName() {
}

public Fingerprint fingerprint() {
return Annotated.instance;
return TestNGFingerprint.instance;
}

public Selector selector() {
Expand Down
12 changes: 4 additions & 8 deletions testng/src/mill/testng/TestNGFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TestNGFramework implements Framework {
public String name(){ return "TestNG"; }

public Fingerprint[] fingerprints() {
return new Fingerprint[]{Annotated.instance};
return new Fingerprint[]{TestNGFingerprint.instance};
}

@Override
Expand All @@ -18,12 +18,8 @@ public Runner runner(String[] args, String[] remoteArgs, ClassLoader classLoader
}
}

class Annotated implements AnnotatedFingerprint{
final public static Annotated instance = new Annotated("org.testng.annotations.Test");
String annotationName;
public Annotated(String annotationName) {
this.annotationName = annotationName;
}
public String annotationName(){return annotationName;}
class TestNGFingerprint implements AnnotatedFingerprint{
final public static TestNGFingerprint instance = new TestNGFingerprint();
public String annotationName(){return "org.testng.annotations.Test";}
public boolean isModule(){return false;}
}
11 changes: 2 additions & 9 deletions testng/src/mill/testng/TestNGInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,12 @@ public void onFinish(ITestContext iTestContext) {}
public class TestNGInstance extends TestNG{
public TestNGInstance(Logger[] loggers,
ClassLoader testClassLoader,
String[] testOptions,
String suiteName,
CommandLineArgs args,
EventHandler eventHandler) {
addClassLoader(testClassLoader);

try{
this.setTestClasses(new Class[]{Class.forName(suiteName)});
}catch(ClassNotFoundException e){
throw new RuntimeException(e);
}
this.addListener(new TestNGListener(eventHandler));
CommandLineArgs args = new CommandLineArgs();
new JCommander(args, testOptions); // args is an output parameter of the constructor!

configure(args);
}
}
Expand Down
29 changes: 20 additions & 9 deletions testng/src/mill/testng/TestNGRunner.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package mill.testng;

import com.beust.jcommander.JCommander;
import org.testng.CommandLineArgs;
import sbt.testing.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

class TestNGTask implements Task {

TaskDef taskDef;
TestNGRunner runner;
public TestNGTask(TaskDef taskDef, TestNGRunner runner){
CommandLineArgs cliArgs;
public TestNGTask(TaskDef taskDef,
TestNGRunner runner,
CommandLineArgs cliArgs){
this.taskDef = taskDef;
this.runner = runner;
this.cliArgs = cliArgs;
}

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

@Override
public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
System.out.println("Executing " + taskDef.fullyQualifiedName());
new TestNGInstance(
loggers,
runner.testClassLoader,
runner.args(),
taskDef.fullyQualifiedName(),
cliArgs,
eventHandler
).run();
return new Task[0];
Expand All @@ -49,12 +55,17 @@ public TestNGRunner(String[] args, String[] remoteArgs, ClassLoader testClassLoa
}

public Task[] tasks(TaskDef[] taskDefs) {
System.out.println("TestNGRunner#tasks " + Arrays.toString(taskDefs));
Task[] out = new Task[taskDefs.length];
for (int i = 0; i < taskDefs.length; i += 1) {
out[i] = new TestNGTask(taskDefs[i], this);
CommandLineArgs cliArgs = new CommandLineArgs();
new JCommander(cliArgs, args); // args is an output parameter of the constructor!
if(cliArgs.testClass == null){
String[] names = new String[taskDefs.length];
for(int i = 0; i < taskDefs.length; i += 1){
names[i] = taskDefs[i].fullyQualifiedName();
}
cliArgs.testClass = String.join(",", names);
}
return out;
if (taskDefs.length == 0) return new Task[]{};
else return new Task[]{new TestNGTask(taskDefs[0], this, cliArgs)};
}

public String done() { return null; }
Expand Down

0 comments on commit 9295d52

Please sign in to comment.