diff --git a/.csharpierignore b/.csharpierignore index 13f737722..236410b22 100644 --- a/.csharpierignore +++ b/.csharpierignore @@ -1 +1,3 @@ -Uploads/ \ No newline at end of file +Uploads/ + +Tests/MsBuild/TestCases/ diff --git a/.github/workflows/validate_pull_request.yml b/.github/workflows/validate_pull_request.yml index 14fded337..777185432 100644 --- a/.github/workflows/validate_pull_request.yml +++ b/.github/workflows/validate_pull_request.yml @@ -27,11 +27,15 @@ jobs: dotnet tool restore dotnet csharpier . --check test_msbuild: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + runs-on: ${{ matrix.os }} name: Test CSharpier.MSBuild steps: - uses: actions/checkout@v2 - uses: actions/setup-dotnet@v3 - - run: | + - env: + GithubOS: ${{matrix.os}} + run: | pwsh ./Tests/MsBuild/Run.ps1 - diff --git a/Src/CSharpier.MsBuild/README.md b/Src/CSharpier.MsBuild/README.md index 8b0903a35..25e9d392f 100644 --- a/Src/CSharpier.MsBuild/README.md +++ b/Src/CSharpier.MsBuild/README.md @@ -4,7 +4,13 @@ One way to test the changes in the build/* files - Edit those files at `C:\Users\[Username]\.nuget\packages\csharpier.msbuild\[VersionNumber]\build` - Ensure you revert those files and make the same changes to the files here. -Another way -- the validate PR GH action does this, currently only uses the net8 sdk -- dotnet pack Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj -o nupkg /p:Version=0.0.1 -- docker build -f ./Tests/CSharpier.MsBuild.Test/Dockerfile . +Some automated tests exist +- the validate PR GH action runs these +- cd ./Tests/MsBuild +- ./Run.ps1 - some of these don't seem to work well locally + +Other things that would be really really nice to automate +- formats files in debug +- formats files if told to in release +- checks files if told to in debug +- log levels \ No newline at end of file diff --git a/Tests/MsBuild/.csharpierignore b/Tests/MsBuild/.csharpierignore new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/MsBuild/Directory.Build.props b/Tests/MsBuild/Directory.Build.props new file mode 100644 index 000000000..c416fb784 --- /dev/null +++ b/Tests/MsBuild/Directory.Build.props @@ -0,0 +1,5 @@ + + + false + + \ No newline at end of file diff --git a/Tests/MsBuild/Run.ps1 b/Tests/MsBuild/Run.ps1 index adb76860b..693c66fd6 100644 --- a/Tests/MsBuild/Run.ps1 +++ b/Tests/MsBuild/Run.ps1 @@ -16,12 +16,18 @@ if (Test-Path $basePath) { New-Item $basePath -ItemType Directory | Out-Null -$failureMessage = "" +$failureMessages = @() foreach ($scenario in $scenarios) { + # these fail on windows in GH and because they use docker for the scenarios we don't need to run them twice anyway + if ($env:GithubOS -eq "windows-latest") { + continue + } + Write-Host "::group::$($scenario.name)" $scenarioPath = Join-Path $basePath $scenario.name + Write-Host $scenarioPath New-Item $scenarioPath -ItemType Directory | Out-Null $dockerFile = Join-Path $scenarioPath "DockerFile" @@ -38,7 +44,7 @@ RUN dotnet build -c Release $csprojFile = Join-Path $scenarioPath "Project.csproj" $csharpierFrameworkVersion = "" - if ($null -ne $scenario.csharpier_frameworkVersion) { + if ([bool]($scenario.PSobject.Properties.name -match "csharpier_frameworkVersion")) { $csharpierFrameworkVersion = " $($scenario.csharpier_frameworkVersion) " @@ -61,14 +67,47 @@ RUN dotnet build -c Release docker build . -f $dockerFile if ($LASTEXITCODE -ne 0) { - $failureMessage += "::error::The scenario $($scenario.name) failed to build. See the logs above for details`n" + $failureMessages += "The scenario $($scenario.name) failed to build. See the logs above for details" } Write-Host "::endgroup::" } -if ($failureMessage -ne "") { - Write-Host $failureMessage + +Write-Host "::group::UnformattedFileCausesError" +$output = [TestHelper]::RunTestCase("UnformattedFileCausesError", $true) +Write-Host "::endgroup::" + +Write-Host "::group::FileThatCantCompileCausesOneError" +$output = [TestHelper]::RunTestCase("FileThatCantCompileCausesOneError", $true) +if (-not($output.Contains("1 Error(s)"))) { + $failureMessages += "The TestCase FileThatCantCompileCausesOneError did not contain the text '1 Error(s)1" +} + +Write-Host "::endgroup::" + +if ($failureMessages.Length -ne 0) { + foreach ($message in $failureMessages) { + Write-Host "::error::$message`n" + } exit 1 } +class TestHelper { + static [string] RunTestCase([string] $testCase, [bool] $expectErrorCode) { + $output = (& dotnet build -c Release ./TestCases/$($testCase)/Project.csproj) | Out-String + Write-Host $output + + $expectedExitCode = 0 + if ($expectErrorCode -eq $true) { + $expectedExitCode = 1 + } + + if ($LASTEXITCODE -ne $expectedExitCode) { + $failureMessages += "The TestCase $testCase did not return an exit code of $expectedExitCode" + } + + return $output + } +} + diff --git a/Tests/MsBuild/Scenarios.json b/Tests/MsBuild/Scenarios.json index a960fdf48..cb1868f20 100644 --- a/Tests/MsBuild/Scenarios.json +++ b/Tests/MsBuild/Scenarios.json @@ -1,21 +1,21 @@ [ { - "name": "sdk:8.0_netstandard2.0", + "name": "sdk-8.0_netstandard2.0", "sdk": "mcr.microsoft.com/dotnet/sdk:8.0", "targetFrameworks": "netstandard2.0" }, { - "name": "sdk:8.0_net8.0-windows", + "name": "sdk-8.0_net8.0-windows", "sdk": "mcr.microsoft.com/dotnet/sdk:8.0", "targetFrameworks": "net8.0-windows" }, { - "name": "sdk:8.0_net6.0;net7.07", + "name": "sdk-8.0_net6.0;net7.07", "sdk": "mcr.microsoft.com/dotnet/sdk:8.0", "targetFrameworks": "net6.0;net7.0" }, { - "name": "sdk:8.0_csharpier-net8.0", + "name": "sdk-8.0_csharpier-net8.0", "sdk": "mcr.microsoft.com/dotnet/sdk:8.0", "targetFrameworks": "netstandard2.0", "csharpier_frameworkVersion": "net8.0" diff --git a/Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/FileWithCompileError.cs b/Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/FileWithCompileError.cs new file mode 100644 index 000000000..47f23fa9d --- /dev/null +++ b/Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/FileWithCompileError.cs @@ -0,0 +1,4 @@ +namespace Net8; + +public class Class1 +{ diff --git a/Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/Project.csproj b/Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/Project.csproj new file mode 100644 index 000000000..f719d5263 --- /dev/null +++ b/Tests/MsBuild/TestCases/FileThatCantCompileCausesOneError/Project.csproj @@ -0,0 +1,12 @@ + + + net8.0 + false + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Tests/MsBuild/TestCases/UnformattedFileCausesError/Project.csproj b/Tests/MsBuild/TestCases/UnformattedFileCausesError/Project.csproj new file mode 100644 index 000000000..f719d5263 --- /dev/null +++ b/Tests/MsBuild/TestCases/UnformattedFileCausesError/Project.csproj @@ -0,0 +1,12 @@ + + + net8.0 + false + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Tests/MsBuild/TestCases/UnformattedFileCausesError/UnformattedFile.cs b/Tests/MsBuild/TestCases/UnformattedFileCausesError/UnformattedFile.cs new file mode 100644 index 000000000..bb5ff02b8 --- /dev/null +++ b/Tests/MsBuild/TestCases/UnformattedFileCausesError/UnformattedFile.cs @@ -0,0 +1,7 @@ +namespace Net8; + +public class Class1 +{ + + +} diff --git a/Tests/MsBuild/nuget.config b/Tests/MsBuild/nuget.config index 09743ecda..4fea3fab9 100644 --- a/Tests/MsBuild/nuget.config +++ b/Tests/MsBuild/nuget.config @@ -1,6 +1,16 @@ + + + + + + + + + + \ No newline at end of file