|
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;
|
@@ -1225,6 +1225,11 @@ public void Api()
|
1225 | 1225 | <Compile Include="{programPath}" />
|
1226 | 1226 | </ItemGroup>
|
1227 | 1227 |
|
| 1228 | + <ItemGroup> |
| 1229 | + <RuntimeHostConfigurationOption Include="EntryPointFilePath" Value="{programPath}" /> |
| 1230 | + <RuntimeHostConfigurationOption Include="EntryPointFileDirectoryPath" Value="{testInstance.Path}" /> |
| 1231 | + </ItemGroup> |
| 1232 | +
|
1228 | 1233 | <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
1229 | 1234 | <Import Project="Sdk.targets" Sdk="Aspire.Hosting.Sdk" Version="9.1.0" />
|
1230 | 1235 |
|
@@ -1308,6 +1313,11 @@ public void Api_Diagnostic_01()
|
1308 | 1313 | <Compile Include="{programPath}" />
|
1309 | 1314 | </ItemGroup>
|
1310 | 1315 |
|
| 1316 | + <ItemGroup> |
| 1317 | + <RuntimeHostConfigurationOption Include="EntryPointFilePath" Value="{programPath}" /> |
| 1318 | + <RuntimeHostConfigurationOption Include="EntryPointFileDirectoryPath" Value="{testInstance.Path}" /> |
| 1319 | + </ItemGroup> |
| 1320 | +
|
1311 | 1321 | <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
1312 | 1322 |
|
1313 | 1323 | <!--
|
@@ -1394,6 +1404,11 @@ public void Api_Diagnostic_02()
|
1394 | 1404 | <Compile Include="{programPath}" />
|
1395 | 1405 | </ItemGroup>
|
1396 | 1406 |
|
| 1407 | + <ItemGroup> |
| 1408 | + <RuntimeHostConfigurationOption Include="EntryPointFilePath" Value="{programPath}" /> |
| 1409 | + <RuntimeHostConfigurationOption Include="EntryPointFileDirectoryPath" Value="{testInstance.Path}" /> |
| 1410 | + </ItemGroup> |
| 1411 | +
|
1397 | 1412 | <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
1398 | 1413 |
|
1399 | 1414 | <!--
|
@@ -1449,4 +1464,109 @@ public void Api_Error()
|
1449 | 1464 | .And.HaveStdOutContaining("Unknown1")
|
1450 | 1465 | .And.HaveStdOutContaining("Unknown2");
|
1451 | 1466 | }
|
| 1467 | + |
| 1468 | + [Fact] |
| 1469 | + public void EntryPointFilePath() |
| 1470 | + { |
| 1471 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1472 | + var filePath = Path.Join(testInstance.Path, "Program.cs"); |
| 1473 | + File.WriteAllText(filePath, """" |
| 1474 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1475 | + Console.WriteLine($"""EntryPointFilePath: {entryPointFilePath}"""); |
| 1476 | + """"); |
| 1477 | + |
| 1478 | + new DotnetCommand(Log, "run", "Program.cs") |
| 1479 | + .WithWorkingDirectory(testInstance.Path) |
| 1480 | + .Execute() |
| 1481 | + .Should().Pass() |
| 1482 | + .And.HaveStdOut($"EntryPointFilePath: {filePath}"); |
| 1483 | + } |
| 1484 | + |
| 1485 | + [Fact] |
| 1486 | + public void EntryPointFileDirectoryPath() |
| 1487 | + { |
| 1488 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1489 | + File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """" |
| 1490 | + var entryPointFileDirectoryPath = AppContext.GetData("EntryPointFileDirectoryPath") as string; |
| 1491 | + Console.WriteLine($"""EntryPointFileDirectoryPath: {entryPointFileDirectoryPath}"""); |
| 1492 | + """"); |
| 1493 | + |
| 1494 | + new DotnetCommand(Log, "run", "Program.cs") |
| 1495 | + .WithWorkingDirectory(testInstance.Path) |
| 1496 | + .Execute() |
| 1497 | + .Should().Pass() |
| 1498 | + .And.HaveStdOut($"EntryPointFileDirectoryPath: {testInstance.Path}"); |
| 1499 | + } |
| 1500 | + |
| 1501 | + [Fact] |
| 1502 | + public void EntryPointFilePath_WithRelativePath() |
| 1503 | + { |
| 1504 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1505 | + var fileName = "Program.cs"; |
| 1506 | + File.WriteAllText(Path.Join(testInstance.Path, fileName), """ |
| 1507 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1508 | + Console.WriteLine($"EntryPointFilePath: {entryPointFilePath}"); |
| 1509 | + """); |
| 1510 | + |
| 1511 | + var relativePath = Path.GetRelativePath(Directory.GetCurrentDirectory(), Path.Join(testInstance.Path, fileName)); |
| 1512 | + new DotnetCommand(Log, "run", relativePath) |
| 1513 | + .WithWorkingDirectory(Directory.GetCurrentDirectory()) |
| 1514 | + .Execute() |
| 1515 | + .Should().Pass() |
| 1516 | + .And.HaveStdOut($"EntryPointFilePath: {Path.GetFullPath(relativePath)}"); |
| 1517 | + } |
| 1518 | + |
| 1519 | + [Fact] |
| 1520 | + public void EntryPointFilePath_WithSpacesInPath() |
| 1521 | + { |
| 1522 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1523 | + var dirWithSpaces = Path.Join(testInstance.Path, "dir with spaces"); |
| 1524 | + Directory.CreateDirectory(dirWithSpaces); |
| 1525 | + var filePath = Path.Join(dirWithSpaces, "Program.cs"); |
| 1526 | + File.WriteAllText(filePath, """ |
| 1527 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1528 | + Console.WriteLine($"EntryPointFilePath: {entryPointFilePath}"); |
| 1529 | + """); |
| 1530 | + |
| 1531 | + new DotnetCommand(Log, "run", filePath) |
| 1532 | + .WithWorkingDirectory(testInstance.Path) |
| 1533 | + .Execute() |
| 1534 | + .Should().Pass() |
| 1535 | + .And.HaveStdOut($"EntryPointFilePath: {filePath}"); |
| 1536 | + } |
| 1537 | + |
| 1538 | + [Fact] |
| 1539 | + public void EntryPointFileDirectoryPath_WithDotSlash() |
| 1540 | + { |
| 1541 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1542 | + var fileName = "Program.cs"; |
| 1543 | + File.WriteAllText(Path.Join(testInstance.Path, fileName), """ |
| 1544 | + var entryPointFileDirectoryPath = AppContext.GetData("EntryPointFileDirectoryPath") as string; |
| 1545 | + Console.WriteLine($"EntryPointFileDirectoryPath: {entryPointFileDirectoryPath}"); |
| 1546 | + """); |
| 1547 | + |
| 1548 | + new DotnetCommand(Log, "run", $"./{fileName}") |
| 1549 | + .WithWorkingDirectory(testInstance.Path) |
| 1550 | + .Execute() |
| 1551 | + .Should().Pass() |
| 1552 | + .And.HaveStdOut($"EntryPointFileDirectoryPath: {testInstance.Path}"); |
| 1553 | + } |
| 1554 | + |
| 1555 | + [Fact] |
| 1556 | + public void EntryPointFilePath_WithUnicodeCharacters() |
| 1557 | + { |
| 1558 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 1559 | + var unicodeFileName = "Программа.cs"; |
| 1560 | + var filePath = Path.Join(testInstance.Path, unicodeFileName); |
| 1561 | + File.WriteAllText(filePath, """ |
| 1562 | + var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; |
| 1563 | + Console.WriteLine($"EntryPointFilePath: {entryPointFilePath}"); |
| 1564 | + """); |
| 1565 | + |
| 1566 | + new DotnetCommand(Log, "run", unicodeFileName) |
| 1567 | + .WithWorkingDirectory(testInstance.Path) |
| 1568 | + .Execute() |
| 1569 | + .Should().Pass() |
| 1570 | + .And.HaveStdOut($"EntryPointFilePath: {filePath}"); |
| 1571 | + } |
1452 | 1572 | }
|
0 commit comments