|
| 1 | +using System.Text.Json; |
| 2 | + |
| 3 | +namespace AutoSDK.IntegrationTests; |
| 4 | + |
| 5 | +public partial class CliTests |
| 6 | +{ |
| 7 | + [TestMethod] |
| 8 | + [DataRow(false)] |
| 9 | + [DataRow(true)] |
| 10 | + public async Task Trim_ReleasePackageGenerationDoesNotLeakIntoAnalysis(bool nativeAot) |
| 11 | + { |
| 12 | + const string spec = """ |
| 13 | + openapi: 3.0.3 |
| 14 | + info: |
| 15 | + title: Trim packaging policy |
| 16 | + version: 1.0.0 |
| 17 | + paths: {} |
| 18 | + components: |
| 19 | + schemas: |
| 20 | + Payload: |
| 21 | + type: object |
| 22 | + properties: |
| 23 | + text: |
| 24 | + type: string |
| 25 | + """; |
| 26 | + await GenerateFromContentAsync("trim-package-policy.yaml", spec, targetFramework: "net10.0", |
| 27 | + assertBuiltOutput: async directory => |
| 28 | + { |
| 29 | + await File.WriteAllTextAsync(Path.Combine(directory, "Directory.Build.props"), """ |
| 30 | + <Project><PropertyGroup Condition="'$(Configuration)' == 'Release'"> |
| 31 | + <GeneratePackageOnBuild>true</GeneratePackageOnBuild> |
| 32 | + </PropertyGroup></Project> |
| 33 | + """); |
| 34 | + var report = Path.Combine(directory, "trim-report.json"); |
| 35 | + var repository = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../../../../../..")); |
| 36 | + var arguments = new List<string> |
| 37 | + { |
| 38 | + "run", "--disable-build-servers", "--no-launch-profile", "--project", "src/libs/AutoSDK.CLI", |
| 39 | + "trim", Path.Combine(directory, "Oag.csproj"), "--report-json", report, |
| 40 | + }; |
| 41 | + if (nativeAot) arguments.Add("--aot"); |
| 42 | + var result = await RunDotnetAsync(repository, arguments.ToArray()); |
| 43 | + result.ExitCode.Should().Be(0, result.StandardOutput + result.StandardError); |
| 44 | + result.StandardOutput.Should().Contain("No trimming warnings found"); |
| 45 | + using var json = JsonDocument.Parse(await File.ReadAllTextAsync(report)); |
| 46 | + json.RootElement.GetProperty("schemaVersion").GetInt32().Should().Be(1); |
| 47 | + json.RootElement.GetProperty("appExecutableBytes").GetInt64().Should().BeGreaterThan(0); |
| 48 | + }); |
| 49 | + } |
| 50 | +} |
0 commit comments