From bb07c60c5b7843eb7a724ada17da272b19b6bec4 Mon Sep 17 00:00:00 2001 From: Enrico Campidoglio Date: Tue, 2 Apr 2024 09:51:39 +0200 Subject: [PATCH] Adds an integration test for Cake Frosting (WIP) --- .github/workflows/test.yml | 36 +++++++++++++++ integrationtests/frosting/Build.csproj | 10 ++++ integrationtests/frosting/Program.cs | 63 ++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 integrationtests/frosting/Build.csproj create mode 100644 integrationtests/frosting/Program.cs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61328cd..b00ee94 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -153,3 +153,39 @@ jobs: string-parameter: 'value' numeric-parameter: 3 boolean-parameter: true + test-with-frosting: + name: Test with Cake Frosting + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + env: + csproj-directory: integrationtests/frosting + steps: + - name: Get the sources + uses: actions/checkout@v1 + - name: Install Node 20 + uses: actions/setup-node@v4 + with: + node-version: '20' + - name: Install the .NET 8 SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + - name: Run a specific Cake Frosting project + uses: ./ + with: + csproj-path: ${{ env.csproj-directory}}/Build.csproj + - name: Run a specific Cake Frosting task + uses: ./ + with: + csproj-path: ${{ env.csproj-directory}}/Build.csproj + target: Successful-Task + - name: Run with a specific verbosity level + uses: ./ + env: + EXPECTED_VERBOSITY: Diagnostic + with: + verbosity: Diagnostic + csproj-path: ${{ env.csproj-directory}}/Build.csproj + target: Test-Verbosity diff --git a/integrationtests/frosting/Build.csproj b/integrationtests/frosting/Build.csproj new file mode 100644 index 0000000..8f8fbc7 --- /dev/null +++ b/integrationtests/frosting/Build.csproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + $(MSBuildProjectDirectory) + + + + + diff --git a/integrationtests/frosting/Program.cs b/integrationtests/frosting/Program.cs new file mode 100644 index 0000000..e2793e4 --- /dev/null +++ b/integrationtests/frosting/Program.cs @@ -0,0 +1,63 @@ +using System; +using Cake.Common; +using Cake.Core; +using Cake.Core.Diagnostics; +using Cake.Frosting; + +public static class Program +{ + public static int Main(string[] args) + { + return new CakeHost() + .UseContext() + .Run(args); + } +} + +public class BuildContext : FrostingContext +{ + public BuildContext(ICakeContext context) + : base(context) + { + } +} + +[TaskName("Successful-Task")] +public sealed class SuccessfulTask : FrostingTask +{ + public override void Run(BuildContext context) + { + context.Log.Information("✓ Passed"); + } +} + +[TaskName("Test-Verbosity")] +public sealed class TestVerbosity : FrostingTask +{ + public override void Run(BuildContext context) + { + var hasExpectedVerbosity = Enum.TryParse( + context.EnvironmentVariable("EXPECTED_VERBOSITY"), + ignoreCase: true, + out Verbosity expectedVerbosity); + + if (!hasExpectedVerbosity) + { + throw new Exception( + "✕ The EXPECTED_VERBOSITY environment variable is not set or it doesn't contain a verbosity level"); + } + + var actualVerbosity = context.Log.Verbosity; + + if (expectedVerbosity != actualVerbosity) + { + throw new Exception($"✕ Expected verbosity {expectedVerbosity} but got {actualVerbosity}"); + } + + context.Log.Information("✓ Passed"); + } +} + +[TaskName("Default")] +[IsDependentOn(typeof(SuccessfulTask))] +public class DefaultTask : FrostingTask;