Skip to content

Commit

Permalink
Adds an integration test for Cake Frosting (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecampidoglio committed Sep 30, 2024
1 parent a1effcc commit 037dd4d
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions integrationtests/frosting/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="4.0.0" />
</ItemGroup>
</Project>
63 changes: 63 additions & 0 deletions integrationtests/frosting/Program.cs
Original file line number Diff line number Diff line change
@@ -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<BuildContext>()
.Run(args);
}
}

public class BuildContext : FrostingContext
{
public BuildContext(ICakeContext context)
: base(context)
{
}
}

[TaskName("Successful-Task")]
public sealed class SuccessfulTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.Log.Information("✓ Passed");
}
}

[TaskName("Test-Verbosity")]
public sealed class TestVerbosity : FrostingTask<BuildContext>
{
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;

0 comments on commit 037dd4d

Please sign in to comment.