Re: Review Request 4361: Patch to make scala tests work

0 views
Skip to first unread message

Stu Hood

unread,
Nov 8, 2016, 4:47:08 PM11/8/16
to Chris Heisterkamp, Eric Ayers, John Sirois, Stu Hood, pants-reviews, Dave Brewster
This is an automatically generated e-mail. To reply, visit: https://rbcommons.com/s/twitter/r/4361/

Thanks for the review! One blocker issue, and then I think we can ship this.


src/java/org/pantsbuild/tools/junit/impl/ScalaTestUtil.java (Diff revision 1)
24
  /**
25
   * Checks if the passed in test clazz has an ancestor that is the scala test suite
26
   * object (looked up in the test classes class loader).
27
   * @param clazz the test class
28
   *
29
   * @return true if the test class is a scalatest test, false if not.
30
   */
31
  public static boolean isScalaTestTest(Class<?> clazz) {
32
    try {
33
      Class suiteClass = Class.forName("org.scalatest.Suite", true, clazz.getClassLoader());
34
      return suiteClass.isAssignableFrom(clazz);
35
    } catch (ClassNotFoundException e) {
36
      throw new RuntimeException(e);
37
    }
38
  }

It seems like this introduces a dependency on scalatest to the runner, because if the org.scalatest.Suite class isn't present, this will raise a RuntimeException?

It seems like the dependency would otherwise not be necessary, so perhaps this should fail silently if that class does not exist? That way non-scalatest tests are not affected.


tests/java/org/pantsbuild/tools/junit/lib/BUILD (Diff revision 1)
10
    '3rdparty:scalatest',

xx: As mentioned above: this won't fly. Should skip the scalatest codepath cleanly if scalatest is not present.


- Stu Hood


On November 8th, 2016, 12:40 a.m. UTC, Dave Brewster wrote:

Review request for pants-reviews, Chris Heisterkamp, John Sirois, Stu Hood, and Eric Ayers.
By Dave Brewster.

Updated Nov. 8, 2016, 12:40 a.m.

Bugs: 4013
Repository: pants

Description

Change to make scalatest test work using the JUnitRunner builtin to scala test. Basically I check if the test extends org.scalatest.Suite, if it does I include it in the specs. Later on, we do the same thing when converting the test class to a junit Runner. We check to see if it is a Suite, and if so then fake like we included the @RunWith annotation.

A few notes: 1) I didn't support scala test "methods" 2) I used reflection instead of modifying junit.py and friends to make scalatest be a non-shaded jar (in fact we don't need to include it at all) 3) I made sure I used the test class's class loader to load Suite and JUnitRunner 4) I bumped the runner_jar version to 1.0.16, I hope this is correct.

I would love to see this as a 1.2.1 release.

NOTE: This is a recreate of #4344

Diffs

  • src/java/org/pantsbuild/tools/junit/impl/AnnotatedClassRequest.java (659688715fe17a31604e1233eee72043c1983eac)
  • src/java/org/pantsbuild/tools/junit/impl/ConsoleRunnerImpl.java (bb6620d3b1f48ec4c8cef0902464d452b15d0c35)
  • src/java/org/pantsbuild/tools/junit/impl/CustomAnnotationBuilder.java (PRE-CREATION)
  • src/java/org/pantsbuild/tools/junit/impl/ScalaTestUtil.java (PRE-CREATION)
  • src/java/org/pantsbuild/tools/junit/impl/Util.java (5decafc26fd7f145c1acdf68897807086ba7ce8e)
  • src/java/org/pantsbuild/tools/junit/withretry/AllDefaultPossibilitiesBuilderWithRetry.java (a7ed9222c6913933236b904df3e7a96c5e86bd7d)
  • tests/java/org/pantsbuild/tools/junit/impl/BUILD (66151e512109d1ec9eb59171078419f91d3d7fc7)
  • tests/java/org/pantsbuild/tools/junit/impl/ConsoleRunnerTest.java (50ae75d6929324b91ea7aaaec96e7ff032f882dd)
  • tests/java/org/pantsbuild/tools/junit/impl/SpecParserTest.java (f6763c364a63f5c86c27af7e802d1450562ee623)
  • tests/java/org/pantsbuild/tools/junit/impl/UtilTest.java (573d3b408868182e7e8cf08e6f528d7195801761)
  • tests/java/org/pantsbuild/tools/junit/lib/BUILD (2affb60039a6618f6a0eead6dd537f29f25aaa80)
  • tests/scala/org/pantsbuild/tools/junit/lib/BUILD (PRE-CREATION)
  • tests/scala/org/pantsbuild/tools/junit/lib/MockScalaTest.scala (PRE-CREATION)
  • tests/scala/org/pantsbuild/tools/junit/lib/NotAScalaTest.scala (PRE-CREATION)

View Diff

Stu Hood

unread,
Nov 8, 2016, 6:03:31 PM11/8/16
to Chris Heisterkamp, Eric Ayers, John Sirois, Stu Hood, pants-reviews, Dave Brewster
This is an automatically generated e-mail. To reply, visit: https://rbcommons.com/s/twitter/r/4361/

Ship it!

Thanks!

Will merge this after a few hours to give other folks a chance to provide feedback.


One note about backporting this in 1.2.1: we can certainly do that, but note that it will not be necessary for it to land in a release before it is usable. It's possible to override any JVM tool version in pants by creating a target in a well-known/configurable location:

$ ./pants help-advanced junit | grep -A4 'junit-junit'
--junit-junit=<target_option> (default: //:junit)
    Target address spec for overriding the classpath of the junit jvm tool which
    is, by default: [JarDependency(org=u'org.pantsbuild', base_name=u'junit-
    runner', rev=u'1.0.15', force=False, ext=None, url=None, apidocs=None,
    classifier=None, mutable=None, intransitive=False, excludes=())]


- Stu Hood


On November 8th, 2016, 10:15 p.m. UTC, Dave Brewster wrote:

Review request for pants-reviews, Chris Heisterkamp, John Sirois, Stu Hood, and Eric Ayers.
By Dave Brewster.

Updated Nov. 8, 2016, 10:15 p.m.

Bugs: 4013
Repository: pants

Description

Change to make scalatest test work using the JUnitRunner builtin to scala test. Basically I check if the test extends org.scalatest.Suite, if it does I include it in the specs. Later on, we do the same thing when converting the test class to a junit Runner. We check to see if it is a Suite, and if so then fake like we included the @RunWith annotation.

A few notes: 1) I didn't support scala test "methods" 2) I used reflection instead of modifying junit.py and friends to make scalatest be a non-shaded jar (in fact we don't need to include it at all) 3) I made sure I used the test class's class loader to load Suite and JUnitRunner 4) I bumped the runner_jar version to 1.0.16, I hope this is correct.

I would love to see this as a 1.2.1 release.

NOTE: This is a recreate of #4344

Diffs

  • src/java/org/pantsbuild/tools/junit/impl/AnnotatedClassRequest.java (659688715fe17a31604e1233eee72043c1983eac)
  • src/java/org/pantsbuild/tools/junit/impl/ConsoleRunnerImpl.java (bb6620d3b1f48ec4c8cef0902464d452b15d0c35)
  • src/java/org/pantsbuild/tools/junit/impl/CustomAnnotationBuilder.java (PRE-CREATION)
  • src/java/org/pantsbuild/tools/junit/impl/ScalaTestUtil.java (PRE-CREATION)
  • src/java/org/pantsbuild/tools/junit/impl/Util.java (5decafc26fd7f145c1acdf68897807086ba7ce8e)
  • src/java/org/pantsbuild/tools/junit/withretry/AllDefaultPossibilitiesBuilderWithRetry.java (a7ed9222c6913933236b904df3e7a96c5e86bd7d)
  • tests/java/org/pantsbuild/tools/junit/impl/BUILD (66151e512109d1ec9eb59171078419f91d3d7fc7)
  • tests/java/org/pantsbuild/tools/junit/impl/ConsoleRunnerTest.java (50ae75d6929324b91ea7aaaec96e7ff032f882dd)
  • tests/java/org/pantsbuild/tools/junit/impl/SpecParserTest.java (f6763c364a63f5c86c27af7e802d1450562ee623)
  • tests/java/org/pantsbuild/tools/junit/impl/UtilTest.java (573d3b408868182e7e8cf08e6f528d7195801761)
  • tests/scala/org/pantsbuild/tools/junit/lib/BUILD (PRE-CREATION)
  • tests/scala/org/pantsbuild/tools/junit/lib/MockScalaTest.scala (PRE-CREATION)
  • tests/scala/org/pantsbuild/tools/junit/lib/NotAScalaTest.scala (PRE-CREATION)

Stu Hood

unread,
Nov 10, 2016, 3:23:39 PM11/10/16
to Chris Heisterkamp, Eric Ayers, John Sirois, Stu Hood, pants-reviews, Dave Brewster
This is an automatically generated e-mail. To reply, visit: https://rbcommons.com/s/twitter/r/4361/

On November 8th, 2016, 11:03 p.m. UTC, Stu Hood wrote:

Thanks!

Will merge this after a few hours to give other folks a chance to provide feedback.


One note about backporting this in 1.2.1: we can certainly do that, but note that it will not be necessary for it to land in a release before it is usable. It's possible to override any JVM tool version in pants by creating a target in a well-known/configurable location:

$ ./pants help-advanced junit | grep -A4 'junit-junit'
--junit-junit=<target_option> (default: //:junit)
    Target address spec for overriding the classpath of the junit jvm tool which
    is, by default: [JarDependency(org=u'org.pantsbuild', base_name=u'junit-
    runner', rev=u'1.0.15', force=False, ext=None, url=None, apidocs=None,
    classifier=None, mutable=None, intransitive=False, excludes=())]

A quick update: this weekend is crazy with Scala by the Bay and another event, and I want to give this a real-world test in our repo, so I might hold off on merging until Monday unless a second reviewer comes along to confirm that this is ready.


- Stu

Stu Hood

unread,
Nov 15, 2016, 1:57:44 AM11/15/16
to Chris Heisterkamp, Eric Ayers, John Sirois, Stu Hood, pants-reviews, Dave Brewster
This is an automatically generated e-mail. To reply, visit: https://rbcommons.com/s/twitter/r/4361/

Fix it, then Ship it!

Did some cursory testing internally, and this seems sane. There is one issue to clear up which seems to have killed CI: please update when CI is green and I'll land this immediately.


src/java/org/pantsbuild/tools/junit/impl/ScalaTestUtil.java (Diff revision 2)
20
      // debatable what to do here.  isScalaTest should fail if scala test isn't available so this is probably ok.

- Stu Hood

Stu Hood

unread,
Nov 15, 2016, 8:35:17 PM11/15/16
to Chris Heisterkamp, Eric Ayers, John Sirois, Stu Hood, pants-reviews, Dave Brewster
This is an automatically generated e-mail. To reply, visit: https://rbcommons.com/s/twitter/r/4361/

On November 15th, 2016, 6:57 a.m. UTC, Stu Hood wrote:

src/java/org/pantsbuild/tools/junit/impl/ScalaTestUtil.java (Diff revision 2)
20
      // debatable what to do here.  isScalaTest should fail if scala test isn't available so this is probably ok.

This line fails in checkstyle:

https://travis-ci.org/pantsbuild/pants/builds/174350476

Your most recent run succeeded. Will merge when you post it here.


- Stu

Reply all
Reply to author
Forward
0 new messages