Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 52478e8

Browse files
author
Peter Huene
committed
Stop modifying current working directory from test.
This commit fixes the ToolPackageInstaller tests so that they no longer modify the current working directory. The directory being set is now being properly passed in as an argument to override the default of the current working directory. Additionally, this commit also changes the package root to a temp location rather than based off of the current working directory.
1 parent e2d9c2f commit 52478e8

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/dotnet/ToolPackage/IToolPackageInstaller.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ IToolPackage InstallPackage(
1515
VersionRange versionRange = null,
1616
string targetFramework = null,
1717
FilePath? nugetConfig = null,
18+
DirectoryPath? rootConfigDirectory = null,
1819
string source = null,
1920
string verbosity = null);
2021
}

src/dotnet/ToolPackage/ToolPackageInstaller.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public IToolPackage InstallPackage(
3535
VersionRange versionRange = null,
3636
string targetFramework = null,
3737
FilePath? nugetConfig = null,
38+
DirectoryPath? rootConfigDirectory = null,
3839
string source = null,
3940
string verbosity = null)
4041
{
@@ -53,7 +54,8 @@ public IToolPackage InstallPackage(
5354
packageId: packageId,
5455
versionRange: versionRange,
5556
targetFramework: targetFramework ?? BundledTargetFramework.GetTargetFrameworkMoniker(),
56-
restoreDirectory: stageDirectory);
57+
restoreDirectory: stageDirectory,
58+
rootConfigDirectory: rootConfigDirectory);
5759

5860
try
5961
{
@@ -115,7 +117,8 @@ private FilePath CreateTempProject(
115117
PackageId packageId,
116118
VersionRange versionRange,
117119
string targetFramework,
118-
DirectoryPath restoreDirectory)
120+
DirectoryPath restoreDirectory,
121+
DirectoryPath? rootConfigDirectory)
119122
{
120123
var tempProject = _tempProject ?? new DirectoryPath(Path.GetTempPath())
121124
.WithSubDirectories(Path.GetRandomFileName())
@@ -135,7 +138,7 @@ private FilePath CreateTempProject(
135138
new XElement("TargetFramework", targetFramework),
136139
new XElement("RestorePackagesPath", restoreDirectory.Value),
137140
new XElement("RestoreProjectStyle", "DotnetToolReference"), // without it, project cannot reference tool package
138-
new XElement("RestoreRootConfigDirectory", Directory.GetCurrentDirectory()), // config file probing start directory
141+
new XElement("RestoreRootConfigDirectory", rootConfigDirectory?.Value ?? Directory.GetCurrentDirectory()), // config file probing start directory
139142
new XElement("DisableImplicitFrameworkReferences", "true"), // no Microsoft.NETCore.App in tool folder
140143
new XElement("RestoreFallbackFolders", "clear"), // do not use fallbackfolder, tool package need to be copied to tool folder
141144
new XElement("RestoreAdditionalProjectSources", // use fallbackfolder as feed to enable offline

test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,17 @@ From mytool.dll to project.assets.json
154154
}
155155

156156
[Fact]
157-
public void GivenAConfigFileInCurrentDirectoryPackageInstallSucceeds()
157+
public void GivenAConfigFileRootDirectoryPackageInstallSucceeds()
158158
{
159159
var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed();
160160

161161
var (store, installer, reporter, fileSystem) = Setup(useMock: false);
162162

163-
/*
164-
* In test, we don't want NuGet to keep look up, so we point current directory to nugetconfig.
165-
*/
166-
Directory.SetCurrentDirectory(nugetConfigPath.GetDirectoryPath().Value);
167-
168163
var package = installer.InstallPackage(
169164
packageId: TestPackageId,
170165
versionRange: VersionRange.Parse(TestPackageVersion),
171-
targetFramework: _testTargetframework);
166+
targetFramework: _testTargetframework,
167+
rootConfigDirectory: nugetConfigPath.GetDirectoryPath());
172168

173169
AssertPackageInstall(reporter, fileSystem, package, store);
174170

@@ -641,7 +637,7 @@ private static (IToolPackageStore, IToolPackageInstaller, BufferedReporter, IFil
641637
FilePath? tempProject = null,
642638
DirectoryPath? offlineFeed = null)
643639
{
644-
var root = new DirectoryPath(Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()));
640+
var root = new DirectoryPath(Path.Combine(Path.GetFullPath(TempRoot.Root), Path.GetRandomFileName()));
645641
var reporter = new BufferedReporter();
646642

647643
IFileSystem fileSystem;

test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageInstallerMock.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public IToolPackage InstallPackage(
4040
VersionRange versionRange = null,
4141
string targetFramework = null,
4242
FilePath? nugetConfig = null,
43+
DirectoryPath? rootConfigDirectory = null,
4344
string source = null,
4445
string verbosity = null)
4546
{

0 commit comments

Comments
 (0)