Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore NoClassDefFoundError exception in test runner #495

Merged
merged 3 commits into from
Dec 15, 2021

Conversation

lwronski
Copy link
Contributor

ScalaCli throws unexpected exception when someone was trying to run test for Main classes.

$ cat HelloWorld.scala
object HelloWorld extends App {
  println("Hello World")
}
$ scala-cli test HelloWorld.scala
Exception in thread "main" java.lang.NoClassDefFoundError: module-info is not a class because access_flag ACC_MODULE is set
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
        at scala.build.testrunner.DynamicTestRunner$.liftedTree1$1(DynamicTestRunner.scala:117)
        at scala.build.testrunner.DynamicTestRunner$.findFramework$$anonfun$2(DynamicTestRunner.scala:121)
        at scala.collection.Iterator$$anon$10.nextCur(Iterator.scala:585)
        at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:599)
        at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:592)
        at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:592)
        at scala.collection.Iterator$SliceIterator.hasNext(Iterator.scala:1228)
        at scala.collection.immutable.List.prependedAll(List.scala:152)
        at scala.collection.IterableOnceOps.toList(IterableOnce.scala:1251)
        at scala.collection.IterableOnceOps.toList$(IterableOnce.scala:1251)
        at scala.collection.AbstractIterator.toList(Iterator.scala:1288)
        at scala.build.testrunner.DynamicTestRunner$.findFramework(DynamicTestRunner.scala:146)
        at scala.build.testrunner.DynamicTestRunner$.$anonfun$4(DynamicTestRunner.scala:177)

If we added new ignored exception in DynamicTestRunner.scala, scala-cli return more friendly user error message:

scala-cli test HelloWorld.scala
No test framework found

@tpasternak
Copy link
Contributor

I'd prefer to print some more details (class Name?), but still it's ok

@lwronski lwronski marked this pull request as ready for review December 14, 2021 15:45
@alexarchambault
Copy link
Contributor

alexarchambault commented Dec 14, 2021

Ideally, we could throw a dedicated exception type there, and catch it wherever it needs to be caught, and where we catch it, either print the simple message ("No test framework found") or keep throwing if verbosity >= 2 say.

@lwronski
Copy link
Contributor Author

Ideally, we could throw a dedicated exception type there, and catch it wherever it needs to be caught, and where we catch it, either print the simple message ("No test framework found") or keep throwing if verbosity >= 2 say.

I added throwing an exception for verbosity> = 2 in this PR.

Copy link
Contributor

@alexarchambault alexarchambault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lwronski lwronski merged commit 2be5aae into VirtusLab:master Dec 15, 2021
@lwronski lwronski deleted the zio-test branch December 16, 2021 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants