diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d50ad648..002beee4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Features - Added StartSpan and GetTransaction methods to the SentrySdk ([#4303](https://github.com/getsentry/sentry-dotnet/pull/4303)) +- `SentryOptions.Debug` now defaults to `true` for Debug build configurations ([#4330](https://github.com/getsentry/sentry-dotnet/pull/4330)) ### Fixes diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index 828eba441b..6eabc645bd 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -6,6 +6,12 @@ false + + + + false diff --git a/samples/Directory.Build.targets b/samples/Directory.Build.targets index e757f55436..0d63482a9e 100644 --- a/samples/Directory.Build.targets +++ b/samples/Directory.Build.targets @@ -7,6 +7,7 @@ + - @@ -42,7 +39,4 @@ true full - - - diff --git a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj index 25f4b66c46..0b0adbbe72 100644 --- a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj +++ b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj @@ -44,11 +44,5 @@ - - - - diff --git a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj index e48c894e34..626f4ee4f5 100644 --- a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj +++ b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj @@ -44,11 +44,5 @@ - - - - diff --git a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj index f924e8f7c0..b84f8b1175 100644 --- a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj +++ b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj @@ -114,7 +114,4 @@ - - - diff --git a/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs b/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs index 7110b4f3a7..763577c53b 100644 --- a/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs +++ b/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs @@ -4,7 +4,6 @@ namespace Sentry.SourceGenerators; - /// /// Generates the necessary msbuild variables /// diff --git a/src/Sentry/CompilerServices/BuildProperties.cs b/src/Sentry/CompilerServices/BuildProperties.cs index d4cd7db07e..6d70756527 100644 --- a/src/Sentry/CompilerServices/BuildProperties.cs +++ b/src/Sentry/CompilerServices/BuildProperties.cs @@ -23,4 +23,27 @@ public static void Initialize(Dictionary properties) { Values ??= properties.AsReadOnly(); } + + /// + /// Tries to retrieve a boolean value from the build properties. + /// + /// The item key + /// The value (if any) + /// True if the key was found, false otherwise + public static bool TryGetBoolean(string key, out bool value) + { + value = false; + if (!(Values?.TryGetValue(key, out var foundValue) ?? false)) + { + return false; + } + + if (!bool.TryParse(foundValue, out var result)) + { + return false; + } + + value = result; + return true; + } } diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index a10449e6fe..e20c7288de 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -13,16 +13,15 @@ static AotHelper() IsTrimmed = CheckIsTrimmed(); } - [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)] private static bool CheckIsTrimmed() { - if (TryGetBoolean("publishtrimmed", out var trimmed)) + if (BuildProperties.TryGetBoolean("PublishTrimmed", out var trimmed)) { return trimmed; } - if (TryGetBoolean("publishaot", out var aot)) + if (BuildProperties.TryGetBoolean("PublishAot", out var aot)) { return aot; } @@ -31,19 +30,4 @@ private static bool CheckIsTrimmed() var stackTrace = new StackTrace(false); return stackTrace.GetFrame(0)?.GetMethod() is null; } - - private static bool TryGetBoolean(string key, out bool value) - { - value = false; - if (BuildProperties.Values?.TryGetValue(key, out var aotValue) ?? false) - { - if (bool.TryParse(aotValue, out var result)) - { - value = result; - return true; - } - } - - return false; - } } diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index ceab5113bc..45de425643 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -1,3 +1,4 @@ +using Sentry.CompilerServices; using Sentry.Extensibility; using Sentry.Http; using Sentry.Infrastructure; @@ -1324,6 +1325,18 @@ public SentryOptions() ); NetworkStatusListener = new PollingNetworkStatusListener(this); + +#if NET8_0_OR_GREATER + // If source generators are available, we can detect the user's build configuration and use this + // to infer whether to enable debug mode by default. + // See: https://develop.sentry.dev/sdk/expected-features/#auto-debug-mode + string? buildConfig = null; + BuildProperties.Values?.TryGetValue("Configuration", out buildConfig); + if (buildConfig == "Debug") + { + Debug = true; + } +#endif } /// diff --git a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt index 94298c45c3..955ba95f9f 100644 --- a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt +++ b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt @@ -1,23 +1,4 @@ -{ - Generator: {}, - GeneratedSources: [ - { - SyntaxTree: { - FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, - Encoding: utf-8, - Length: 639, - HasCompilationUnitRoot: true, - Options: { - LanguageVersion: CSharp12, - Language: C#, - DocumentationMode: Parse, - Errors: null - } - }, - SourceText: { - Encoding: utf-8, - Source: -// +// // Code generated by Sentry Source Generators // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -39,330 +20,3 @@ public static class BuildVariableInitializer } } #endif -, - Length: 639, - ChecksumAlgorithm: Sha1, - CanBeEmbedded: true, - Container: {}, - Lines: [ - { - End: 19, - EndIncludingLineBreak: 20, - Span: { - Length: 19 - }, - SpanIncludingLineBreak: { - Length: 20 - } - }, - { - LineNumber: 1, - Start: 20, - End: 65, - EndIncludingLineBreak: 66, - Span: { - Start: 20, - Length: 45 - }, - SpanIncludingLineBreak: { - Start: 20, - Length: 46 - } - }, - { - LineNumber: 2, - Start: 66, - End: 137, - EndIncludingLineBreak: 138, - Span: { - Start: 66, - Length: 71 - }, - SpanIncludingLineBreak: { - Start: 66, - Length: 72 - } - }, - { - LineNumber: 3, - Start: 138, - End: 153, - EndIncludingLineBreak: 154, - Span: { - Start: 138, - Length: 15 - }, - SpanIncludingLineBreak: { - Start: 138, - Length: 16 - } - }, - { - LineNumber: 4, - Start: 154, - End: 174, - EndIncludingLineBreak: 175, - Span: { - Start: 154, - Length: 20 - }, - SpanIncludingLineBreak: { - Start: 154, - Length: 21 - } - }, - { - LineNumber: 5, - Start: 175, - End: 175, - EndIncludingLineBreak: 176, - Span: { - Start: 175 - }, - SpanIncludingLineBreak: { - Start: 175, - Length: 1 - } - }, - { - LineNumber: 6, - Start: 176, - End: 197, - EndIncludingLineBreak: 198, - Span: { - Start: 176, - Length: 21 - }, - SpanIncludingLineBreak: { - Start: 176, - Length: 22 - } - }, - { - LineNumber: 7, - Start: 198, - End: 215, - EndIncludingLineBreak: 216, - Span: { - Start: 198, - Length: 17 - }, - SpanIncludingLineBreak: { - Start: 198, - Length: 18 - } - }, - { - LineNumber: 8, - Start: 216, - End: 216, - EndIncludingLineBreak: 217, - Span: { - Start: 216 - }, - SpanIncludingLineBreak: { - Start: 216, - Length: 1 - } - }, - { - LineNumber: 9, - Start: 217, - End: 276, - EndIncludingLineBreak: 277, - Span: { - Start: 217, - Length: 59 - }, - SpanIncludingLineBreak: { - Start: 217, - Length: 60 - } - }, - { - LineNumber: 10, - Start: 277, - End: 321, - EndIncludingLineBreak: 322, - Span: { - Start: 277, - Length: 44 - }, - SpanIncludingLineBreak: { - Start: 277, - Length: 45 - } - }, - { - LineNumber: 11, - Start: 322, - End: 323, - EndIncludingLineBreak: 324, - Span: { - Start: 322, - Length: 1 - }, - SpanIncludingLineBreak: { - Start: 322, - Length: 2 - } - }, - { - LineNumber: 12, - Start: 324, - End: 387, - EndIncludingLineBreak: 388, - Span: { - Start: 324, - Length: 63 - }, - SpanIncludingLineBreak: { - Start: 324, - Length: 64 - } - }, - { - LineNumber: 13, - Start: 388, - End: 423, - EndIncludingLineBreak: 424, - Span: { - Start: 388, - Length: 35 - }, - SpanIncludingLineBreak: { - Start: 388, - Length: 36 - } - }, - { - LineNumber: 14, - Start: 424, - End: 429, - EndIncludingLineBreak: 430, - Span: { - Start: 424, - Length: 5 - }, - SpanIncludingLineBreak: { - Start: 424, - Length: 6 - } - }, - { - LineNumber: 15, - Start: 430, - End: 564, - EndIncludingLineBreak: 565, - Span: { - Start: 430, - Length: 134 - }, - SpanIncludingLineBreak: { - Start: 430, - Length: 135 - } - }, - { - LineNumber: 16, - Start: 565, - End: 594, - EndIncludingLineBreak: 595, - Span: { - Start: 565, - Length: 29 - }, - SpanIncludingLineBreak: { - Start: 565, - Length: 30 - } - }, - { - LineNumber: 17, - Start: 595, - End: 620, - EndIncludingLineBreak: 621, - Span: { - Start: 595, - Length: 25 - }, - SpanIncludingLineBreak: { - Start: 595, - Length: 26 - } - }, - { - LineNumber: 18, - Start: 621, - End: 626, - EndIncludingLineBreak: 627, - Span: { - Start: 621, - Length: 5 - }, - SpanIncludingLineBreak: { - Start: 621, - Length: 6 - } - }, - { - LineNumber: 19, - Start: 627, - End: 629, - EndIncludingLineBreak: 630, - Span: { - Start: 627, - Length: 2 - }, - SpanIncludingLineBreak: { - Start: 627, - Length: 3 - } - }, - { - LineNumber: 20, - Start: 630, - End: 631, - EndIncludingLineBreak: 632, - Span: { - Start: 630, - Length: 1 - }, - SpanIncludingLineBreak: { - Start: 630, - Length: 2 - } - }, - { - LineNumber: 21, - Start: 632, - End: 638, - EndIncludingLineBreak: 639, - Span: { - Start: 632, - Length: 6 - }, - SpanIncludingLineBreak: { - Start: 632, - Length: 7 - } - }, - { - LineNumber: 22, - Start: 639, - End: 639, - EndIncludingLineBreak: 639, - Span: { - Start: 639 - }, - SpanIncludingLineBreak: { - Start: 639 - } - } - ] - }, - HintName: __BuildProperties.g.cs - } - ], - Diagnostics: null -} \ No newline at end of file diff --git a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt index 37b44b9ecd..d3964a67a1 100644 --- a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt +++ b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt @@ -1,23 +1,4 @@ -{ - Generator: {}, - GeneratedSources: [ - { - SyntaxTree: { - FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, - Encoding: utf-8, - Length: 636, - HasCompilationUnitRoot: true, - Options: { - LanguageVersion: CSharp12, - Language: C#, - DocumentationMode: Parse, - Errors: null - } - }, - SourceText: { - Encoding: utf-8, - Source: -// +// // Code generated by Sentry Source Generators // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -35,334 +16,8 @@ public static class BuildVariableInitializer global::Sentry.CompilerServices.BuildProperties.Initialize(new global::System.Collections.Generic.Dictionary { {"PublishAot", "true"}, {"OutputType", "exe"}, + {"Configuration", "Release"}, }); } } #endif -, - Length: 636, - ChecksumAlgorithm: Sha1, - CanBeEmbedded: true, - Container: {}, - Lines: [ - { - End: 19, - EndIncludingLineBreak: 20, - Span: { - Length: 19 - }, - SpanIncludingLineBreak: { - Length: 20 - } - }, - { - LineNumber: 1, - Start: 20, - End: 65, - EndIncludingLineBreak: 66, - Span: { - Start: 20, - Length: 45 - }, - SpanIncludingLineBreak: { - Start: 20, - Length: 46 - } - }, - { - LineNumber: 2, - Start: 66, - End: 137, - EndIncludingLineBreak: 138, - Span: { - Start: 66, - Length: 71 - }, - SpanIncludingLineBreak: { - Start: 66, - Length: 72 - } - }, - { - LineNumber: 3, - Start: 138, - End: 153, - EndIncludingLineBreak: 154, - Span: { - Start: 138, - Length: 15 - }, - SpanIncludingLineBreak: { - Start: 138, - Length: 16 - } - }, - { - LineNumber: 4, - Start: 154, - End: 174, - EndIncludingLineBreak: 175, - Span: { - Start: 154, - Length: 20 - }, - SpanIncludingLineBreak: { - Start: 154, - Length: 21 - } - }, - { - LineNumber: 5, - Start: 175, - End: 175, - EndIncludingLineBreak: 176, - Span: { - Start: 175 - }, - SpanIncludingLineBreak: { - Start: 175, - Length: 1 - } - }, - { - LineNumber: 6, - Start: 176, - End: 197, - EndIncludingLineBreak: 198, - Span: { - Start: 176, - Length: 21 - }, - SpanIncludingLineBreak: { - Start: 176, - Length: 22 - } - }, - { - LineNumber: 7, - Start: 198, - End: 215, - EndIncludingLineBreak: 216, - Span: { - Start: 198, - Length: 17 - }, - SpanIncludingLineBreak: { - Start: 198, - Length: 18 - } - }, - { - LineNumber: 8, - Start: 216, - End: 216, - EndIncludingLineBreak: 217, - Span: { - Start: 216 - }, - SpanIncludingLineBreak: { - Start: 216, - Length: 1 - } - }, - { - LineNumber: 9, - Start: 217, - End: 276, - EndIncludingLineBreak: 277, - Span: { - Start: 217, - Length: 59 - }, - SpanIncludingLineBreak: { - Start: 217, - Length: 60 - } - }, - { - LineNumber: 10, - Start: 277, - End: 321, - EndIncludingLineBreak: 322, - Span: { - Start: 277, - Length: 44 - }, - SpanIncludingLineBreak: { - Start: 277, - Length: 45 - } - }, - { - LineNumber: 11, - Start: 322, - End: 323, - EndIncludingLineBreak: 324, - Span: { - Start: 322, - Length: 1 - }, - SpanIncludingLineBreak: { - Start: 322, - Length: 2 - } - }, - { - LineNumber: 12, - Start: 324, - End: 387, - EndIncludingLineBreak: 388, - Span: { - Start: 324, - Length: 63 - }, - SpanIncludingLineBreak: { - Start: 324, - Length: 64 - } - }, - { - LineNumber: 13, - Start: 388, - End: 423, - EndIncludingLineBreak: 424, - Span: { - Start: 388, - Length: 35 - }, - SpanIncludingLineBreak: { - Start: 388, - Length: 36 - } - }, - { - LineNumber: 14, - Start: 424, - End: 429, - EndIncludingLineBreak: 430, - Span: { - Start: 424, - Length: 5 - }, - SpanIncludingLineBreak: { - Start: 424, - Length: 6 - } - }, - { - LineNumber: 15, - Start: 430, - End: 564, - EndIncludingLineBreak: 565, - Span: { - Start: 430, - Length: 134 - }, - SpanIncludingLineBreak: { - Start: 430, - Length: 135 - } - }, - { - LineNumber: 16, - Start: 565, - End: 591, - EndIncludingLineBreak: 592, - Span: { - Start: 565, - Length: 26 - }, - SpanIncludingLineBreak: { - Start: 565, - Length: 27 - } - }, - { - LineNumber: 17, - Start: 592, - End: 617, - EndIncludingLineBreak: 618, - Span: { - Start: 592, - Length: 25 - }, - SpanIncludingLineBreak: { - Start: 592, - Length: 26 - } - }, - { - LineNumber: 18, - Start: 618, - End: 623, - EndIncludingLineBreak: 624, - Span: { - Start: 618, - Length: 5 - }, - SpanIncludingLineBreak: { - Start: 618, - Length: 6 - } - }, - { - LineNumber: 19, - Start: 624, - End: 626, - EndIncludingLineBreak: 627, - Span: { - Start: 624, - Length: 2 - }, - SpanIncludingLineBreak: { - Start: 624, - Length: 3 - } - }, - { - LineNumber: 20, - Start: 627, - End: 628, - EndIncludingLineBreak: 629, - Span: { - Start: 627, - Length: 1 - }, - SpanIncludingLineBreak: { - Start: 627, - Length: 2 - } - }, - { - LineNumber: 21, - Start: 629, - End: 635, - EndIncludingLineBreak: 636, - Span: { - Start: 629, - Length: 6 - }, - SpanIncludingLineBreak: { - Start: 629, - Length: 7 - } - }, - { - LineNumber: 22, - Start: 636, - End: 636, - EndIncludingLineBreak: 636, - Span: { - Start: 636 - }, - SpanIncludingLineBreak: { - Start: 636 - } - } - ] - }, - HintName: __BuildProperties.g.cs - } - ], - Diagnostics: null -} \ No newline at end of file diff --git a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt index ff9d84c52d..5d688fddea 100644 --- a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt +++ b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt @@ -1,23 +1,4 @@ -{ - Generator: {}, - GeneratedSources: [ - { - SyntaxTree: { - FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, - Encoding: utf-8, - Length: 637, - HasCompilationUnitRoot: true, - Options: { - LanguageVersion: CSharp12, - Language: C#, - DocumentationMode: Parse, - Errors: null - } - }, - SourceText: { - Encoding: utf-8, - Source: -// +// // Code generated by Sentry Source Generators // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -39,330 +20,3 @@ public static class BuildVariableInitializer } } #endif -, - Length: 637, - ChecksumAlgorithm: Sha1, - CanBeEmbedded: true, - Container: {}, - Lines: [ - { - End: 19, - EndIncludingLineBreak: 20, - Span: { - Length: 19 - }, - SpanIncludingLineBreak: { - Length: 20 - } - }, - { - LineNumber: 1, - Start: 20, - End: 65, - EndIncludingLineBreak: 66, - Span: { - Start: 20, - Length: 45 - }, - SpanIncludingLineBreak: { - Start: 20, - Length: 46 - } - }, - { - LineNumber: 2, - Start: 66, - End: 137, - EndIncludingLineBreak: 138, - Span: { - Start: 66, - Length: 71 - }, - SpanIncludingLineBreak: { - Start: 66, - Length: 72 - } - }, - { - LineNumber: 3, - Start: 138, - End: 153, - EndIncludingLineBreak: 154, - Span: { - Start: 138, - Length: 15 - }, - SpanIncludingLineBreak: { - Start: 138, - Length: 16 - } - }, - { - LineNumber: 4, - Start: 154, - End: 174, - EndIncludingLineBreak: 175, - Span: { - Start: 154, - Length: 20 - }, - SpanIncludingLineBreak: { - Start: 154, - Length: 21 - } - }, - { - LineNumber: 5, - Start: 175, - End: 175, - EndIncludingLineBreak: 176, - Span: { - Start: 175 - }, - SpanIncludingLineBreak: { - Start: 175, - Length: 1 - } - }, - { - LineNumber: 6, - Start: 176, - End: 197, - EndIncludingLineBreak: 198, - Span: { - Start: 176, - Length: 21 - }, - SpanIncludingLineBreak: { - Start: 176, - Length: 22 - } - }, - { - LineNumber: 7, - Start: 198, - End: 215, - EndIncludingLineBreak: 216, - Span: { - Start: 198, - Length: 17 - }, - SpanIncludingLineBreak: { - Start: 198, - Length: 18 - } - }, - { - LineNumber: 8, - Start: 216, - End: 216, - EndIncludingLineBreak: 217, - Span: { - Start: 216 - }, - SpanIncludingLineBreak: { - Start: 216, - Length: 1 - } - }, - { - LineNumber: 9, - Start: 217, - End: 276, - EndIncludingLineBreak: 277, - Span: { - Start: 217, - Length: 59 - }, - SpanIncludingLineBreak: { - Start: 217, - Length: 60 - } - }, - { - LineNumber: 10, - Start: 277, - End: 321, - EndIncludingLineBreak: 322, - Span: { - Start: 277, - Length: 44 - }, - SpanIncludingLineBreak: { - Start: 277, - Length: 45 - } - }, - { - LineNumber: 11, - Start: 322, - End: 323, - EndIncludingLineBreak: 324, - Span: { - Start: 322, - Length: 1 - }, - SpanIncludingLineBreak: { - Start: 322, - Length: 2 - } - }, - { - LineNumber: 12, - Start: 324, - End: 387, - EndIncludingLineBreak: 388, - Span: { - Start: 324, - Length: 63 - }, - SpanIncludingLineBreak: { - Start: 324, - Length: 64 - } - }, - { - LineNumber: 13, - Start: 388, - End: 423, - EndIncludingLineBreak: 424, - Span: { - Start: 388, - Length: 35 - }, - SpanIncludingLineBreak: { - Start: 388, - Length: 36 - } - }, - { - LineNumber: 14, - Start: 424, - End: 429, - EndIncludingLineBreak: 430, - Span: { - Start: 424, - Length: 5 - }, - SpanIncludingLineBreak: { - Start: 424, - Length: 6 - } - }, - { - LineNumber: 15, - Start: 430, - End: 564, - EndIncludingLineBreak: 565, - Span: { - Start: 430, - Length: 134 - }, - SpanIncludingLineBreak: { - Start: 430, - Length: 135 - } - }, - { - LineNumber: 16, - Start: 565, - End: 592, - EndIncludingLineBreak: 593, - Span: { - Start: 565, - Length: 27 - }, - SpanIncludingLineBreak: { - Start: 565, - Length: 28 - } - }, - { - LineNumber: 17, - Start: 593, - End: 618, - EndIncludingLineBreak: 619, - Span: { - Start: 593, - Length: 25 - }, - SpanIncludingLineBreak: { - Start: 593, - Length: 26 - } - }, - { - LineNumber: 18, - Start: 619, - End: 624, - EndIncludingLineBreak: 625, - Span: { - Start: 619, - Length: 5 - }, - SpanIncludingLineBreak: { - Start: 619, - Length: 6 - } - }, - { - LineNumber: 19, - Start: 625, - End: 627, - EndIncludingLineBreak: 628, - Span: { - Start: 625, - Length: 2 - }, - SpanIncludingLineBreak: { - Start: 625, - Length: 3 - } - }, - { - LineNumber: 20, - Start: 628, - End: 629, - EndIncludingLineBreak: 630, - Span: { - Start: 628, - Length: 1 - }, - SpanIncludingLineBreak: { - Start: 628, - Length: 2 - } - }, - { - LineNumber: 21, - Start: 630, - End: 636, - EndIncludingLineBreak: 637, - Span: { - Start: 630, - Length: 6 - }, - SpanIncludingLineBreak: { - Start: 630, - Length: 7 - } - }, - { - LineNumber: 22, - Start: 637, - End: 637, - EndIncludingLineBreak: 637, - Span: { - Start: 637 - }, - SpanIncludingLineBreak: { - Start: 637 - } - } - ] - }, - HintName: __BuildProperties.g.cs - } - ], - Diagnostics: null -} \ No newline at end of file diff --git a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs index b952748dd5..0eb5f023ca 100644 --- a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs @@ -5,7 +5,6 @@ namespace Sentry.SourceGenerators.Tests; - public class BuildPropertySourceGeneratorTests { [SkippableFact] @@ -18,10 +17,10 @@ public Task RunResult_Success() result.Exception.Should().BeNull(); result.GeneratedSources.Length.Should().Be(1); result.GeneratedSources.First().HintName.Should().Be("__BuildProperties.g.cs"); - return Verify(result); + var source = result.GeneratedSources.First().SourceText.ToString(); + return Verify(source); } - [SkippableFact] public Task RunResult_BadStrings() { @@ -33,24 +32,24 @@ public Task RunResult_BadStrings() result.Exception.Should().BeNull(); result.GeneratedSources.Length.Should().Be(1); result.GeneratedSources.First().HintName.Should().Be("__BuildProperties.g.cs"); - return Verify(result); + var source = result.GeneratedSources.First().SourceText.ToString(); + return Verify(source); } - [SkippableFact] public Task RunResult_Publish_AotTrue() { Skip.If(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); - var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "true"), ("OutputType", "exe")); + var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "true"), ("OutputType", "exe"), ("Configuration", "Release")); var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); result.GeneratedSources.Length.Should().Be(1); result.GeneratedSources.First().HintName.Should().Be("__BuildProperties.g.cs"); - return Verify(result); + var source = result.GeneratedSources.First().SourceText.ToString(); + return Verify(source); } - [SkippableTheory] [InlineData("no", true)] [InlineData("true", false)] @@ -67,7 +66,6 @@ public void RunResult_SentryDisableSourceGenerator_Values(string value, bool sou generated.Should().Be(sourceGenExpected); } - [SkippableFact] public Task RunResult_Expect_None() { @@ -81,7 +79,6 @@ public Task RunResult_Expect_None() return Verify(result); } - private static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEnumerable<(string Key, string Value)> buildProperties) { var metadataReference = MetadataReference.CreateFromFile(metadataAssembly.Location); diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt index 3bbe328943..7c8784c948 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -1304,6 +1304,7 @@ namespace Sentry.CompilerServices { public static System.Collections.Generic.IReadOnlyDictionary? Values { get; } public static void Initialize(System.Collections.Generic.Dictionary properties) { } + public static bool TryGetBoolean(string key, out bool value) { } } } namespace Sentry.Extensibility diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt index 3bbe328943..7c8784c948 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -1304,6 +1304,7 @@ namespace Sentry.CompilerServices { public static System.Collections.Generic.IReadOnlyDictionary? Values { get; } public static void Initialize(System.Collections.Generic.Dictionary properties) { } + public static bool TryGetBoolean(string key, out bool value) { } } } namespace Sentry.Extensibility diff --git a/test/Sentry.Tests/Sentry.Tests.csproj b/test/Sentry.Tests/Sentry.Tests.csproj index 3f00bc5a9f..5f4fb7b910 100644 --- a/test/Sentry.Tests/Sentry.Tests.csproj +++ b/test/Sentry.Tests/Sentry.Tests.csproj @@ -44,4 +44,12 @@ + + + + + + diff --git a/test/Sentry.Tests/SentryOptionsTests.cs b/test/Sentry.Tests/SentryOptionsTests.cs index 7d53c1c9b5..a8442c8375 100644 --- a/test/Sentry.Tests/SentryOptionsTests.cs +++ b/test/Sentry.Tests/SentryOptionsTests.cs @@ -675,4 +675,17 @@ public void CachesInstallationId() installationId2.Should().Be(installationId1); logger.Received(0).Log(SentryLevel.Debug, "Resolved installation ID '{0}'.", null, Arg.Any()); } + +#if NET8_0_OR_GREATER + [Fact] + public void Debug_AutoDebug() + { + var sut = new SentryOptions(); +#if DEBUG + Assert.True(sut.Debug); +#else + Assert.False(sut.Debug); +#endif + } +#endif }