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 25 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
31 changes: 22 additions & 9 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,31 +493,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`
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.*

### `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` &lt;`flag`&gt;

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` &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 @@ -600,6 +605,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` <`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` &lt;`log-level`&gt;
Expand Down
25 changes: 24 additions & 1 deletion 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 @@ -416,6 +416,29 @@ public void ShouldSupplyWithBaselineWhenPassed(params string[] argName)
_inputs.WithBaselineInput.SuppliedInput.Value.ShouldBeTrue();
}

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

_strykerRunnerMock.VerifyAll();

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

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

_strykerRunnerMock.VerifyAll();

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

[Theory]
[InlineData("-o", null)]
[InlineData("-o:html", "html")]
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 @@ -1925,4 +1925,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,53 @@ 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.Description = "Enables the baseline feature";
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
//};
//RegisterCliInput(baselineCmd, targetInput);
//AddCliInput(targetInput.Input, "--target", "-t", CommandOptionType.SingleValue, InputCategory.Mutation);
//baselineCmd.AddOption(targetOption);
baselineCmd.Command("recreate", createCmd =>
{
//RegisterCliInputs(createCmd);
//RegisterCommandLineOptions(createCmd, inputs);
//RegisterCliInput(createCmd, targetInput);

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

public CommandOption GetConfigFileOption(string[] args, CommandLineApplication app)
{
var commands = app.Parse(args);
Expand Down Expand Up @@ -183,6 +230,7 @@ private void PrepareCliOptions(IStrykerInputs inputs)
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.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 +243,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 +278,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: 3 additions & 0 deletions src/Stryker.CLI/Stryker.CLI/FileConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static void DeserializeConfig(string configFilePath, IStrykerInputs input
inputs.AzureFileStorageUrlInput.SuppliedInput = config.Baseline.AzureFileShareUrl;
}

inputs.WithBaselineInput.SuppliedInput =
config.Baseline is not null &&
(config.Baseline.Enabled.HasValue && config.Baseline.Enabled.Value);

inputs.CoverageAnalysisInput.SuppliedInput = config.CoverageAnalysis;
inputs.DisableBailInput.SuppliedInput = config.DisableBail;
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 @@ -13,7 +13,7 @@ public class NullCoalescingExpressionMutatorTests : TestBase
public void ShouldBeMutationLevelStandard()
{
var target = new NullCoalescingExpressionMutator();
target.MutationLevel.ShouldBe(MutationLevel.Basic);
target.MutationLevel.ShouldBe(MutationLevel.Standard);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Shouldly;
using Stryker.Core.Options.Inputs;
using Xunit;

namespace Stryker.Core.UnitTest.Options.Inputs;

public class BaselineRecreateEnabledInputTests : TestBase
{
[Fact]
public void ShouldHaveHelpText()
{
var target = new BaselineRecreateEnabledInput();
target.HelpText.ShouldBe("When enabled a new baseline will be created by doing a full run and storing the mutation results. | default: 'False'");
}

[Fact]
public void ShouldHaveDefault()
{
var target = new BaselineRecreateEnabledInput { SuppliedInput = true };

var result = target.Validate();

target.Default.ShouldBeFalse();
result.ShouldBeTrue();
}

[Fact]
public void ShouldHaveDefaultForDashboard()
{
var target = new BaselineRecreateEnabledInput { SuppliedInput = false };

var result = target.Validate();

target.Default.ShouldBeFalse();
result.ShouldBeFalse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Shouldly;
using Stryker.Core.Exceptions;
using Stryker.Core.Options.Inputs;
using Xunit;

namespace Stryker.Core.UnitTest.Options.Inputs;

public class BaselineTargetInputTests : TestBase
{
[Fact]
public void ShouldHaveHelpText()
{
var target = new BaselineTargetInput();
target.HelpText.ShouldBe(
"The target branch/commit to compare with the current codebase when the baseline feature is enabled. | default: 'master'");
}

[Fact]
public void ShouldUseSuppliedInputWhenSinceEnabled()
{
var suppliedInput = "develop";
var validatedBaselineBranch =
new BaselineTargetInput { SuppliedInput = suppliedInput }.Validate(sinceEnabled: true);
validatedBaselineBranch.ShouldBe(suppliedInput);
}

[Fact]
public void ShouldUseDefaultWhenSinceEnabledAndInputNull()
{
var input = new BaselineTargetInput();
var validatedBaselineBranch = input.Validate(sinceEnabled: true);
validatedBaselineBranch.ShouldBe(input.Default);
}

[Fact]
public void MustNotBeEmptyStringWhenSinceEnabled()
{
var ex = Assert.Throws<InputException>(() =>
{
new BaselineTargetInput { SuppliedInput = "" }.Validate(sinceEnabled: true);
});
ex.Message.ShouldBe("The baseline target cannot be empty when the since feature is enabled");
}

[Fact]
public void ShouldNotValidateBaselineTargetWhenSinceDisabled()
{
var input = new BaselineTargetInput { SuppliedInput = "develop" };
var validatedBaselineBranch = input.Validate(sinceEnabled: false);
validatedBaselineBranch.ShouldBe(input.Default);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Shouldly;
using Stryker.Core.Exceptions;
using Stryker.Core.Options.Inputs;
using Xunit;

Expand All @@ -8,10 +7,10 @@ namespace Stryker.Core.UnitTest.Options.Inputs
public class OpenReportEnabledInputTests : TestBase
{
[Fact]
public void ShouldHaveNoHelpText()
public void ShouldHaveHelpText()
{
var target = new OpenReportEnabledInput();
target.HelpText.ShouldBe(@" | default: 'False'");
target.HelpText.ShouldBe(@"When enabled the report will open automatically after stryker has generated the report. | default: 'False'");
}

[Fact]
Expand Down
Loading
Loading