-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
CleanTests.cs
112 lines (87 loc) · 4.31 KB
/
CleanTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Linq;
using Wasm.Build.NativeRebuild.Tests;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
#nullable enable
namespace Wasm.Build.Tests;
public class CleanTests : NativeRebuildTestsBase
{
public CleanTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
{
}
[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void Blazor_BuildThenClean_NativeRelinking(string config)
{
string id = Path.GetRandomFileName();
InitBlazorWasmProjectDir(id);
string projectFile = CreateBlazorWasmTemplateProject(id);
string extraProperties = @"<_WasmDevel>true</_WasmDevel>
<WasmBuildNative>true</WasmBuildNative>";
AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties);
BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked));
string relinkDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFrameworkForBlazor, "wasm", "for-build");
Assert.True(Directory.Exists(relinkDir), $"Could not find expected relink dir: {relinkDir}");
string logPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-clean.binlog");
new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("build", "-t:Clean", $"-p:Configuration={config}", $"-bl:{logPath}")
.EnsureSuccessful();
AssertEmptyOrNonExistentDirectory(relinkDir);
}
[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void Blazor_BuildNoNative_ThenBuildNative_ThenClean(string config)
=> Blazor_BuildNativeNonNative_ThenCleanTest(config, firstBuildNative: false);
[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void Blazor_BuildNative_ThenBuildNonNative_ThenClean(string config)
=> Blazor_BuildNativeNonNative_ThenCleanTest(config, firstBuildNative: true);
private void Blazor_BuildNativeNonNative_ThenCleanTest(string config, bool firstBuildNative)
{
string id = Path.GetRandomFileName();
InitBlazorWasmProjectDir(id);
string projectFile = CreateBlazorWasmTemplateProject(id);
string extraProperties = @"<_WasmDevel>true</_WasmDevel>";
AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties);
bool relink = firstBuildNative;
BlazorBuildInternal(id, config, publish: false,
extraArgs: relink ? "-p:WasmBuildNative=true" : string.Empty);
string relinkDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFrameworkForBlazor, "wasm", "for-build");
if (relink)
Assert.True(Directory.Exists(relinkDir), $"Could not find expected relink dir: {relinkDir}");
relink = !firstBuildNative;
BlazorBuildInternal(id, config, publish: false,
extraArgs: relink ? "-p:WasmBuildNative=true" : string.Empty);
if (relink)
Assert.True(Directory.Exists(relinkDir), $"Could not find expected relink dir: {relinkDir}");
string logPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-clean.binlog");
new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _projectDir!)
.ExecuteWithCapturedOutput("build", "-t:Clean", $"-p:Configuration={config}", $"-bl:{logPath}")
.EnsureSuccessful();
AssertEmptyOrNonExistentDirectory(relinkDir);
}
private void AssertEmptyOrNonExistentDirectory(string dirPath)
{
_testOutput.WriteLine($"dirPath: {dirPath}");
if (!Directory.Exists(dirPath))
return;
var files = Directory.GetFileSystemEntries(dirPath);
if (files.Length == 0)
return;
string found = string.Join(',', files.Select(p => Path.GetFileName(p)));
throw new XunitException($"Expected dir {dirPath} to be empty, but found: {found}");
}
}