Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix hard-coded v16 in remove-junk" #77

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions DotNetPlease.Tests/Commands/RemoveJunkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

using System.Collections.Generic;
using System.IO;
using System.Reflection.Metadata;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -114,49 +113,6 @@ public async Task It_only_removes_bin_and_obj_from_project_directories(bool dryR
Directory.Exists(WorkingDirectory + "/bin").Should().BeTrue();
}

[Theory, CombinatorialData]
public async Task It_removes_the_TestStore_directory([CombinatorialValues("v16", "v17")]string vsVersion, bool dryRun)
{
var solutionFileName = GetFullPath("Test.sln");
CreateSolution(solutionFileName);
var directoryToDelete = Path.Combine(WorkingDirectory, ".vs", "Test", vsVersion, "TestStore");
Directory.CreateDirectory(directoryToDelete);

if (dryRun) CreateSnapshot();

await RunAndAssertSuccess("remove-junk", "--testStore", DryRunOption(dryRun));

if (dryRun)
{
VerifySnapshot();
return;
}

Directory.Exists(directoryToDelete).Should().BeFalse();
}

[Theory, CombinatorialData]
public async Task It_removes_the_suo_file([CombinatorialValues("v16", "v17")] string vsVersion, bool dryRun)
{
var solutionFileName = GetFullPath("Test.sln");
CreateSolution(solutionFileName);
var fileToDelete = Path.Combine(WorkingDirectory, ".vs", "Test", vsVersion, ".suo");
Directory.CreateDirectory(Path.GetDirectoryName(fileToDelete));
File.Create(fileToDelete).Dispose();

if (dryRun) CreateSnapshot();

await RunAndAssertSuccess("remove-junk", "--suo", DryRunOption(dryRun));

if (dryRun)
{
VerifySnapshot();
return;
}

File.Exists(fileToDelete).Should().BeFalse();
}

public RemoveJunkTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
}
Expand Down
18 changes: 0 additions & 18 deletions DotNetPlease.Tests/Commands/TestFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@
[Collection("cwd")]
public class TestFixtureBase : IDisposable
{
//[Theory, CombinatorialData]
//public async Task Template_test(bool dryRun)
//{
// // Arrange workspace

// if (dryRun) CreateSnapshot();

// await RunAndAssertSuccess("command", "--switch", "argument", DryRunOption(dryRun));

// if (dryRun)
// {
// VerifySnapshot();
// return;
// }

// // Assert
//}

protected readonly string WorkingDirectory;

protected readonly TestOutputReporter TestOutputReporter;
Expand All @@ -78,7 +60,7 @@
{
var relativePath = GetRelativePath(fileName);
var newPath = Path.GetFullPath(relativePath, _snapshotDirectory);
Directory.CreateDirectory(Path.GetDirectoryName(newPath));

Check warning on line 63 in DotNetPlease.Tests/Commands/TestFixtureBase.cs

View workflow job for this annotation

GitHub Actions / build / build

Possible null reference argument for parameter 'path' in 'DirectoryInfo Directory.CreateDirectory(string path)'.
File.Copy(fileName, newPath);
}
}
Expand Down
15 changes: 5 additions & 10 deletions DotNetPlease/Commands/RemoveJunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
using System.Threading;
using System.Threading.Tasks;
using DotNetPlease.Annotations;
using DotNetPlease.Helpers;
using DotNetPlease.Internal;
using DotNetPlease.Services.Reporting.Abstractions;
using JetBrains.Annotations;
using MediatR;
using static DotNetPlease.Helpers.MSBuildHelper;

namespace DotNetPlease.Commands
{
Expand Down Expand Up @@ -74,10 +74,8 @@ private void RemoveSuo(Context context)
return;
}

foreach (var dir in GetHiddenVSFiles(context.SolutionFileName, ".suo"))
{
TryDeleteFile(dir, context);
}
var path = Path.Combine(MSBuildHelper.GetHiddenVsDirectory(context.SolutionFileName), "v16/.suo");
TryDeleteFile(path, context);
}

private void RemoveTestStore(Context context)
Expand All @@ -87,11 +85,8 @@ private void RemoveTestStore(Context context)
Reporter.Warning("Test Store can only be removed from solutions");
return;
}

foreach (var dir in GetHiddenVSDirectories(context.SolutionFileName, "TestStore"))
{
TryDeleteDirectory(dir, context);
}
var path = Path.Combine(MSBuildHelper.GetHiddenVsDirectory(context.SolutionFileName), $"v16/TestStore");
TryDeleteDirectory(path, context);
}

private void RemoveBinFolders(Context context)
Expand Down
45 changes: 2 additions & 43 deletions DotNetPlease/Helpers/MSBuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,55 +544,14 @@ public static void LocateMSBuild()
_msBuildLocated = true;
}

private static readonly Regex VSVersionRegex = new Regex(@"v\d+");

/// <summary>
/// Returns the root directory for the specified solution under the hidden .vs directory, eg.
/// <c>.vs/SolutionName</c>
/// </summary>
/// <param name="solutionFileName"></param>
/// <returns></returns>
public static string GetHiddenVSDirectoryRoot(string solutionFileName)
public static string GetHiddenVsDirectory(string solutionFileName)
{
var hiddenDirectoryName = Path.GetExtension(solutionFileName)?.ToLower() switch
{
".slnf" => Path.GetFileName(solutionFileName),
_ => Path.ChangeExtension(Path.GetFileName(solutionFileName), null)
};
return Path.Combine(Path.GetDirectoryName(solutionFileName), ".vs", hiddenDirectoryName);
}

/// <summary>
/// Returns a collection of directories matching the specified name
/// in any of the version-specific hidden directories for the solution, eg.
/// <c>.vs/SolutionName/v17/name</c>
/// </summary>
/// <param name="solutionFileName"></param>
/// <param name="directoryName"></param>
/// <returns></returns>
public static IEnumerable<string> GetHiddenVSDirectories(string solutionFileName, string directoryName)
{
return GetHiddenVSDirectoryItems(solutionFileName, directoryName).Where(Directory.Exists);
}

/// <summary>
/// Returns a collection of file names matching the specified globbing pattern
/// in any of the version-specific hidden directories for the solution, eg.
/// <c>.vs/SolutionName/v17/pattern</c>
/// </summary>
/// <param name="solutionFileName"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public static IEnumerable<string> GetHiddenVSFiles(string solutionFileName, string fileName)
{
return GetHiddenVSDirectoryItems(solutionFileName, fileName).Where(File.Exists);
}

private static IEnumerable<string> GetHiddenVSDirectoryItems(string solutionFileName, string name)
{
return Directory.GetDirectories(GetHiddenVSDirectoryRoot(solutionFileName))
.Where(dir => VSVersionRegex.IsMatch(Path.GetFileName(dir)!))
.Select(dir => Path.Combine(dir, name));
return $".vs/{hiddenDirectoryName}";
}
}

Expand Down
Loading