|
| 1 | +# This file contains test cases for https://pester.dev/ |
| 2 | +Set-StrictMode -Version Latest |
| 3 | +$ErrorActionPreference = 'Stop' |
| 4 | +. $PSScriptRoot/common.ps1 |
| 5 | + |
| 6 | +$IsARM64 = "Arm64".Equals([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()) |
| 7 | + |
| 8 | +# NOTE: These .NET versions are used to build a test app that consumes the Sentry |
| 9 | +# .NET SDK, and are not tied to the .NET version used to build the SDK itself. |
| 10 | +Describe 'MSBuild app' { |
| 11 | + BeforeDiscovery { |
| 12 | + $frameworks = @() |
| 13 | + |
| 14 | + # .NET 5.0 does not support ARM64 on macOS |
| 15 | + if (-not $IsMacOS -or -not $IsARM64) |
| 16 | + { |
| 17 | + $frameworks += @{ |
| 18 | + framework = 'net5.0' |
| 19 | + sdk = '5.0.400' |
| 20 | + # NuGet 5 does not support packageSourceMapping |
| 21 | + config = "$PSScriptRoot\nuget5.config" |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + $frameworks += @( |
| 26 | + @{ framework = 'net8.0'; sdk = '8.0.400' }, |
| 27 | + @{ framework = 'net9.0'; sdk = '9.0.300' } |
| 28 | + ) |
| 29 | + } |
| 30 | + |
| 31 | + Context '(<framework>)' -ForEach $frameworks { |
| 32 | + BeforeEach { |
| 33 | + Write-Host "::group::Create msbuild-app" |
| 34 | + dotnet new console --no-restore --output msbuild-app --framework $framework | ForEach-Object { Write-Host $_ } |
| 35 | + $LASTEXITCODE | Should -Be 0 |
| 36 | + AddPackageReference msbuild-app Sentry |
| 37 | + Push-Location msbuild-app |
| 38 | + @' |
| 39 | +using System.Runtime.InteropServices; |
| 40 | +using Sentry; |
| 41 | +
|
| 42 | +SentrySdk.Init(options => |
| 43 | +{ |
| 44 | + options.Dsn = args[0]; |
| 45 | + options.Debug = true; |
| 46 | +}); |
| 47 | +
|
| 48 | +SentrySdk.CaptureMessage($"Hello from MSBuild app"); |
| 49 | +'@ | Out-File Program.cs |
| 50 | + Write-Host "::endgroup::" |
| 51 | + |
| 52 | + Write-Host "::group::Setup .NET SDK" |
| 53 | + if (Test-Path variable:sdk) |
| 54 | + { |
| 55 | + # Pin to a specific SDK version to use MSBuild from that version |
| 56 | + @" |
| 57 | +{ |
| 58 | + "sdk": { |
| 59 | + "version": "$sdk", |
| 60 | + "rollForward": "latestFeature" |
| 61 | + } |
| 62 | +} |
| 63 | +"@ | Out-File global.json |
| 64 | + } |
| 65 | + Write-Host "Using .NET SDK: $(dotnet --version)" |
| 66 | + Write-Host "Using MSBuild version: $(dotnet msbuild -version)" |
| 67 | + Write-Host "::endgroup::" |
| 68 | + } |
| 69 | + |
| 70 | + AfterEach { |
| 71 | + Pop-Location |
| 72 | + Remove-Item msbuild-app -Recurse -Force -ErrorAction SilentlyContinue |
| 73 | + } |
| 74 | + |
| 75 | + It 'builds without warnings and is able to capture a message' { |
| 76 | + Write-Host "::group::Restore packages" |
| 77 | + if (!(Test-Path variable:config)) |
| 78 | + { |
| 79 | + $config = "$PSScriptRoot/nuget.config" |
| 80 | + } |
| 81 | + dotnet restore msbuild-app.csproj --configfile $config -p:CheckEolTargetFramework=false | ForEach-Object { Write-Host $_ } |
| 82 | + $LASTEXITCODE | Should -Be 0 |
| 83 | + Write-Host "::endgroup::" |
| 84 | + |
| 85 | + # TODO: pass -p:TreatWarningsAsErrors=true after #4554 is fixed |
| 86 | + dotnet msbuild msbuild-app.csproj -t:Build -p:Configuration=Release -p:TreatWarningsAsErrors=false | ForEach-Object { Write-Host $_ } |
| 87 | + $LASTEXITCODE | Should -Be 0 |
| 88 | + |
| 89 | + Write-Host "::group::Run msbuild-app" |
| 90 | + $result = Invoke-SentryServer { |
| 91 | + param([string]$url) |
| 92 | + $dsn = $url.Replace('http://', 'http://key@') + '/0' |
| 93 | + dotnet msbuild msbuild-app.csproj -t:Run -p:Configuration=Release -p:RunArguments=$dsn | ForEach-Object { Write-Host $_ } |
| 94 | + $LASTEXITCODE | Should -Be 0 |
| 95 | + } |
| 96 | + $result.HasErrors() | Should -BeFalse |
| 97 | + $result.Envelopes() | Should -AnyElementMatch "`"message`":`"Hello from MSBuild app`"" |
| 98 | + Write-Host "::endgroup::" |
| 99 | + } |
| 100 | + } |
| 101 | +} |
0 commit comments