Skip to content

Commit

Permalink
Update docs + try to add target option to command
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Werkman committed Sep 15, 2023
1 parent 9ebf7f7 commit e1b4d14
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
31 changes: 22 additions & 9 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,31 +471,36 @@ Use [globbing syntax](https://en.wikipedia.org/wiki/Glob_(programming)) for wild

### `with-baseline` <`flag`> [`:committish`]

Default: `false`
Command line: `--with-baseline:feat-2`
Default: `false`
Command line: `dotnet baseline:feat-2`
Config file: `"baseline": { }`

Enabling `with-baseline` saves the mutation report to a storage location such as the filesystem. The mutation report is loaded at the start of the next mutation run. Any changed source code or unit test results in a reset of the mutants affected by the change. For unchanged mutants the previous result is reused. This feature expands on the [since](#since-flag-committish) feature by providing you with a full report after a partial mutation testrun.

The report name is based on the current branch name or the [project-info.version](#project-infoversion-committish).

Set the diffing target on the command line by passing a committish with the since flag.
Set the diffing target in the config file by setting the [since target](#sincetarget-committish) option.

*\* This feature automatically enables the [since](#since-flag-committish) feature.*

### `target` <`string`>

Default: `false`
Command line: `dotnet baseline --target feat-2`
Config file: `"baseline": { "target": "feat-2" }`

Set the target on the command line by passing a committish with the baseline target option.

### `baseline.enabled` <`flag`>

Default: `null`
Command line: `N/A`
Default: `null`
Command line: `N/A`
Config file: `"baseline": { "enabled": false }`

Enable or disable [with-baseline](#with-baseline-flag-committish). If the enabled property is not set but the `baseline` object exists in the config file it is assumed to be enabled. Use this option to (temporarily) disable `with-baseline` without having to delete the other baseline configuration.

### `baseline.fallback-version` <`string`>

Default: [since-target](#since-flag-committish)
Command line: `N/A`
Default: [since-target](#since-flag-committish)
Command line: `N/A`
Config file: `"baseline": { "fallback-version": 'develop' }`

When [with-baseline](#with-baseline-flag-committish) is enabled and Stryker cannot find an existing report for the current branch the fallback version is used. When Stryker is still unable to find a baseline we will do a complete instead of partial testrun. The complete testrun will then be saved as the new baseline for the next mutation testrun.
Expand Down Expand Up @@ -570,6 +575,14 @@ Config file: `N/A`
When using the azure file storage [provider](#baselineprovider-string) you must pass credentials for the fileshare to Stryker.
For authentication with the azure fileshare we support Shared Access Signatures. For more information on how to configure a SAS check the [Azure documentation](https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview).

### `baseline recreate` <`flag`>

Default: `false`
Command line: `dotnet baseline recreate`
Config file: `N/A`

Sometimes your baseline can get corrupted or out of touch with reality. In that case the baseline can be recreated using this command. This will test all mutations in your project and save the result as the new baseline.

## Troubleshooting

### `verbosity` <`log-level`>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void PrepareCliOptions(IStrykerInputs inputs)
AddCliInput(inputs.DevModeInput, "dev-mode", null, optionType: CommandOptionType.NoValue, category: InputCategory.Misc);
}

private void RegisterCliInput(CommandLineApplication app, CliInput option)
public void RegisterCliInput(CommandLineApplication app, CliInput option)
{
var argumentHint = option.OptionType switch
{
Expand Down Expand Up @@ -178,7 +178,7 @@ private CliInput AddCliOnlyInput(string argumentName, string argumentShortName,
return cliOption;
}

private void AddCliInput(IInput input, string argumentName, string argumentShortName,
public void AddCliInput(IInput input, string argumentName, string argumentShortName,
CommandOptionType optionType = CommandOptionType.SingleValue, InputCategory category = InputCategory.Generic, string argumentHint = null)
{
var cliOption = new CliInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Stryker.CLI
{
[ExcludeFromCodeCoverage] // Not worth the effort to test
[ExcludeFromCodeCoverage(Justification = "Not worth the effort to test")]
internal class GroupedHelpTextGenerator : DefaultHelpTextGenerator
{
protected override void GenerateOptions(CommandLineApplication application, TextWriter output, IReadOnlyList<CommandOption> visibleOptions, int firstColumnWidth)
Expand Down
24 changes: 22 additions & 2 deletions src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Stryker.CLI.Logging;
using Stryker.Core;
using Stryker.Core.Options;
using Stryker.Core.Options.Inputs;

namespace Stryker.CLI
{
Expand Down Expand Up @@ -45,7 +46,7 @@ public int Run(string[] args)
{
Name = "Stryker",
FullName = "Stryker: Stryker mutator for .Net",
Description = "Stryker mutator for .Net",
Description = "The mutation test framework for .Net",
ExtendedHelpText = "Welcome to Stryker for .Net! Run dotnet stryker to kick off a mutation test run",
HelpTextGenerator = new GroupedHelpTextGenerator()
};
Expand All @@ -60,10 +61,29 @@ public int Run(string[] args)
{
baselineCmd.Description = "Enables the baseline feature";
cmdConfigReader.RegisterCommandLineOptions(baselineCmd, inputs);

var targetInput = new CliInput()
{
Input = new BaselineTargetInput(),
ArgumentName = "target",
ArgumentShortName = "t",
Description = @"The target for the compare. For example, when runnin on branch feat-2 and wanting to compare to branch ""main"", set this value to ""main""",
Category = InputCategory.Mutation
};
var targetOption = new CommandOption("-t|--target <value>", CommandOptionType.SingleValue) {
LongName = "target",
ShortName = "t",
Description = @"The target for the compare. For example, when runnin on branch feat-2 and wanting to compare to branch ""main"", set this value to ""main""",
ShowInHelpText = true
};
cmdConfigReader.RegisterCliInput(app, targetInput);
cmdConfigReader.AddCliInput(targetInput.Input, "--target", "-t", CommandOptionType.SingleValue, InputCategory.Mutation);
baselineCmd.AddOption(targetOption);
baselineCmd.Command("recreate", createCmd =>
{
cmdConfigReader.RegisterCommandLineOptions(createCmd, inputs);
cmdConfigReader.RegisterCliInput(app, targetInput);
cmdConfigReader.AddCliInput(targetInput.Input, "--target", "-t", CommandOptionType.SingleValue, InputCategory.Mutation);
createCmd.AddOption(targetOption);

createCmd.OnExecute(() =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Stryker.Core.Exceptions;

namespace Stryker.Core.Options.Inputs
{
public class BaselineTargetInput : Input<string>
{
public override string Default => "main";
protected override string Description => "The target branch/commit to compare with the current codebase when the baseline feature is enabled.";

public string Validate(bool sinceEnabled)
{
if (sinceEnabled && SuppliedInput is not null)
{
if (string.IsNullOrWhiteSpace(SuppliedInput))
{
throw new InputException("The baseline target cannot be empty when the since feature is enabled");
}

return SuppliedInput;
}
return Default;
}
}
}

0 comments on commit e1b4d14

Please sign in to comment.