|
1 |
| -// Licensed to the .NET Foundation under one or more agreements. |
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 | 4 | using System.Runtime.Versioning;
|
@@ -1277,6 +1277,11 @@ public void Api()
|
1277 | 1277 | <Compile Include="{programPath}" />
|
1278 | 1278 | </ItemGroup>
|
1279 | 1279 |
|
| 1280 | + <ItemGroup> |
| 1281 | + <RuntimeHostConfigurationOption Include="EntryPointFilePath" Value="{programPath}" /> |
| 1282 | + <RuntimeHostConfigurationOption Include="EntryPointFileDirectoryPath" Value="{testInstance.Path}" /> |
| 1283 | + </ItemGroup> |
| 1284 | +
|
1280 | 1285 | <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
1281 | 1286 | <Import Project="Sdk.targets" Sdk="Aspire.Hosting.Sdk" Version="9.1.0" />
|
1282 | 1287 |
|
@@ -1360,6 +1365,11 @@ public void Api_Diagnostic_01()
|
1360 | 1365 | <Compile Include="{programPath}" />
|
1361 | 1366 | </ItemGroup>
|
1362 | 1367 |
|
| 1368 | + <ItemGroup> |
| 1369 | + <RuntimeHostConfigurationOption Include="EntryPointFilePath" Value="{programPath}" /> |
| 1370 | + <RuntimeHostConfigurationOption Include="EntryPointFileDirectoryPath" Value="{testInstance.Path}" /> |
| 1371 | + </ItemGroup> |
| 1372 | +
|
1363 | 1373 | <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
1364 | 1374 |
|
1365 | 1375 | <!--
|
@@ -1446,6 +1456,11 @@ public void Api_Diagnostic_02()
|
1446 | 1456 | <Compile Include="{programPath}" />
|
1447 | 1457 | </ItemGroup>
|
1448 | 1458 |
|
| 1459 | + <ItemGroup> |
| 1460 | + <RuntimeHostConfigurationOption Include="EntryPointFilePath" Value="{programPath}" /> |
| 1461 | + <RuntimeHostConfigurationOption Include="EntryPointFileDirectoryPath" Value="{testInstance.Path}" /> |
| 1462 | + </ItemGroup> |
| 1463 | +
|
1449 | 1464 | <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
1450 | 1465 |
|
1451 | 1466 | <!--
|
@@ -1501,4 +1516,110 @@ public void Api_Error()
|
1501 | 1516 | .And.HaveStdOutContaining("Unknown1")
|
1502 | 1517 | .And.HaveStdOutContaining("Unknown2");
|
1503 | 1518 | }
|
| 1519 | + |
| 1520 | + [Fact] |
| 1521 | + public void EntryPointFilePath() |
| 1522 | + { |
| 1523 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1524 | + var filePath = Path.Join(testInstance.Path, "Program.cs"); |
| 1525 | + File.WriteAllText(filePath, """" |
| 1526 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1527 | + Console.WriteLine($"""EntryPointFilePath: {entryPointFilePath}"""); |
| 1528 | + """"); |
| 1529 | + |
| 1530 | + new DotnetCommand(Log, "run", "Program.cs") |
| 1531 | + .WithWorkingDirectory(testInstance.Path) |
| 1532 | + .Execute() |
| 1533 | + .Should().Pass() |
| 1534 | + .And.HaveStdOut($"EntryPointFilePath: {filePath}"); |
| 1535 | + } |
| 1536 | + |
| 1537 | + [Fact] |
| 1538 | + public void EntryPointFileDirectoryPath() |
| 1539 | + { |
| 1540 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1541 | + File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """" |
| 1542 | + var entryPointFileDirectoryPath = AppContext.GetData("EntryPointFileDirectoryPath") as string; |
| 1543 | + Console.WriteLine($"""EntryPointFileDirectoryPath: {entryPointFileDirectoryPath}"""); |
| 1544 | + """"); |
| 1545 | + |
| 1546 | + new DotnetCommand(Log, "run", "Program.cs") |
| 1547 | + .WithWorkingDirectory(testInstance.Path) |
| 1548 | + .Execute() |
| 1549 | + .Should().Pass() |
| 1550 | + .And.HaveStdOut($"EntryPointFileDirectoryPath: {testInstance.Path}"); |
| 1551 | + } |
| 1552 | + |
| 1553 | + [Fact] |
| 1554 | + public void EntryPointFilePath_WithRelativePath() |
| 1555 | + { |
| 1556 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1557 | + var fileName = "Program.cs"; |
| 1558 | + File.WriteAllText(Path.Join(testInstance.Path, fileName), """ |
| 1559 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1560 | + Console.WriteLine($"EntryPointFilePath: {entryPointFilePath}"); |
| 1561 | + """); |
| 1562 | + |
| 1563 | + var relativePath = Path.GetRelativePath(Directory.GetCurrentDirectory(), Path.Join(testInstance.Path, fileName)); |
| 1564 | + new DotnetCommand(Log, "run", relativePath) |
| 1565 | + .WithWorkingDirectory(Directory.GetCurrentDirectory()) |
| 1566 | + .Execute() |
| 1567 | + .Should().Pass() |
| 1568 | + .And.HaveStdOut($"EntryPointFilePath: {Path.GetFullPath(relativePath)}"); |
| 1569 | + } |
| 1570 | + |
| 1571 | + [Fact] |
| 1572 | + public void EntryPointFilePath_WithSpacesInPath() |
| 1573 | + { |
| 1574 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1575 | + var dirWithSpaces = Path.Join(testInstance.Path, "dir with spaces"); |
| 1576 | + Directory.CreateDirectory(dirWithSpaces); |
| 1577 | + var filePath = Path.Join(dirWithSpaces, "Program.cs"); |
| 1578 | + File.WriteAllText(filePath, """ |
| 1579 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1580 | + Console.WriteLine($"EntryPointFilePath: {entryPointFilePath}"); |
| 1581 | + """); |
| 1582 | + |
| 1583 | + new DotnetCommand(Log, "run", filePath) |
| 1584 | + .WithWorkingDirectory(testInstance.Path) |
| 1585 | + .Execute() |
| 1586 | + .Should().Pass() |
| 1587 | + .And.HaveStdOut($"EntryPointFilePath: {filePath}"); |
| 1588 | + } |
| 1589 | + |
| 1590 | + [Fact] |
| 1591 | + public void EntryPointFileDirectoryPath_WithDotSlash() |
| 1592 | + { |
| 1593 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1594 | + var fileName = "Program.cs"; |
| 1595 | + File.WriteAllText(Path.Join(testInstance.Path, fileName), """ |
| 1596 | + var entryPointFileDirectoryPath = AppContext.GetData("EntryPointFileDirectoryPath") as string; |
| 1597 | + Console.WriteLine($"EntryPointFileDirectoryPath: {entryPointFileDirectoryPath}"); |
| 1598 | + """); |
| 1599 | + |
| 1600 | + new DotnetCommand(Log, "run", $"./{fileName}") |
| 1601 | + .WithWorkingDirectory(testInstance.Path) |
| 1602 | + .Execute() |
| 1603 | + .Should().Pass() |
| 1604 | + .And.HaveStdOut($"EntryPointFileDirectoryPath: {testInstance.Path}"); |
| 1605 | + } |
| 1606 | + |
| 1607 | + [Fact] |
| 1608 | + public void EntryPointFilePath_WithUnicodeCharacters() |
| 1609 | + { |
| 1610 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1611 | + var unicodeFileName = "Программа.cs"; |
| 1612 | + var filePath = Path.Join(testInstance.Path, unicodeFileName); |
| 1613 | + File.WriteAllText(filePath, """ |
| 1614 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1615 | + Console.WriteLine($"EntryPointFilePath: {entryPointFilePath}"); |
| 1616 | + """); |
| 1617 | + |
| 1618 | + new DotnetCommand(Log, "run", unicodeFileName) |
| 1619 | + .WithWorkingDirectory(testInstance.Path) |
| 1620 | + .WithStandardOutputEncoding(Encoding.UTF8) |
| 1621 | + .Execute() |
| 1622 | + .Should().Pass() |
| 1623 | + .And.HaveStdOut($"EntryPointFilePath: {filePath}"); |
| 1624 | + } |
1504 | 1625 | }
|
0 commit comments