Skip to content
Merged

cleanup #3969

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
8 changes: 4 additions & 4 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ public void EnsureAssemblyInfoFalse()
[Test]
public void DynamicRepoLocation()
{
var arguments = this.argumentParser.ParseArguments("-dynamicRepoLocation c:\\foo\\");
arguments.ClonePath.ShouldBe("c:\\foo\\");
var arguments = this.argumentParser.ParseArguments(@"-dynamicRepoLocation /tmp/foo");
arguments.ClonePath.ShouldBe("/tmp/foo");
}

[Test]
Expand Down Expand Up @@ -748,14 +748,14 @@ public void EnsureFormatIsSet()
}

[TestCase("custom-config.yaml")]
[TestCase(@"c:\custom-config.yaml")]
[TestCase("/tmp/custom-config.yaml")]
public void ThrowIfConfigurationFileDoesNotExist(string configFile) =>
Should.Throw<WarningException>(() => _ = this.argumentParser.ParseArguments($"-config {configFile}"));

[Test]
public void EnsureConfigurationFileIsSet()
{
var configFile = Path.GetTempPath() + Guid.NewGuid() + ".yaml";
var configFile = PathHelper.GetTempPath() + Guid.NewGuid() + ".yaml";
File.WriteAllText(configFile, "next-version: 1.0.0");
var arguments = this.argumentParser.ParseArguments($"-config {configFile}");
arguments.ConfigurationFile.ShouldBe(configFile);
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public async Task VerifyBitBucketPipelinesPullRequest(string pullRequestRef)

private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pullRequestRef, Dictionary<string, string> env)
{
using var fixture = new EmptyRepositoryFixture("main");
var remoteRepositoryPath = PathHelper.GetTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath, "main");
using var fixture = new EmptyRepositoryFixture();
var remoteRepositoryPath = PathHelper.GetRepositoryTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath);
using (var remoteRepository = new Repository(remoteRepositoryPath))
{
remoteRepository.Config.Set("user.name", "Test");
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.App.Tests/TagCheckoutInBuildAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public async Task VerifyTagCheckoutOnGitHubActions()

private static async Task VerifyTagCheckoutVersionIsCalculatedProperly(Dictionary<string, string> env)
{
using var fixture = new EmptyRepositoryFixture("main");
var remoteRepositoryPath = PathHelper.GetTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath, "main");
using var fixture = new EmptyRepositoryFixture();
var remoteRepositoryPath = PathHelper.GetRepositoryTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath);
using (var remoteRepository = new Repository(remoteRepositoryPath))
{
remoteRepository.Config.Set("user.name", "Test");
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList<st
// If we've reached through all argument switches without a match, we can relatively safely assume that the first argument isn't a switch, but the target path.
if (parseEnded)
{
if (name?.StartsWith("/") == true)
if (name?.StartsWith('/') == true)
{
if (Path.DirectorySeparatorChar == '/' && name.IsValidPath())
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.BuildAgents.Tests/Agents/EnvRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void SetEnvironmentVariableForTest()
this.buildServer = sp.GetRequiredService<EnvRun>();

// set environment variable and create an empty envrun file to indicate that EnvRun is running...
this.mFilePath = PathHelper.Combine(Path.GetTempPath(), "envrun.db");
this.mFilePath = PathHelper.Combine(PathHelper.GetTempPath(), "envrun.db");
this.environment.SetEnvironmentVariable(EnvVarName, this.mFilePath);
File.OpenWrite(this.mFilePath).Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public static class ConfigurationFileLocatorTests
{
public class DefaultConfigFileLocatorTests : TestBase
{
private const string DefaultRepoPath = @"c:\MyGitRepo";
private const string DefaultWorkingPath = @"c:\MyGitRepo\Working";

private string repoPath;
private string workingPath;
private IFileSystem fileSystem;
Expand All @@ -25,8 +22,8 @@ public class DefaultConfigFileLocatorTests : TestBase
[SetUp]
public void Setup()
{
this.repoPath = DefaultRepoPath;
this.workingPath = DefaultWorkingPath;
this.repoPath = Path.Combine(PathHelper.GetTempPath(), "MyGitRepo");
this.workingPath = Path.Combine(PathHelper.GetTempPath(), "MyGitRepo", "Working");
var options = Options.Create(new GitVersionOptions { WorkingDirectory = repoPath });

var sp = ConfigureServices(services => services.AddSingleton(options));
Expand Down Expand Up @@ -76,8 +73,8 @@ private string SetupConfigFileContent(string text, string fileName, string path)

public class NamedConfigurationFileLocatorTests : TestBase
{
private const string DefaultRepoPath = @"c:\MyGitRepo";
private const string DefaultWorkingPath = @"c:\MyGitRepo\Working";
private static readonly string DefaultRepoPath = Path.Combine(PathHelper.GetTempPath(), "MyGitRepo");
private static readonly string DefaultWorkingPath = Path.Combine(PathHelper.GetTempPath(), "MyGitRepo", "Working");
private const string myConfigYaml = "my-config.yaml";

private string repoPath;
Expand Down Expand Up @@ -189,7 +186,7 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
this.fileSystem = sp.GetRequiredService<IFileSystem>();

SetupConfigFileContent(string.Empty, path: @"c:\\Unrelated\\path");
SetupConfigFileContent(string.Empty, path: PathHelper.Combine(PathHelper.GetTempPath(), "unrelatedPath"));

var configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ namespace GitVersion.Core.Tests;
[TestFixture]
public class ConfigurationProviderTests : TestBase
{
private const string DefaultRepoPath = @"c:\MyGitRepo";

private string repoPath;
private ConfigurationProvider configurationProvider;
private IFileSystem fileSystem;

[SetUp]
public void Setup()
{
this.repoPath = DefaultRepoPath;
this.repoPath = Path.Combine(PathHelper.GetTempPath(), "MyGitRepo");
var options = Options.Create(new GitVersionOptions { WorkingDirectory = repoPath });
var sp = ConfigureServices(services => services.AddSingleton(options));
this.configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Configuration/ConfigurationFileLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public bool TryGetConfigurationFile(string? workingDirectory, string? projectRoo

public void Verify(string? workingDirectory, string? projectRootDirectory)
{
if (!Path.IsPathRooted(this.configurationFile) && !fileSystem.PathsEqual(workingDirectory, projectRootDirectory))
if (!Path.IsPathRooted(this.configurationFile) && !PathHelper.Equal(workingDirectory, projectRootDirectory))
WarnAboutAmbiguousConfigFileSelection(workingDirectory, projectRootDirectory);
}

Expand Down
5 changes: 0 additions & 5 deletions src/GitVersion.Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using GitVersion.Configuration.SupportedWorkflows;
using GitVersion.Extensions;
using GitVersion.Logging;
using Microsoft.Extensions.Options;
using YamlDotNet.Core;

namespace GitVersion.Configuration;

internal class ConfigurationProvider(
IFileSystem fileSystem,
ILog log,
IConfigurationFileLocator configFileLocator,
IOptions<GitVersionOptions> options)
: IConfigurationProvider
{
private readonly IFileSystem fileSystem = fileSystem.NotNull();
private readonly ILog log = log.NotNull();
private readonly IConfigurationFileLocator configFileLocator = configFileLocator.NotNull();
private readonly IOptions<GitVersionOptions> options = options.NotNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GitVersionTaskDirectoryTests : TestBase
[SetUp]
public void SetUp()
{
this.workDirectory = PathHelper.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
this.workDirectory = PathHelper.Combine(PathHelper.GetTempPath(), Guid.NewGuid().ToString());
this.gitDirectory = Repository.Init(this.workDirectory).TrimEnd(Path.DirectorySeparatorChar);
Assert.That(this.gitDirectory, Is.Not.Null);
}
Expand Down
29 changes: 22 additions & 7 deletions src/GitVersion.Core.Tests/Helpers/GitVersionContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

namespace GitVersion.Core.Tests;

public class GitVersionContextBuilder
public class GitVersionContextBuilder : IDisposable
{
private IGitRepository? repository;
private EmptyRepositoryFixture? emptyRepositoryFixture;
private IReadOnlyDictionary<object, object?>? overrideConfiguration;
public IServiceProvider? ServicesProvider;
private Action<IServiceCollection>? overrideServices;
public IServiceProvider? ServicesProvider;

public GitVersionContextBuilder WithRepository(IGitRepository gitRepository)
{
Expand Down Expand Up @@ -56,11 +57,8 @@ public void Build()
{
var repo = this.repository ?? CreateRepository();

var options = Options.Create(new GitVersionOptions
{
WorkingDirectory = new EmptyRepositoryFixture().RepositoryPath,
ConfigurationInfo = { OverrideConfiguration = this.overrideConfiguration }
});
emptyRepositoryFixture = new();
var options = Options.Create(new GitVersionOptions { WorkingDirectory = emptyRepositoryFixture.RepositoryPath, ConfigurationInfo = { OverrideConfiguration = this.overrideConfiguration } });

this.ServicesProvider = ConfigureServices(services =>
{
Expand Down Expand Up @@ -94,4 +92,21 @@ private static IServiceProvider ConfigureServices(Action<IServiceCollection>? ov

return services.BuildServiceProvider();
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (!disposing)
{
return;
}

this.repository?.Dispose();
this.emptyRepositoryFixture?.Dispose();
}
}
1 change: 1 addition & 0 deletions src/GitVersion.Core.Tests/Helpers/TestConsoleAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Helpers;
using GitVersion.Logging;

namespace GitVersion.Core.Tests.Helpers;
Expand Down
7 changes: 1 addition & 6 deletions src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GitVersion.Core.Tests.Helpers;

public class TestFileSystem : IFileSystem
{
private readonly Dictionary<string, byte[]> fileSystem = new(StringComparerUtils.OsDependentComparer);
private readonly Dictionary<string, byte[]> fileSystem = new(SysEnv.OSVersion.Platform == PlatformID.Unix ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase);

public void Copy(string from, string to, bool overwrite)
{
Expand Down Expand Up @@ -94,9 +94,4 @@ public bool DirectoryExists(string path)
}

public long GetLastDirectoryWrite(string path) => 1;

public bool PathsEqual(string? path, string? otherPath) => string.Equals(
Path.GetFullPath(path ?? throw new ArgumentNullException(nameof(path))).TrimEnd('\\').TrimEnd('/'),
Path.GetFullPath(otherPath ?? throw new ArgumentNullException(nameof(otherPath))).TrimEnd('\\').TrimEnd('/'),
StringComparerUtils.OsDependentComparison);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static GitHubFlowConfigurationBuilder GetConfigurationBuilder() => GitHu
[Test]
public void ExpectedBehavior()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("1.0.0");

Expand Down Expand Up @@ -172,7 +172,7 @@ public void ExpectedBehavior()
[Test]
public void MainRelease()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("0.0.2");

Expand All @@ -186,7 +186,7 @@ public void MainRelease()
[Test]
public void MergeFeatureToMain()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("0.0.2");
fixture.BranchTo("feature/test");
Expand Down Expand Up @@ -220,7 +220,7 @@ public void MergeFeatureToMain()
[Test]
public void MergeFeatureToMainWithPreviousCommits()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("0.0.2");
fixture.MakeACommit();
Expand Down Expand Up @@ -270,7 +270,7 @@ public void MergeFeatureToMainWithPreviousCommits()
[Test]
public void MergeFeatureToMainWithMinorMinorSemversionIncrement()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("0.0.2");
fixture.BranchTo("feature/test");
Expand Down Expand Up @@ -304,7 +304,7 @@ public void MergeFeatureToMainWithMinorMinorSemversionIncrement()
[Test]
public void MergeFeatureToMainWithMajorMinorSemversionIncrement()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("0.0.2");
fixture.BranchTo("feature/test");
Expand Down Expand Up @@ -338,7 +338,7 @@ public void MergeFeatureToMainWithMajorMinorSemversionIncrement()
[Test]
public void MergeFeatureToMainWithPreviousCommitsAndMinorMinorSemversionIncrement()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("0.0.2");
fixture.MakeACommit("+semver: minor");
Expand Down Expand Up @@ -388,7 +388,7 @@ public void MergeFeatureToMainWithPreviousCommitsAndMinorMinorSemversionIncremen
[Test]
public void MergeFeatureToMainWithPreviousCommitsAndMinorMajorSemversionIncrement()
{
using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.MakeATaggedCommit("0.0.2");
fixture.MakeACommit("+semver: minor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void ShouldTreatTheFeatureBranchLikeTheFirstReleaseBranchWhenItHasBeenBra

var configuration = GitFlowConfigurationBuilder.New.Build();

using var fixture = new EmptyRepositoryFixture("main");
using var fixture = new EmptyRepositoryFixture();

fixture.Repository.MakeACommit();

Expand Down
Loading