stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.74k stars 177 forks source link

CLI: Allow user to set custom base path #2953

Open rmg-x opened 3 weeks ago

rmg-x commented 3 weeks ago

Is your feature request related to a problem? Please describe. When running the CLI, it would be useful to override the base path to a value other than the current working directory.

This feature would be useful for mutating projects in the following scenarios:

  1. CI/CD pipelines or other automated flows
  2. Testing local changes to the stryker-net project itself, e.g. trying to run from bin/Debug

Describe the solution you'd like Add flag to set a custom base path.

Describe alternatives you've considered N/A

Additional context Code that handles setting the base path here: https://github.com/stryker-mutator/stryker-net/blob/6556ab96d320fc2b7647363577a62683df48b6d6/src/Stryker.CLI/Stryker.CLI/ConfigBuilder.cs#L26-L27

dupdob commented 3 weeks ago

I am not sure I understand this correctly. You could simply change the current directory before running the CLI for that same effect.

Also note that you cannot use Stryker on its own folder: project analysis will fail. You need to use it against another copy of the project.

This is a limitation of buildalyzer that we never tried to fix as it is easy to workaround and very, very specific.

rmg-x commented 3 weeks ago

You could simply change the current directory before running the CLI for that same effect.

You can, but this assumes that you're running Stryker from a "convenient" location, e.g. from PATH or global dotnet tool installation. It also seems more intuitive (to me) so that you're not cd-ing everywhere. It's more of a QoL feature when that assumption is broken.

For example, say that I made a local change to stryker-net and want to run it against my console projects.

Debug executable is located here: C:\Users\me\source\repos\stryker-net-dev\src\Stryker.CLI\Stryker.CLI\bin\Debug\net8.0\Stryker.CLI.exe

My test project locations: C:\Users\me\source\repos\MyConsoleProj1 C:\Users\me\source\repos\MyConsoleProj2 C:\Users\me\source\repos\MyConsoleProj3

Currently, I would have to cd into each of the console projects and insert the long winded debug executable path for Stryker. Rather than just cd-ing once into the debug folder and passing in the more concise folder locations for my projects to the CLI.

EDIT: This would also help when setting breakpoints and running from the IDE since a simple flag could be set in the run configuration. As a temporary way to make that easier, I just hardcode the base path in ConfigBuilder.cs

Also note that you cannot use Stryker on its own folder

I meant it would be useful for devs working on stryker-net to run against other projects from the debug output folder. Sorry for the confusion.