Skip to content

Commit 089797c

Browse files
Copilotagocke
andcommitted
Add Native AOT test with space in path
Add a new test case that verifies Native AOT publishing works correctly when the project path contains a space. This test: - Creates a test project with an identifier containing a space ("with space") - Publishes the project with PublishAot=true - Verifies the path actually contains a space - Confirms the native executable is created and runs successfully Co-authored-by: agocke <[email protected]>
1 parent 0ca3157 commit 089797c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,62 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string
7777
.And.HaveStdOutContaining("Hello World");
7878
}
7979

80+
[RequiresMSBuildVersionTheory("17.12.0", Skip = "https://github.com/dotnet/sdk/issues/46006")]
81+
[MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))]
82+
public void NativeAot_app_publishes_with_space_in_path(string targetFramework)
83+
{
84+
if (targetFramework == "net7.0" && RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
85+
{
86+
// 7.0 is not supported on Mac
87+
return;
88+
}
89+
90+
var projectName = "HelloWorldNativeAotApp";
91+
92+
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);
93+
testProject.RecordProperties("NETCoreSdkPortableRuntimeIdentifier");
94+
testProject.AdditionalProperties["PublishAot"] = "true";
95+
// Linux symbol files are embedded and require additional steps to be stripped to a separate file
96+
// assumes /bin (or /usr/bin) are in the PATH
97+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
98+
{
99+
testProject.AdditionalProperties["StripSymbols"] = "true";
100+
}
101+
// Use an identifier with a space to create a path with a space
102+
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: "with space");
103+
104+
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
105+
publishCommand
106+
.Execute($"/p:UseCurrentRuntimeIdentifier=true", "/p:SelfContained=true", "/p:CheckEolTargetFramework=false")
107+
.Should().Pass()
108+
.And.NotHaveStdOutContaining("IL2026")
109+
.And.NotHaveStdErrContaining("NETSDK1179")
110+
.And.NotHaveStdErrContaining("warning")
111+
.And.NotHaveStdOutContaining("warning");
112+
113+
var buildProperties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework);
114+
var rid = buildProperties["NETCoreSdkPortableRuntimeIdentifier"];
115+
var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
116+
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
117+
118+
// Verify the path contains a space
119+
testAsset.TestRoot.Should().Contain(" ", "Test should run with a space in the path");
120+
121+
// The exe should exist and should be native
122+
File.Exists(publishedExe).Should().BeTrue();
123+
DoSymbolsExist(publishDirectory, testProject.Name).Should().BeTrue($"{publishDirectory} should contain {testProject.Name} symbol");
124+
IsNativeImage(publishedExe).Should().BeTrue();
125+
126+
bool useRuntimePackLayout = targetFramework is not ("net7.0" or "net8.0" or "net9.0");
127+
128+
GetKnownILCompilerPackVersion(testAsset, targetFramework, out string expectedVersion);
129+
CheckIlcVersions(testAsset, targetFramework, rid, expectedVersion, useRuntimePackLayout);
130+
131+
var command = new RunExeCommand(Log, publishedExe)
132+
.Execute().Should().Pass()
133+
.And.HaveStdOutContaining("Hello World");
134+
}
135+
80136
[RequiresMSBuildVersionTheory("17.12.0")]
81137
[MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))]
82138
public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false(string targetFramework)

0 commit comments

Comments
 (0)