Skip to content

ScalaTest Integration #94

Closed
wants to merge 82 commits into from

8 participants

@cheeseng

Hi guys,

This fork added ScalaTest integration, which facilitates user to use ScalaTest within Scala IDE. In summary, user would be able to:-

-Select a ScalaTest file/suite/test from source code to run.
-Show test results in either ScalaTest standard GUI or built-in ScalaTest View (if user uses ScalaTest 2.0 snapshot)
-Navigator to source from the ScalaTest view.

The integration only adds dependency to ScalaTest Finders, not the whole ScalaTest:-


org.scalatest
scalatest-finders_2.9.0
0.9.1-SNAPSHOT

User could choose their own ScalaTest version by including it on their build path.

Thanks.

Best Regards,
Chee Seng

@dragos

You could use pattern matching on the tree, since trees are case classes, or have extractors. For instance:

case Apply(fun, args) => ..

or even

case Apply(fun, List(Literal(arg1), Literal(arg2)) =>

Have a look at any source in the IDE project where trees are inspected to get a taste of it.

@dragos

This could be done much more efficiently if you used the position information of the tree you're looking for. Positions have a method includes to test if a position is fully included inside another. That would guide your search in this case. Otherwise, you are blindly traversing the whole AST. Have a look at class Locator, as I mentioned by email on scala-ide-dev.

Eclipse Scala IDE member
@dragos

All type information should be retrieved using the Symbol. They hold the correct information, while the tree contains what the user wrote (meaning there is no type inference results, etc). So I would do:

val sym = defDef.symbol
sym.name
sym.info.paramTypes
cheeseng and others added some commits Feb 6, 2012
@cheeseng cheeseng Rewrite getParent method in ScalaTestLaunchShortcut using
Position.includes.
0449610
@cheeseng cheeseng Change to use Symbol.decodedName. 17a532b
@cheeseng cheeseng Change to use symbol.info.paramTypes instead of symbol.info.paramsType,
but stay commented as it still doesn't compile.
f70b5b3
@cheeseng cheeseng Added code to transform AST in eclipse to AST used by ScalaTest's
finder.
741aa1e
@cheeseng cheeseng Added code to map eclipse AST to ScalaTest's finder AST. 86bdbfd
@cheeseng cheeseng Refactored code for transforming AST and find ScalaTest's tests into
ScalaTestFinder, and solve the dependent type problem.
b72665a
@cheeseng cheeseng Added ScalaTest dependency into pom.xml and .classpath. 1795932
@cheeseng cheeseng Added ScalaTest Launch Configuration screen, which has a Test Class
field with search function that only list project's classes that
subclass org.scalatest.Suite.
826f3aa
@cheeseng cheeseng Make AST wrapper classes as case class to enable use in pattern
matching.
2424c39
@cheeseng cheeseng Change to use URLClassLoader to load Suite, Style and Finder class from
client project's classpath, to support loading of custom style traits
and finders.
15bd3fc
@cheeseng cheeseng Changed ScalaTestFinder and ScalaTestLauncherShortcut to use only
classes from scalatest-finders.jar.
5b8f978
@cheeseng cheeseng Fixed incorrect target's parent behavior, if target of a method
invocation 'A' is another method invocation 'B', 'B' method invocation's
parent should be set to 'A'.
8759f9f
@cheeseng cheeseng Change to cast to GenericApply to avoid casting error. 28cfa31
@cheeseng cheeseng Added org.scalatest.finder.* to export content. 2363913
@cheeseng cheeseng Updated ScalaTest Finder dependency to use version 1.0.0. 73fd098
@cheeseng cheeseng Added code launch selected Scala Test suite. 39484f8
@cheeseng cheeseng Fixed problem in getChildren and getTarget methodd in ScalaTestFinder.
Added case to handle user clicking on non-Scala source file in
ScalaTestLaunchShortcut.
7b8847e
@cheeseng cheeseng Separated code to launch ScalaTest Suite and Test. 8fe6542
@cheeseng cheeseng Added support of launching ScalaTest from launch configuration based on
File and Package.
b773ef2
@cheeseng cheeseng Added shortcut support to launch selected file. d2d8e60
@cheeseng cheeseng Added ScalaTestLaunchShortcut.containsScalaTestSuite and use it in
ScalaTestLaunchableTester for faster popup.
92f670e
@cheeseng cheeseng Added support of launching ScalaTest File by right-clicking on Scala
source file in Package Explorer/Navigator.
3041705
@cheeseng cheeseng Added support of launching ScalaTest package when a package is selected
from Package Manager/Navigator.
8effe86
@cheeseng cheeseng Refactored ScalaTestLaunchShortcut. 5fb0019
@cheeseng cheeseng Added support of launching Suite by right-clicking on class in Package
Explorer.
d9d1aa7
@cheeseng cheeseng Rewrite launch in ScalaTestPackageLaunchShortcut and
ScalaTestFileLaunchShortcut to use ITreeSelection.getFirstElement.
bbfebc7
@cheeseng cheeseng Changed ScalaTest - Test menu item to be shown only when part selected
in editor can be identified by ScalaTest finder as test.
89f709b
@cheeseng cheeseng Changed 'ScalaTest - File' and 'ScalaTest - Suite' based on selection
context.
65bc0e4
@cheeseng cheeseng Changed to use IType.getSuperInterfaceNames() in
ScalaTestLaunchShortcut.isScalaTestSuite to determine if the selected
source is a Scala Test Suite.
f5a1fb3
@cheeseng cheeseng Changed launch configuration of suite type to support test name(s)
entry.
9ba5c56
@cheeseng cheeseng Updated to use ScalaTest Finders 1.0.1 to fix running selected
FeatureSpec problem, and fixed problem in ScalaTestFinder to fix running
selected test in FreeSpec.
39f58fc
@cheeseng cheeseng Added initial work for run result view. bfcc2cb
@cheeseng cheeseng Changed models in ScalaTestModels.scala to postfix with the word
'Model', to avoid 'Test' class to have conflicting class name with
'Test' class name used in the same package.
bf004bf
@cheeseng cheeseng Initial working counter panel and progress bar. 9c0b390
@cheeseng cheeseng Changed counter panel to use ScalaTest status, which includes
count of test succeed, failure, ignored, pending, canceled, total suites
and aborted suites count.
385b228
@cheeseng cheeseng Changed to use Suite icons for Runs, Suites and Suite Aborted. 57f4cf2
@cheeseng cheeseng Added initial working version of Tree view of the suites and tests being
run.
4cf99b9
@cheeseng cheeseng Added support of displaying info/markup provided in the tree view. 6c726cb
@cheeseng cheeseng Got the hopping to source code for TopOfClass location to work. 86b9bb4
@cheeseng cheeseng Got hopping for TopOfMethod and LineInFile location type to work. 4bec63c
@cheeseng cheeseng Added hopping support for SeeStackDepthException location type. 795fad5
@cheeseng cheeseng Changed test failure icon to use red x instead of blue. Changed label
in counter panel "Succeed" -> "Succeeded", "Failure" -> "Failed". 
Changed to not show MarkupProvided as a node in the tree viewer.  Added
check to filter out org.scalatest.tools.DiscoverySuite.
eb80d81
@cheeseng cheeseng Added Stack Trace panel to show stack trace of selected node in tree. 03f6eeb
@cheeseng cheeseng Added popup in tree view for suite or test node in tree viewer, yet to
implement code when popup selected.
ecb5533
@cheeseng cheeseng Added code to support rerunning selected suite/test. eb560e5
@cheeseng cheeseng Added buttons to rerun all tests and failed tests to ScalaTest view. 2607c0a
@cheeseng cheeseng Removed code to copy rerunner from suite to TestModel's rerunner, as the
latest built from socketrep branch already supports this.
225f5df
@cheeseng cheeseng Added stack folding feature to ScalaTest view. 94906aa
@cheeseng cheeseng Updated code to work with suite marked with @WrapWith correctly,
identify them as ScalaTest runnable suite, and lookup @Style from the
runner class.
8040792
@cheeseng cheeseng Added code to support auto build before rerun tests. a9eec38
@cheeseng cheeseng Changed icon for test failed. e2e5a4a
@cheeseng cheeseng Added support of auto-expand failed test node. 947e168
@cheeseng cheeseng Added support of showing next/previous failed text. 78bc70c
@cheeseng cheeseng Added 'stop' feature. c1b381a
@cheeseng cheeseng Added code changes to enable stop button to work, and support of auto…
…-relayout when ScalaTest view orientation changes.
849a3e9
@cheeseng cheeseng Cleaned up code. Disabled next/prev failed test button when there's …
…o failed test. Fixed view refresh problem after run get terminated by user. Changed to update particular test node for better efficiency, replacing the old way of calling full refresh. Improved reading event XML performance. Fixed inconsistent behavior of opening first failed test after test run.
f186377
@cheeseng cheeseng Added show failed tests only filter. 7f61aa3
@bvenners bvenners Improved two icons. 0233539
@cheeseng cheeseng Changed label 'Runs' to 'Tests' in counter panel. 677fda6
@cheeseng cheeseng Changed next/previous buttons to enable only when there's next/previo…
…us failed test.
aae854e
@cheeseng cheeseng Moved ScalaTest shortcuts' label in plugin.xml into plugin.properties…
…. Further removed unused commented code. Fixed ***Run Aborted*** problem when trying to execute a ScalaTest file with non-ScalaTest suite classes.
e2b7aec
@cheeseng cheeseng Updated to use published scalatest-finders artifact's version. 4d1e09a
@misto
Eclipse Scala IDE member
misto commented Apr 24, 2012

Would it make sense to put this (great!) contribution into its own plug-in instead of sdt.core?

@dragos
Eclipse Scala IDE member
dragos commented Apr 27, 2012

@misto I would love that too. We are trying to break the project into manageable bundles (see for instance sdt.debug). @skyluc knows more about it, but it should be pretty easy to achieve.

@dragos
Eclipse Scala IDE member
dragos commented Apr 27, 2012

..and yes, this is an awesome contribution, can't say how badly we all need it :)

@ijuma
ijuma commented Apr 27, 2012

Great work. One question I have is whether some of this work could be reused for the Specs 2 Google Summer of Code project.

@cheeseng

Hi all,

Sorry for replying late here, what a busy week!

I am ok to make the code into its own bundle, instead of mixing the code in the core itself. After moving them into its own bundle, the user could still install the bundle together when they install Scala IDE, right? Would be great for the Scala IDE user to get the feature out of the box, without needing to install it as another plugin.

@ijuma I am not sure if the code could be reused for the Specs 2 Google Summer of Code project, any URL for that project?

Should I start moving stuff into its own bundle? Is there any guideline that I could follow to create new bundle? I afraid I might be doing the wrong way as I am still very new in eclipse development.

Thanks!

@dragos
Eclipse Scala IDE member
dragos commented Apr 27, 2012

The specs2 project is mentored by Eric Torreborre, it would be good to get in tough with you.

@cheeseng, you can start to package it as a bundle. @skyluc is away until Monday, he will be able to help you. As a starting point, you can have a look at how org.scala-ide.sdt.debug is set up in this repository.

@skyluc
Eclipse Scala IDE member
skyluc commented Apr 27, 2012

@cheeseng yes, i would be great if you could put the code in its own plugin. I don't think there's much doc about extracting Scala based plugin in Eclipse...

You should start by copying the structure of the org.scala-ide.sdt.debug plugin in the current master. The interestings files are .project, .classpath, pom.xml, META-INF/MANIFEST.MF, rename the project and artifact in .project and .pom.xml, and remove the references to tools.jar in .classpath and pom.xml.

That should give you a fairly clean project. Add a reference to it as a module in the org.scala-ide.build/pom.xml, and it should get compiled with everything else.

After that, you need to start moving your code and the content of plugin.xml.

I have limited connectivity right now, but I have a copy of your branch. Just message me if you have problems.

@cheeseng

Thanks @dragos and @skyluc , I'll start the process asap.

@skyluc
Eclipse Scala IDE member
skyluc commented Apr 27, 2012

A few comments:

  • You should rebase the branch on the current master. Your poms are still referencing scala-tools which is not available anymore.

  • I cannot compile the branch on the command line. The compiler complains that it cannot find org.scalatest. Looking at the diffs, it looks like you added the scalatest lib to sbt.full.library. I see two solutions to package the scalatest library. One is to package it in the plugin you are creating right now, like it is down for the miglayout jar in sdt.core. Or creating a plug-in that contains only the scalatest jar, like it is done for scalariform and refactoring. I'm not quite sure how this part works, @dotta ?

  • I don't see any new tests in your branch. It would be great to have at least high level integration test that checks that the feature is basically working. If you check sdt.debug.test, you'll that we use pre-created workspace with saved-to-file launch configurations that are launch in the tests. You should be able to do the same thing, and then you need some to check that the result of the test is what is expected

@cheeseng

Hi @skyluc , the latest code should have the following dependencies added:-


org.scalatest
scalatest-finders_2.9.0
0.9.1-SNAPSHOT

It is actually a mini jar that contains the finders (classes that identify selected test), and not the whole ScalaTest jar itself. We just published that in sonatype in early this week, may be you could try git pull to get the latest?

I do think adding some tests is a good idea, I'll first try to finish moving the code and makes it working as before, and then I think I could checkout how the sdt.debug.test that you mentioned works, and add some similar tests for the plugin.

Thanks!

@rlegendi
rlegendi commented May 1, 2012

Hi @cheeseng, @dotta, @dragos, @ijuma,

I'm the student who would like to integrate Specs2 into the Scala IDE. I made my original proposal public, hopefully now it can be seen on the Goolge Melange site which ijuma linked. Anyway, I started writing a few draft ideas in the Wiki of my forked Scala-IDE repo, you can find some preliminar ideas there (please note that this is just draft, I have to discuss it with Eric).

I haven't heard about ScalaTest before (to be honest, I'm pretty new to Scala), but Mirco showed me this video about Bill Venner's talk at Scala Days. As far as I see ScalaTest is inteded to a support different kind of testing platforms, and it already supports Specs (if I got it right). I think it would be great if I could extend the code with Specs2 support.

@bvenners
bvenners commented May 2, 2012

Hi rlegendi,

Iulian Dragos and I discussed your project in the hallways at ScalaDays. Our feeling was that the right approach to take with the Scala IDE for Eclipse was to let the ScalaTest integration that we submitted here be the platform on top of which users can run ScalaTest, specs2, ScalaCheck, JUnit, and TestNG tests. That way when people have mixed projects, they have one uniform and seamless way to run everything. ScalaTest was designed to do this sort of thing, but what it means is that a great deal of what you proposed for your project has already been done. But certain things have not, and we thought perhaps you could take over those things for specs2, and maybe possibly help by doing these things for JUnit, ScalaCheck, and TestNG as well. But start with specs2 and see how it goes. Here's what you'd need to do:

  1. Create one "wrapper suite" each for the specs2 mutable and immutable Specification style traits
  2. Create one "finder" each for the specs2 mutable and immutable Specification style traits
  3. Enhance the plugin so that it automatically wraps specs2 Specification traits with the wrapper, so that users don't need to put a @WrapWith annotation on it.

These are the same steps that would be required to support JUnit, TestNG, and ScalaCheck, but as I said, start with specs2. I looked at your proposal page and I think there are some things there we haven't done yet, so another way to focus your efforts is to do those things for the ScalaTest plugin, which would mean all 5 supported test frameworks would benefit from your work. But I would suggest you start with the specs2 wrapper suites and finders.

It is very late where I am. I'll let Chee Seng point you to some resources that would help you understand what wrapper suites and finders are, and get started.

@cheeseng
cheeseng commented May 2, 2012

Hi @rlegendi,

You could get started by look at the wrapper suite and finder that we have done for Spec 1 here:-

https://scalatest.googlecode.com/svn/branches/spec-runner

It's a SBT project, you should be able to build the jar and put it into client project classpath. Currently, you'll need to annotate your Spec1 specification with @WrapWith(classOf[Spec1Runner]) for the ScalaTest eclipse plugin to run it. The finder (who figure out the test name you choose by right clicking) for Spec 1 should work as well once you added @WrapWith(classOf[Spec1Runner]).

Do let us know if you have further question(s).

@rlegendi
rlegendi commented May 2, 2012

Great, thanks for the feedback and resources guys! Tomorrow I'll have a meeting with Eric, I am going to discuss this topic with him.

@cheeseng

This pull request should be closed as the effort has been moved to luc's temporary repo at https://github.com/skyluc/scalatest.

@cheeseng cheeseng closed this Jun 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.