stryker-mutator / stryker4s

Mutation testing for Scala
https://stryker-mutator.io
Apache License 2.0
198 stars 35 forks source link

Plugin for sbt #2

Closed legopiraat closed 5 years ago

legopiraat commented 6 years ago

A plugin would be nice so integration with sbt is easy and fast to setup.

We could make a command like sbt mutationTest

hugo-vrijswijk commented 6 years ago

Definitely something we should have, and it would increase our performance by keeping sbt alive (instead of restarting sbt every mutation). I propose we use sbt stryker to keep in line with strykerjs

legopiraat commented 6 years ago

I wasn't aware that StrykerJs used that as their command. But i fully agree let's make it sbt stryker.

simondel commented 6 years ago

There's not really any default build tool for JS. For .NET Core the command is dotnet stryker though.

scelestino commented 5 years ago

There is anyone working with this improvement? I could give you a hand if you want, I'm very interested in this feature.

hugo-vrijswijk commented 5 years ago

Hi, thanks for your interest! It's definitely high on the priority list, but there's a bit of a technical hurdle to get over. There's a sbt-plugin branch that has some super early work you could Have a look at. Should you have any questions, don't hesitate to ask here or on gitter

scelestino commented 5 years ago

I've been working in this feature for some hours but I'm moving in circles. There are a lot of things that have to be changed in order to add sbt support.

The most blocking and hard to change is the sys.env. Currently ACTIVE_MUTATION is a process property, but in an SBT plugin the runner just need to call test task (in the same process). That is necessary if we want to improve stryker performance, loading SBT for each Mutation is too much for a medium/large project.

Maybe it can be changed to sys.props.

legopiraat commented 5 years ago

Hi Scelestino, clearly at this point performance is still an issue because we have to reboot the sbt process every time when using the current ProcessRunner. We wanted to use sbt as well to keep the process open and gain a lot of speed. So if sys.props enables us to make it work in sbt we would be for that approach!

The ProcessRunner was designed as a fit all solution but in the future we wanted to move to full integration with sbt and maybe others anyway.

Let us know when your hitting walls and we will help you.

hugo-vrijswijk commented 5 years ago

sys.props seems like what we need to change (among many other things, haha) to reuse a single process. This is a big one, so I think it'd be good to collaborate on it if possible. @scelestino I will have a look at any code you've pushed in your fork when I have the time and maybe I could give some insights. Any code (even unfinished) is useful!

scelestino commented 5 years ago

I think I'm very close to get a result.

Due we need to override settings (eg javaOptions) or call the same task over and over again (eg test), I replaced "sys.env.get" with "sys.props.get" + javaOptions and I created a Command instead a Task. That allow me to do things that cannot be done in a normal task. I'ill try to push something working in my branch today.

scelestino commented 5 years ago

@hugo-vrijswijk @legopiraat Can you check my sbt-plugin branch?

It is working, I need to improve some things but the worst is over. This version is really much faster (I need to try it with some bigger project)

legopiraat commented 5 years ago

Overall there is a lot of work done! And I think it's moving in the right direction.

Just a few questions,

And in general, were can we help :)

scelestino commented 5 years ago

How well does it integrate with the current codebase? (in the future we might want to make a maven plugin as well so its good intel)

Now that ACTIVE_MUTATION can be readed from JVM and Process variables, with a custom Runner and Report is enough. The most important method is runMutant.

Would we be able to run a separate Process when we are inside the sbt stryker task? (made a feature so files are copied based on git list)

sbt stryker is a command, not a task. Inside a command you can do almost anything. It would be able to create and run a new process, but I don't know why I would want that. Everything can run smooth inside the sbt process.

Could we add a sbt config key to specify the stryker4s path if for some reason the user not has it in the root, with root being the default?

Downloading Stryker4s source is not need it to run the command, it is a plugin, so there is no path to it. The only thing you need to do is to add the plugin to a project (addSbtPlugin("io.stryker-mutator" % "sbt-stryker4s" % "0.0.1-SNAPSHOT")) and then run sbt stryker. (obviously, before that just publishLocal the plugin)

If you want to run stryker over the sbt-test project, you can do it through sbt scripted

hugo-vrijswijk commented 5 years ago

Awesome work!! I will have a look tomorrow

@scelestino Could you create a pull request? That way we can also provide changes or add comments, even if it's still a WIP