From 84dc529409f254892af772403652edaad66da7cb Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:51:04 +0100 Subject: [PATCH 01/11] Implemented tests to assert correct behaviour, currently broken due to spectre.console reference being 0.46.0 --- src/Cake.Frosting.Tests/CakeHostTests.cs | 19 ++++++++++++++++++- src/Cake.Tests/Unit/ProgramTests.cs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Cake.Frosting.Tests/CakeHostTests.cs b/src/Cake.Frosting.Tests/CakeHostTests.cs index 02e330fbca..f609e26577 100644 --- a/src/Cake.Frosting.Tests/CakeHostTests.cs +++ b/src/Cake.Frosting.Tests/CakeHostTests.cs @@ -316,7 +316,7 @@ public void Should_Install_Tools() } [Fact] - public void Should_pass_target_within_cakeContext_arguments() + public void Should_Pass_Target_Within_CakeContext_Arguments() { // Given var fixture = new CakeHostFixture(); @@ -359,5 +359,22 @@ public void Should_Execute_Multiple_Targets_In_Correct_Order(string task0, strin fixture.Strategy.ExecuteAsync(Arg.Is(t => t.Name == task2), Arg.Any()); }); } + + [Fact] + public void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() + { + // Given + var fixture = new CakeHostFixture(); + fixture.RegisterTask(); + fixture.Strategy = Substitute.For(); + + // When + fixture.Run("--version", "1.2.3"); + + // Then + fixture.Strategy.Received(1).ExecuteAsync( + Arg.Any(), + Arg.Is(cc => cc.Arguments.HasArgument("version") && cc.Arguments.GetArgument("version").Equals("1.2.3"))); + } } } diff --git a/src/Cake.Tests/Unit/ProgramTests.cs b/src/Cake.Tests/Unit/ProgramTests.cs index 704bf94cd0..cc16e4206b 100644 --- a/src/Cake.Tests/Unit/ProgramTests.cs +++ b/src/Cake.Tests/Unit/ProgramTests.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using System.Xml.Linq; using Autofac; using Cake.Cli; using Cake.Core; @@ -130,5 +131,22 @@ public async Task The_Info_Option_Should_Call_Info_Feature(params string[] args) // Then feature.Received(1).Run(fixture.Console); } + + [Fact] + public async void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() + { + // Given + var fixture = new ProgramFixture(); + var feature = Substitute.For(); + fixture.Overrides.Add(builder => builder.RegisterInstance(feature)); + + // When + var result = await fixture.Run("--version", "1.2.3"); + + // Then + feature.Received(1).Run( + Arg.Is(arguments => arguments.Parsed.Contains("version") && arguments.Parsed["version"].Contains("1.2.3")), + Arg.Is(settings => settings.BuildHostKind == BuildHostKind.Build)); + } } } From ee414b2bf4b23645f4554984cedabba55393d71e Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Thu, 6 Apr 2023 20:06:26 +0100 Subject: [PATCH 02/11] Unit tests, fully implemented --- src/Cake.Frosting.Tests/CakeHostTests.cs | 26 ++++++++++++++++++- .../Fakes/FakeVersionResolver.cs | 25 ++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Cake.Frosting.Tests/Fakes/FakeVersionResolver.cs diff --git a/src/Cake.Frosting.Tests/CakeHostTests.cs b/src/Cake.Frosting.Tests/CakeHostTests.cs index f609e26577..def8ace1b9 100644 --- a/src/Cake.Frosting.Tests/CakeHostTests.cs +++ b/src/Cake.Frosting.Tests/CakeHostTests.cs @@ -3,9 +3,13 @@ // See the LICENSE file in the project root for more information. using System; +using System.Linq; +using Autofac.Core; +using Cake.Cli; using Cake.Core; using Cake.Core.Diagnostics; using Cake.Core.Packaging; +using Cake.Frosting.Tests.Fakes; using Cake.Testing; using Microsoft.Extensions.DependencyInjection; using NSubstitute; @@ -360,6 +364,26 @@ public void Should_Execute_Multiple_Targets_In_Correct_Order(string task0, strin }); } + [Fact] + public void The_Version_Option_Should_Call_Version_Feature() + { + // Given + var fixture = new CakeHostFixture(); + fixture.RegisterTask(); + fixture.Strategy = Substitute.For(); + + // Replace the Cake.Cli.VersionResolver that CakeHost adds to its service collection + // with a fake so that the call to VersionFeature can be asserted below + fixture.Host.ConfigureServices(services => services.Remove(services.Single(sd => sd.ServiceType == typeof(IVersionResolver)))); + fixture.Host.ConfigureServices(services => services.AddSingleton()); + + // When + fixture.Run("--version"); + + // Then + Assert.Collection(fixture.Console.Messages, s => string.Compare(s, "FakeVersion")); + } + [Fact] public void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() { @@ -373,7 +397,7 @@ public void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() // Then fixture.Strategy.Received(1).ExecuteAsync( - Arg.Any(), + Arg.Any(), Arg.Is(cc => cc.Arguments.HasArgument("version") && cc.Arguments.GetArgument("version").Equals("1.2.3"))); } } diff --git a/src/Cake.Frosting.Tests/Fakes/FakeVersionResolver.cs b/src/Cake.Frosting.Tests/Fakes/FakeVersionResolver.cs new file mode 100644 index 0000000000..ec268063d5 --- /dev/null +++ b/src/Cake.Frosting.Tests/Fakes/FakeVersionResolver.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Cake.Cli; + +namespace Cake.Frosting.Tests.Fakes +{ + internal sealed class FakeVersionResolver : IVersionResolver + { + public FakeVersionResolver() + { + } + + public string GetVersion() + { + return "FakeVersion"; + } + + public string GetProductVersion() + { + return "ProductVersion"; + } + } +} From 59b53982f90e589f7945d413526c705b43af6bb2 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Thu, 6 Apr 2023 21:21:36 +0100 Subject: [PATCH 03/11] config.Settings.ConvertFlagsToRemainingArguments = true; --- src/Cake.Frosting/CakeHost.cs | 5 +++++ src/Cake/Program.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Cake.Frosting/CakeHost.cs b/src/Cake.Frosting/CakeHost.cs index 6a4ed7fdea..0240cca543 100644 --- a/src/Cake.Frosting/CakeHost.cs +++ b/src/Cake.Frosting/CakeHost.cs @@ -93,6 +93,11 @@ public int Run(IEnumerable args) config.AddExample(Array.Empty()); config.AddExample(new[] { "--verbosity", "quiet" }); config.AddExample(new[] { "--tree" }); + + // Allow the Cake runner arguments, when found on the command line with a value, + // to be passed directly to the Cake build script as an argument + // eg. "--version=1.2.3" is accessable in the build script by calling Argument("version") + config.Settings.ConvertFlagsToRemainingArguments = true; }); return app.Run(args); diff --git a/src/Cake/Program.cs b/src/Cake/Program.cs index 614f9f5422..a77cfa3200 100644 --- a/src/Cake/Program.cs +++ b/src/Cake/Program.cs @@ -61,6 +61,11 @@ public async Task Run(string[] args) config.AddExample(Array.Empty()); config.AddExample(new[] { "build.cake", "--verbosity", "quiet" }); config.AddExample(new[] { "build.cake", "--tree" }); + + // Allow the Cake runner arguments, when found on the command line with a value, + // to be passed directly to the Cake build script as an argument + // eg. "--version=1.2.3" is accessable in the build script by calling Argument("version") + config.Settings.ConvertFlagsToRemainingArguments = true; }); return await app.RunAsync(args); From 3e20144a759d1223f6cad6f0bbf352e75c6c7df7 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Thu, 6 Apr 2023 21:57:30 +0100 Subject: [PATCH 04/11] Updated tests, all green --- src/Cake.Frosting.Tests/CakeHostTests.cs | 6 +++--- src/Cake.Tests/Unit/ProgramTests.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Cake.Frosting.Tests/CakeHostTests.cs b/src/Cake.Frosting.Tests/CakeHostTests.cs index def8ace1b9..f3591b241d 100644 --- a/src/Cake.Frosting.Tests/CakeHostTests.cs +++ b/src/Cake.Frosting.Tests/CakeHostTests.cs @@ -381,7 +381,7 @@ public void The_Version_Option_Should_Call_Version_Feature() fixture.Run("--version"); // Then - Assert.Collection(fixture.Console.Messages, s => string.Compare(s, "FakeVersion")); + Assert.Collection(fixture.Console.Messages, s => s.Equals("FakeVersion")); } [Fact] @@ -393,12 +393,12 @@ public void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() fixture.Strategy = Substitute.For(); // When - fixture.Run("--version", "1.2.3"); + fixture.Run("--target", "dummytask", "--version=1.2.3"); // Then fixture.Strategy.Received(1).ExecuteAsync( Arg.Any(), - Arg.Is(cc => cc.Arguments.HasArgument("version") && cc.Arguments.GetArgument("version").Equals("1.2.3"))); + Arg.Is(cc => cc.Arguments.HasArgument("version") && cc.Arguments.GetArgument("version") == "1.2.3")); } } } diff --git a/src/Cake.Tests/Unit/ProgramTests.cs b/src/Cake.Tests/Unit/ProgramTests.cs index cc16e4206b..be696abb59 100644 --- a/src/Cake.Tests/Unit/ProgramTests.cs +++ b/src/Cake.Tests/Unit/ProgramTests.cs @@ -141,7 +141,7 @@ public async void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() fixture.Overrides.Add(builder => builder.RegisterInstance(feature)); // When - var result = await fixture.Run("--version", "1.2.3"); + var result = await fixture.Run("--version=1.2.3"); // Then feature.Received(1).Run( From 9ef3b7055aa8da7f385b1db3811f6941669cb344 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:51:04 +0100 Subject: [PATCH 05/11] Implemented tests to assert correct behaviour --- src/Cake.Frosting.Tests/CakeHostTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Frosting.Tests/CakeHostTests.cs b/src/Cake.Frosting.Tests/CakeHostTests.cs index f3591b241d..164f031d3a 100644 --- a/src/Cake.Frosting.Tests/CakeHostTests.cs +++ b/src/Cake.Frosting.Tests/CakeHostTests.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. From 29de9905c4540c8f50676fa8c998a471dc4eae62 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Mon, 22 May 2023 11:29:49 +0100 Subject: [PATCH 06/11] Upgraded spectre.console to 0.47 to get access to the new IConfigurator settings property, ConvertFlagsToRemainingArguments --- src/Cake.Cli/Cake.Cli.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Cli/Cake.Cli.csproj b/src/Cake.Cli/Cake.Cli.csproj index 64a6fd31e2..35e3c2ceaf 100644 --- a/src/Cake.Cli/Cake.Cli.csproj +++ b/src/Cake.Cli/Cake.Cli.csproj @@ -1,4 +1,4 @@ - + Cake.Cli Library From 1ca90c5bf2fcbd02cb8e851da39593ef3aae0cc3 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Mon, 22 May 2023 11:48:12 +0100 Subject: [PATCH 07/11] Minor change to reprompt the build (to see if it passes this time) --- src/Cake.Frosting/CakeHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Frosting/CakeHost.cs b/src/Cake.Frosting/CakeHost.cs index 0240cca543..86141f07c7 100644 --- a/src/Cake.Frosting/CakeHost.cs +++ b/src/Cake.Frosting/CakeHost.cs @@ -94,7 +94,7 @@ public int Run(IEnumerable args) config.AddExample(new[] { "--verbosity", "quiet" }); config.AddExample(new[] { "--tree" }); - // Allow the Cake runner arguments, when found on the command line with a value, + // Allow the Cake runner arguments, when found on the command line with a value // to be passed directly to the Cake build script as an argument // eg. "--version=1.2.3" is accessable in the build script by calling Argument("version") config.Settings.ConvertFlagsToRemainingArguments = true; From 87fdd26d8e0bd35a10a04749f8b7503568b7a549 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Mon, 22 May 2023 12:23:55 +0100 Subject: [PATCH 08/11] Exclude newly introduced tests to check if they are causing the performance problems when the integration tests are run after pushing to the PR --- src/Cake.Frosting.Tests/CakeHostTests.cs | 2 +- src/Cake.Tests/Unit/ProgramTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cake.Frosting.Tests/CakeHostTests.cs b/src/Cake.Frosting.Tests/CakeHostTests.cs index 164f031d3a..dd268f38bb 100644 --- a/src/Cake.Frosting.Tests/CakeHostTests.cs +++ b/src/Cake.Frosting.Tests/CakeHostTests.cs @@ -384,7 +384,7 @@ public void The_Version_Option_Should_Call_Version_Feature() Assert.Collection(fixture.Console.Messages, s => s.Equals("FakeVersion")); } - [Fact] + [Fact(Skip = "Excluded to see if the performance implication of this test is causing the integration tests to break on push to PR")] public void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() { // Given diff --git a/src/Cake.Tests/Unit/ProgramTests.cs b/src/Cake.Tests/Unit/ProgramTests.cs index be696abb59..b4bb534778 100644 --- a/src/Cake.Tests/Unit/ProgramTests.cs +++ b/src/Cake.Tests/Unit/ProgramTests.cs @@ -132,7 +132,7 @@ public async Task The_Info_Option_Should_Call_Info_Feature(params string[] args) feature.Received(1).Run(fixture.Console); } - [Fact] + [Fact(Skip = "Excluded to see if the performance implication of this test is causing the integration tests to break on push to PR")] public async void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() { // Given From 91c5dbb2e819d0d49e10b63b2e33fef106dc5145 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Mon, 22 May 2023 11:48:12 +0100 Subject: [PATCH 09/11] Revert "Minor change to reprompt the build (to see if it passes this time)" This reverts commit ba4e83f5acf4198035524ca973d2823e04344ea1. --- src/Cake.Frosting/CakeHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Frosting/CakeHost.cs b/src/Cake.Frosting/CakeHost.cs index 86141f07c7..0240cca543 100644 --- a/src/Cake.Frosting/CakeHost.cs +++ b/src/Cake.Frosting/CakeHost.cs @@ -94,7 +94,7 @@ public int Run(IEnumerable args) config.AddExample(new[] { "--verbosity", "quiet" }); config.AddExample(new[] { "--tree" }); - // Allow the Cake runner arguments, when found on the command line with a value + // Allow the Cake runner arguments, when found on the command line with a value, // to be passed directly to the Cake build script as an argument // eg. "--version=1.2.3" is accessable in the build script by calling Argument("version") config.Settings.ConvertFlagsToRemainingArguments = true; From e854873a4e00b0c0828b99ffedc395c6821457fb Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Mon, 22 May 2023 12:23:55 +0100 Subject: [PATCH 10/11] Revert "Exclude newly introduced tests to check if they are causing the performance problems when the integration tests are run after pushing to the PR" This reverts commit 3b51ae76b58ca683ae852ab8fa5a4d08280e9f4a. --- src/Cake.Frosting.Tests/CakeHostTests.cs | 2 +- src/Cake.Tests/Unit/ProgramTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cake.Frosting.Tests/CakeHostTests.cs b/src/Cake.Frosting.Tests/CakeHostTests.cs index dd268f38bb..164f031d3a 100644 --- a/src/Cake.Frosting.Tests/CakeHostTests.cs +++ b/src/Cake.Frosting.Tests/CakeHostTests.cs @@ -384,7 +384,7 @@ public void The_Version_Option_Should_Call_Version_Feature() Assert.Collection(fixture.Console.Messages, s => s.Equals("FakeVersion")); } - [Fact(Skip = "Excluded to see if the performance implication of this test is causing the integration tests to break on push to PR")] + [Fact] public void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() { // Given diff --git a/src/Cake.Tests/Unit/ProgramTests.cs b/src/Cake.Tests/Unit/ProgramTests.cs index b4bb534778..be696abb59 100644 --- a/src/Cake.Tests/Unit/ProgramTests.cs +++ b/src/Cake.Tests/Unit/ProgramTests.cs @@ -132,7 +132,7 @@ public async Task The_Info_Option_Should_Call_Info_Feature(params string[] args) feature.Received(1).Run(fixture.Console); } - [Fact(Skip = "Excluded to see if the performance implication of this test is causing the integration tests to break on push to PR")] + [Fact] public async void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() { // Given From 09cf0d215672f4d5cc7c246f3f427d362bc96e8a Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:41:20 +0000 Subject: [PATCH 11/11] Updated unit test to fix broken build after rebase --- src/Cake.Tests/Unit/ProgramTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Tests/Unit/ProgramTests.cs b/src/Cake.Tests/Unit/ProgramTests.cs index be696abb59..1490f46acf 100644 --- a/src/Cake.Tests/Unit/ProgramTests.cs +++ b/src/Cake.Tests/Unit/ProgramTests.cs @@ -145,7 +145,7 @@ public async void Should_Pass_Cake_Runner_Argument_And_Value_To_Build_Script() // Then feature.Received(1).Run( - Arg.Is(arguments => arguments.Parsed.Contains("version") && arguments.Parsed["version"].Contains("1.2.3")), + Arg.Is(arguments => arguments.HasArgument("version") && arguments.GetArguments("version").Contains("1.2.3")), Arg.Is(settings => settings.BuildHostKind == BuildHostKind.Build)); } }