Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(baseline): Allow force creating fresh baseline #2124

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
853cbd9
init
Aug 5, 2022
dc5686f
Merge branch 'master' into baseline-command
richardwerkman Aug 5, 2022
e986e68
Fix unit tests
Aug 5, 2022
89b9cb6
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Aug 5, 2022
5c7705d
Merge branch 'master' of https://github.com/stryker-mutator/stryker-n…
May 26, 2023
68d4e39
Baseline recreate added
Jun 9, 2023
67db04d
merge main
Jun 9, 2023
4871f39
fix merge
Jun 9, 2023
36a4ce9
try to enable baseline by command
Jun 9, 2023
e180534
Fixed command
Jun 23, 2023
f1f6cf3
Fix mutation level
Jun 23, 2023
7dd8a89
merged master
Jun 23, 2023
e44bb01
Remove using
Jun 23, 2023
9ebf7f7
merged master
Sep 1, 2023
e1b4d14
Update docs + try to add target option to command
Sep 15, 2023
ca9b354
Merge master, fix and add tests, consistency (#2712)
danihengeveld Oct 13, 2023
60d6d41
fix using
Oct 13, 2023
02193a7
Merge branch 'master' into baseline-command
richardwerkman Oct 13, 2023
8f39401
Fix: StrykerCLITests info text test (#2713)
danihengeveld Oct 13, 2023
938920d
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Oct 13, 2023
dc0f060
Pass command line arguments and options to subcommands (#2718)
danihengeveld Oct 14, 2023
4d5303b
merged master
Feb 2, 2024
97d5c54
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Feb 2, 2024
0d9a5e6
Fix build
Feb 2, 2024
b530afa
Refactor but I broke it...
Feb 2, 2024
4f6c3cc
Merged master
Feb 16, 2024
a02f5c9
Fix commands
Feb 16, 2024
548d06b
Reset mutation level
Feb 16, 2024
ef6392f
Update docs
Feb 16, 2024
552c9a3
Remove "with-baseline.enabled"
Feb 16, 2024
0d62dda
Update docs and add help text for commands
Feb 16, 2024
e51eebd
Update pipeline docs
Feb 16, 2024
937f26f
merged master
Mar 1, 2024
d0fa85a
.
Mar 1, 2024
d7ac653
Fix tests
Mar 1, 2024
079311a
Merge branch 'master' into baseline-command
richardwerkman Mar 1, 2024
e87f5bb
Fix sonar
Mar 1, 2024
4c21604
Merge branch 'baseline-command' of https://github.com/stryker-mutator…
Mar 1, 2024
1202182
merged master
Mar 15, 2024
0380d09
Fix docs
Mar 15, 2024
0ba1d08
Fix unit tests
Mar 15, 2024
0dc89f4
merged
Jun 21, 2024
20cab04
Remove double logging and refactor
Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,33 +491,30 @@ Use [globbing syntax](https://en.wikipedia.org/wiki/Glob_(programming)) for wild

## Baseline

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

Default: `false`
Command line: `--with-baseline:feat-2`
Default: `false`
Command line: `dotnet stryker baseline`
rouke-broersma marked this conversation as resolved.
Show resolved Hide resolved
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.

*\* The baseline and since features are mutually exclusive. This feature implicitly enables the [since](#since-flag-committish) feature for now.*

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

Default: `null`
Command line: `N/A`
Config file: `"baseline": { "enabled": false }`
Default: `false`
Command line: `dotnet stryker baseline --target feat-2`
Config file: `"baseline": { "target": "feat-2" }`

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.
Set the target on the command line by passing a committish with the baseline target option.

### `baseline.fallback-version` &lt;`string`&gt;

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 @@ -586,7 +583,7 @@ Providing a subfolder is optional but allowed. In the case of a custom subfolder
### `azure-fileshare-sas` &lt;`string`&gt;

Default: `null`
Command line: `--azure-fileshare-sas "se=2022-08-25T14%3A27Z&sp=rwdl&spr=https&sv=2021-06-08&sr=d&sdd=1&sig=XXXXXXXXXXXXX"`
Command line: `dotnet stryker baseline --azure-fileshare-sas "se=2022-08-25T14%3A27Z&sp=rwdl&spr=https&sv=2021-06-08&sr=d&sdd=1&sig=XXXXXXXXXXXXX"`
Config file: `N/A`

When using the azure file storage [provider](#baselineprovider-string) you must pass credentials for the fileshare to Stryker.
Expand All @@ -600,6 +597,14 @@ Allowed permissions: `Read`, `Write`, `Create`

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`

Default: `false`
Command line: `dotnet stryker 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` &lt;`log-level`&gt;
Expand All @@ -619,7 +624,7 @@ All available loglevels are

### `log-to-file` &lt;`flag`&gt;

Default: `false`
Default: `false`
Command line: `[-L|--log-to-file]`
Config file: `N/A`

Expand Down
2 changes: 1 addition & 1 deletion src/Stryker.CLI/Stryker.CLI.UnitTest/ConfigBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static Mock<IStrykerInputs> GetMockInputs()
inputs.Setup(x => x.MutateInput).Returns(new MutateInput());
inputs.Setup(x => x.MutationLevelInput).Returns(new MutationLevelInput());
inputs.Setup(x => x.SinceInput).Returns(new SinceInput());
inputs.Setup(x => x.WithBaselineInput).Returns(new WithBaselineInput());
inputs.Setup(x => x.BaselineEnabledInput).Returns(new BaselineEnabledInput());
inputs.Setup(x => x.OpenReportInput).Returns(new OpenReportInput());
inputs.Setup(x => x.ReportersInput).Returns(new ReportersInput());
inputs.Setup(x => x.ProjectVersionInput).Returns(new ProjectVersionInput());
Expand Down
27 changes: 25 additions & 2 deletions src/Stryker.CLI/Stryker.CLI.UnitTest/StrykerCLITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void ShouldDisplayInfoOnHelp()

var expected = @"Stryker: Stryker mutator for .Net

Stryker mutator for .Net
The mutation test framework for .Net

Usage: Stryker [command] [options]

Expand Down Expand Up @@ -413,7 +413,30 @@ public void ShouldSupplyWithBaselineWhenPassed(params string[] argName)

_strykerRunnerMock.VerifyAll();

_inputs.WithBaselineInput.SuppliedInput.Value.ShouldBeTrue();
_inputs.BaselineEnabledInput.SuppliedInput.Value.ShouldBeTrue();
}

[Theory]
[InlineData("baseline")]
public void ShouldSupplyWithBaselineWhenCommandPassed(params string[] argName)
{
_target.Run(argName);

_strykerRunnerMock.VerifyAll();

_inputs.BaselineEnabledInput.SuppliedInput.Value.ShouldBeTrue();
}

[Theory]
[InlineData("baseline", "recreate")]
public void ShouldSetBaselineRecreateWhenCommandPassed(params string[] argName)
{
_target.Run(argName);

_strykerRunnerMock.VerifyAll();

_inputs.BaselineEnabledInput.SuppliedInput.Value.ShouldBeTrue();
_inputs.BaselineRecreateEnabledInput.SuppliedInput.ShouldBeTrue();
}

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion src/Stryker.CLI/Stryker.CLI.UnitTest/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1924,4 +1924,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,35 @@ public void RegisterInitCommand(CommandLineApplication app, IFileSystem fileSyst
});
}

public void RegisterBaselineCommand(CommandLineApplication app, IStrykerInputs inputs, string[] args, StrykerCli strykerCli)
{
app.Command("baseline", baselineCmd =>
{
RegisterCliInputs(baselineCmd);

baselineCmd.OnExecute(() =>
{
inputs.BaselineEnabledInput.SuppliedInput = true;
baselineCmd.Description = "Starts a stryker run based on the results of a previous run.";
return strykerCli.StartApp(inputs, args, app, this);
});

baselineCmd.Command("recreate", createCmd =>
{
RegisterCliInputs(createCmd);

createCmd.OnExecute(() =>
{
inputs.BaselineEnabledInput.SuppliedInput = true;
createCmd.Description = "Creates a new baseline by doing a full stryker run";
// Enable recreate
inputs.BaselineRecreateEnabledInput.SuppliedInput = true;
return strykerCli.StartApp(inputs, args, app, this);
});
});
});
}

public CommandOption GetConfigFileOption(string[] args, CommandLineApplication app)
{
var commands = app.Parse(args);
Expand Down Expand Up @@ -146,8 +175,8 @@ private static void HandleSingleOrNoValue(IInput strykerInput, CommandOption cli
inputs.SinceTargetInput.SuppliedInput = cliInput.Value();
break;

case WithBaselineInput withBaselineInput:
withBaselineInput.SuppliedInput = true;
case BaselineEnabledInput baselineEnabledInput:
baselineEnabledInput.SuppliedInput = true;
inputs.SinceTargetInput.SuppliedInput = cliInput.Value();
break;

Expand Down Expand Up @@ -182,7 +211,8 @@ private void PrepareCliOptions(IStrykerInputs inputs)
AddCliInput(inputs.MutateInput, "mutate", "m", optionType: CommandOptionType.MultipleValue, argumentHint: "glob-pattern", category: InputCategory.Mutation);
AddCliInput(inputs.MutationLevelInput, "mutation-level", "l", category: InputCategory.Mutation);
AddCliInput(inputs.SinceInput, "since", "", optionType: CommandOptionType.SingleOrNoValue, argumentHint: "committish", category: InputCategory.Mutation);
AddCliInput(inputs.WithBaselineInput, "with-baseline", "", optionType: CommandOptionType.SingleOrNoValue, argumentHint: "committish", category: InputCategory.Mutation);
AddCliInput(inputs.BaselineEnabledInput, "with-baseline", "", optionType: CommandOptionType.SingleOrNoValue, argumentHint: "committish", category: InputCategory.Mutation);
AddCliInput(inputs.BaselineTargetInput, "target", "", argumentHint: "committish", category: InputCategory.Mutation);
// Category: Reporting
AddCliInput(inputs.OpenReportInput, "open-report", "o", CommandOptionType.SingleOrNoValue, argumentHint: "report-type", category: InputCategory.Reporting);
AddCliInput(inputs.ReportersInput, "reporter", "r", optionType: CommandOptionType.MultipleValue, category: InputCategory.Reporting);
Expand All @@ -195,7 +225,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 @@ -230,7 +260,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 @@ -8,7 +8,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
3 changes: 0 additions & 3 deletions src/Stryker.CLI/Stryker.CLI/FileBasedInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public class Since : IExtraData

public class Baseline : IExtraData
{
[JsonPropertyName("enabled")]
public bool? Enabled { get; init; }

[JsonPropertyName("provider")]
public string Provider { get; init; }

Expand Down
4 changes: 0 additions & 4 deletions src/Stryker.CLI/Stryker.CLI/FileConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ public static void DeserializeConfig(string configFilePath, IStrykerInputs input

if (config.Baseline is not null)
{
// Baseline is implicitly enabled when the object exists in the file config
inputs.WithBaselineInput.SuppliedInput = config.Baseline.Enabled ?? true;

inputs.BaselineProviderInput.SuppliedInput = config.Baseline.Provider;
inputs.FallbackVersionInput.SuppliedInput = config.Baseline.FallbackVersion;
inputs.AzureFileStorageUrlInput.SuppliedInput = config.Baseline.AzureFileShareUrl;
}


inputs.CoverageAnalysisInput.SuppliedInput = config.CoverageAnalysis;
inputs.DisableBailInput.SuppliedInput = config.DisableBail;
inputs.DisableMixMutantsInput.SuppliedInput = config.DisableMixMutants;
Expand Down
1 change: 0 additions & 1 deletion src/Stryker.CLI/Stryker.CLI/FileConfigWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ private static FileBasedInputOuter CreateConfig(IStrykerInputs inputs)
{
Baseline = new Baseline
{
Enabled = inputs.WithBaselineInput.SuppliedInput ?? inputs.WithBaselineInput.Default,
Provider = inputs.BaselineProviderInput.SuppliedInput ?? inputs.BaselineProviderInput.Default,
FallbackVersion = inputs.FallbackVersionInput.SuppliedInput ?? inputs.FallbackVersionInput.Default,
AzureFileShareUrl = inputs.AzureFileStorageUrlInput.SuppliedInput ?? inputs.AzureFileStorageUrlInput.Default,
Expand Down
30 changes: 18 additions & 12 deletions src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 @@ -61,18 +61,11 @@ public int Run(string[] args)

cmdConfigReader.RegisterCommandLineOptions(app, inputs);
cmdConfigReader.RegisterInitCommand(app, _fileSystem, inputs, args);
cmdConfigReader.RegisterBaselineCommand(app, inputs, args, this);

app.OnExecute(() =>
{
// app started
PrintStrykerASCIIName();

_configReader.Build(inputs, args, app, cmdConfigReader);
_loggingInitializer.SetupLogOptions(inputs);

PrintStrykerVersionInformationAsync();
RunStryker(inputs);
return ExitCode;
return StartApp(inputs, args, app, cmdConfigReader);
});

try
Expand All @@ -87,16 +80,29 @@ public int Run(string[] args)
{
Console.Error.WriteLine();
Console.Error.WriteLine("Did you mean this?");
foreach(var match in uex.NearestMatches)
foreach (var nearMatch in uex.NearestMatches)
{
Console.Error.WriteLine(" " + match);
Console.Error.WriteLine(" " + nearMatch);
}
}

return ExitCodes.OtherError;
}
}

internal int StartApp(IStrykerInputs inputs, string[] args, CommandLineApplication app, CommandLineConfigReader cmdConfigReader)
{
// app started
PrintStrykerASCIIName();

_configReader.Build(inputs, args, app, cmdConfigReader);
_loggingInitializer.SetupLogOptions(inputs);

PrintStrykerVersionInformationAsync();
RunStryker(inputs);
return ExitCode;
}

private void RunStryker(IStrykerInputs inputs)
{
var result = _stryker.RunMutationTest(inputs, ApplicationLogging.LoggerFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void GetBaseline_UsesBaselineFallbackVersion_WhenReportForCurrentVersionN

var options = new StrykerOptions()
{
WithBaseline = true,
BaselineEnabled = true,
DashboardApiKey = "Acces_Token",
ProjectName = "github.com/JohnDoe/project",
ProjectVersion = "version/human/readable",
Expand Down Expand Up @@ -83,7 +83,7 @@ public void GetBaseline_UsesFallbackVersion_WhenBaselineFallbackVersionNotFound(

var options = new StrykerOptions()
{
WithBaseline = true,
BaselineEnabled = true,
DashboardApiKey = "Acces_Token",
ProjectName = "github.com/JohnDoe/project",
ProjectVersion = "version/human/readable",
Expand Down Expand Up @@ -121,7 +121,7 @@ public void GetBaseline_UsesCurrentVersionReport_IfReportExists()

var options = new StrykerOptions()
{
WithBaseline = true,
BaselineEnabled = true,
DashboardApiKey = "Access_Token",
ProjectName = "github.com/JohnDoe/project",
ProjectVersion = "version/human/readable",
Expand Down Expand Up @@ -155,7 +155,7 @@ public void FilterMutantsReturnAllMutantsWhenCompareToDashboardEnabledAndBaselin

var options = new StrykerOptions()
{
WithBaseline = true,
BaselineEnabled = true,
ProjectVersion = "version",
};

Expand Down Expand Up @@ -187,7 +187,7 @@ public void FilterMutants_WhenMutantSourceCodeIsNull_MutantIsReturned()

var options = new StrykerOptions()
{
WithBaseline = true,
BaselineEnabled = true,
ProjectVersion = "version",
};
var file = new CsharpFileLeaf
Expand Down Expand Up @@ -239,7 +239,7 @@ public void FilterMutants_WhenMutantMatchesSourceCode_StatusIsSetToJsonMutant()

var options = new StrykerOptions()
{
WithBaseline = true,
BaselineEnabled = true,
ProjectVersion = "version",
};
var file = new CsharpFileLeaf
Expand Down Expand Up @@ -302,7 +302,7 @@ public void FilterMutants_WhenMultipleMatchingMutants_ResultIsSetToNotRun()

var options = new StrykerOptions()
{
WithBaseline = true,
BaselineEnabled = true,
ProjectVersion = "version",
};
var file = new CsharpFileLeaf
Expand Down Expand Up @@ -375,7 +375,7 @@ public void ShouldNotUpdateMutantsWithBaselineIfFileNotInBaseline()

var options = new StrykerOptions
{
WithBaseline = true,
BaselineEnabled = true,
ProjectVersion = "version"
};

Expand Down
Loading
Loading