Skip to content

Commit

Permalink
Add a test for configure runtime using msbuild properties
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyang-mono committed Aug 4, 2021
1 parent f0b1fde commit e284581
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
bool hasIcudt = true,
bool useCache = true,
bool expectSuccess = true,
bool createProject = true)
bool createProject = true,
bool createCsProject = true)
{
if (useCache && _buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product))
{
Expand All @@ -291,7 +292,10 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
InitProjectDir(_projectDir);
initProject?.Invoke();

File.WriteAllText(Path.Combine(_projectDir, $"{buildArgs.ProjectName}.csproj"), buildArgs.ProjectFileContents);
if (createCsProject)
{
File.WriteAllText(Path.Combine(_projectDir, $"{buildArgs.ProjectName}.csproj"), buildArgs.ProjectFileContents);
}
File.Copy(Path.Combine(AppContext.BaseDirectory, "runtime-test.js"), Path.Combine(_projectDir, "runtime-test.js"));
}
else if (_projectDir is null)
Expand Down
56 changes: 51 additions & 5 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/WasmBuildAppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ public void PropertiesFromRuntimeConfigJson(BuildArgs buildArgs, RunHost host, s

string runtimeConfigTemplateJson = @"
{
""configProperties"": {
""abc"": ""4"",
""test_runtimeconfig_json"": ""25""
}
}";
""configProperties"": {
""abc"": ""4"",
""test_runtimeconfig_json"": ""25""
}
}";

BuildProject(buildArgs,
initProject: () =>
Expand All @@ -122,6 +122,52 @@ public void PropertiesFromRuntimeConfigJson(BuildArgs buildArgs, RunHost host, s
test: output => Assert.Contains("test_runtimeconfig_json: 25", output), host: host, id: id);
}

[Theory]
[BuildAndRun]
public void PropertiesFromCsproj(BuildArgs buildArgs, RunHost host, string id)
{
buildArgs = buildArgs with { ProjectName = $"runtime_config_csproj_{buildArgs.Config}_{buildArgs.AOT}" };
buildArgs = ExpandBuildArgs(buildArgs);

string programText = @"
using System;
using System.Runtime.CompilerServices;
var config = AppContext.GetData(""System.Threading.ThreadPool.MaxThreads"");
Console.WriteLine ($""System.Threading.ThreadPool.MaxThreads: {(string)config}"");
return 42;
";

string csprojFile = @"
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
<WasmMainJSPath>runtime-test.js</WasmMainJSPath>
<ThreadPoolMaxThreads>20</ThreadPoolMaxThreads>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
</Project>
";

BuildProject(buildArgs,
initProject: () =>
{
File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programText);
File.WriteAllText(Path.Combine(_projectDir!, $"{buildArgs.ProjectName}.csproj"), csprojFile);
},
id: id,
dotnetWasmFromRuntimePack: !(buildArgs.AOT || buildArgs.Config == "Release"),
createCsProject: false);

RunAndTestWasmApp(buildArgs, expectedExitCode: 42,
test: output => Assert.Contains("System.Threading.ThreadPool.MaxThreads: 20", output), host: host, id: id);
}

void TestMain(string projectName,
string programText,
BuildArgs buildArgs,
Expand Down

0 comments on commit e284581

Please sign in to comment.