Skip to content

Commit b089586

Browse files
authored
chore: Fix seed assembly project build failure (#10576)
* chore: fix failed build of seed assembly project * chore: add exitcode validation for snapshot tests
1 parent b0632f8 commit b089586

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

samples/seed/dotnet/assembly/BuildFromAssembly.csproj

-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,4 @@
99
<NoWarn>CS1591</NoWarn>
1010
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<PackageReference Include="Microsoft.SourceLink.GitHub">
14-
<PrivateAssets>all</PrivateAssets>
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
16-
</PackageReference>
17-
</ItemGroup>
18-
1912
</Project>

test/docfx.Snapshot.Tests/SamplesTest.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public async Task Seed()
5656

5757
using var process = Process.Start("dotnet", $"build \"{s_samplesDir}/seed/dotnet/assembly/BuildFromAssembly.csproj\"");
5858
await process.WaitForExitAsync();
59+
VerifyExitCode(process);
5960

6061
if (Debugger.IsAttached || IsWslRemoteTest())
6162
{
@@ -121,7 +122,8 @@ public async Task SeedMarkdown()
121122
var outputPath = nameof(SeedMarkdown);
122123
Clean(samplePath);
123124

124-
Program.Main(["metadata", $"{samplePath}/docfx.json", "--outputFormat", "markdown", "--output", outputPath]);
125+
var exitCode = Program.Main(["metadata", $"{samplePath}/docfx.json", "--outputFormat", "markdown", "--output", outputPath]);
126+
Assert.Equal(0, exitCode);
125127

126128
await VerifyDirectory(outputPath).AutoVerify(includeBuildServer: false);
127129
}
@@ -156,10 +158,12 @@ public Task Extensions()
156158
#if DEBUG
157159
using var process = Process.Start("dotnet", $"build \"{samplePath}/build\"");
158160
process.WaitForExit();
161+
VerifyExitCode(process);
159162
Assert.Equal(0, Exec("dotnet", "run --no-build --project build", workingDirectory: samplePath));
160163
#else
161164
using var process = Process.Start("dotnet", $"build -c Release \"{samplePath}/build\"");
162165
process.WaitForExit();
166+
VerifyExitCode(process);
163167
Assert.Equal(0, Exec("dotnet", "run --no-build -c Release --project build", workingDirectory: samplePath));
164168
#endif
165169

@@ -239,4 +243,19 @@ private static bool IsWslRemoteTest([CallerFilePath] string callerFilePath = "")
239243
return Environment.GetEnvironmentVariable("WSLENV") != null
240244
&& callerFilePath.Contains('\\', StringComparison.Ordinal); // Contains `\` when build on windows environment.
241245
}
246+
247+
private static void VerifyExitCode(Process process)
248+
{
249+
if (!process.HasExited)
250+
throw new InvalidOperationException("Process is not exited yet.");
251+
252+
// Gets exit code before closing process.
253+
var exitCode = process.ExitCode;
254+
255+
// Close process to flush stdout/stderr logs.
256+
process.Close();
257+
258+
// Assert exit code
259+
Assert.Equal(0, exitCode);
260+
}
242261
}

0 commit comments

Comments
 (0)