Skip to content
Merged
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
4 changes: 2 additions & 2 deletions GVFS/GVFS.FunctionalTests/FileSystemRunners/BashRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ public override long FileSize(string path)
return long.Parse(this.RunProcess(statCommand));
}

public override void CreateFileWithoutClose(string path)
public override IDisposable CreateFileWithoutClose(string path)
{
throw new NotImplementedException();
}

public override void OpenFileAndWriteWithoutClose(string path, string data)
public override IDisposable OpenFileAndWriteWithoutClose(string path, string data)
{
throw new NotImplementedException();
}
Expand Down
10 changes: 5 additions & 5 deletions GVFS/GVFS.FunctionalTests/FileSystemRunners/CmdRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ public override void ChangeMode(string path, ushort mode)
throw new NotSupportedException();
}

public override void CreateFileWithoutClose(string path)
{
public override IDisposable CreateFileWithoutClose(string path)
{
throw new NotImplementedException();
}

public override void OpenFileAndWriteWithoutClose(string path, string data)
}
public override IDisposable OpenFileAndWriteWithoutClose(string path, string data)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public static FileSystemRunner DefaultRunner
/// <param name="path">Path to file</param>
/// <param name="contents">File contents</param>
public abstract void WriteAllText(string path, string contents);
public abstract void CreateFileWithoutClose(string path);
public abstract void OpenFileAndWriteWithoutClose(string path, string data);
public abstract IDisposable CreateFileWithoutClose(string path);
public abstract IDisposable OpenFileAndWriteWithoutClose(string path, string data);

/// <summary>
/// Append the specified contents to the specified file. By calling this method the caller is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GVFS.Tests.Should;
using System;
using System.IO;

namespace GVFS.FunctionalTests.FileSystemRunners
Expand Down Expand Up @@ -217,12 +218,12 @@ public override void ChangeMode(string path, ushort mode)
throw new System.NotSupportedException();
}

public override void CreateFileWithoutClose(string path)
public override IDisposable CreateFileWithoutClose(string path)
{
throw new System.NotSupportedException();
}

public override void OpenFileAndWriteWithoutClose(string path, string data)
}
public override IDisposable OpenFileAndWriteWithoutClose(string path, string data)
{
throw new System.NotSupportedException();
}
Expand Down
12 changes: 7 additions & 5 deletions GVFS/GVFS.FunctionalTests/FileSystemRunners/SystemIORunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public override string MoveFile(string sourcePath, string targetPath)
return string.Empty;
}

public override void CreateFileWithoutClose(string path)
public override IDisposable CreateFileWithoutClose(string path)
{
File.Create(path);
}

public override void OpenFileAndWriteWithoutClose(string path, string content)
return File.Create(path);
}
public override IDisposable OpenFileAndWriteWithoutClose(string path, string content)
{
StreamWriter file = new StreamWriter(path);
file.Write(content);
file.Flush();
return file;
}

public override void MoveFileShouldFail(string sourcePath, string targetPath)
Expand Down
42 changes: 33 additions & 9 deletions GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitRepoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,24 @@ protected void CreateFile(string content, params string[] filePathPaths)
this.FileSystem.WriteAllText(controlFile, content);
}

protected void CreateFileWithoutClose(string path)
{
protected IDisposable CreateFileWithoutClose(string path)
{
string virtualFile = Path.Combine(this.Enlistment.RepoRoot, path);
string controlFile = Path.Combine(this.ControlGitRepo.RootPath, path);
this.FileSystem.CreateFileWithoutClose(virtualFile);
this.FileSystem.CreateFileWithoutClose(controlFile);
}

protected void ReadFileAndWriteWithoutClose(string path, string contents)
IDisposable virtualHandle = this.FileSystem.CreateFileWithoutClose(virtualFile);
IDisposable controlHandle = this.FileSystem.CreateFileWithoutClose(controlFile);
return new CompositeDisposable(virtualHandle, controlHandle);
}

protected IDisposable ReadFileAndWriteWithoutClose(string path, string contents)
{
string virtualFile = Path.Combine(this.Enlistment.RepoRoot, path);
string controlFile = Path.Combine(this.ControlGitRepo.RootPath, path);
this.FileSystem.ReadAllText(virtualFile);
this.FileSystem.ReadAllText(controlFile);
this.FileSystem.OpenFileAndWriteWithoutClose(virtualFile, contents);
this.FileSystem.OpenFileAndWriteWithoutClose(controlFile, contents);
IDisposable virtualHandle = this.FileSystem.OpenFileAndWriteWithoutClose(virtualFile, contents);
IDisposable controlHandle = this.FileSystem.OpenFileAndWriteWithoutClose(controlFile, contents);
return new CompositeDisposable(virtualHandle, controlHandle);
}

protected void CreateFolder(string folderPath)
Expand Down Expand Up @@ -667,5 +669,27 @@ protected void FilesShouldMatchAfterConflict()
this.FileContentsShouldMatch("Test_ConflictTests", "ModifiedFiles", "SameChange.txt");
this.FileContentsShouldMatch("Test_ConflictTests", "ModifiedFiles", "SuccessfulMerge.txt");
}

/// <summary>
/// Disposes multiple <see cref="IDisposable"/> objects as a single unit.
/// Used to hold file handles open for the duration of a test scope.
/// </summary>
protected sealed class CompositeDisposable : IDisposable
{
private readonly IDisposable[] disposables;

public CompositeDisposable(params IDisposable[] disposables)
{
this.disposables = disposables;
}

public void Dispose()
{
foreach (IDisposable disposable in this.disposables)
{
disposable?.Dispose();
}
}
}
}
}
12 changes: 8 additions & 4 deletions GVFS/GVFS.FunctionalTests/Tests/GitCommands/StatusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ public void DeleteThenCreateThenDeleteFile()
public void CreateFileWithoutClose()
{
string srcPath = @"CreateFileWithoutClose.md";
this.CreateFileWithoutClose(srcPath);
this.ValidGitStatusWithRetry(srcPath);
using (IDisposable handles = this.CreateFileWithoutClose(srcPath))
{
this.ValidGitStatusWithRetry(srcPath);
}
}

[TestCase]
public void WriteWithoutClose()
{
string srcPath = @"Readme.md";
this.ReadFileAndWriteWithoutClose(srcPath, "More Stuff");
this.ValidGitStatusWithRetry(srcPath);
using (IDisposable handles = this.ReadFileAndWriteWithoutClose(srcPath, "More Stuff"))
{
this.ValidGitStatusWithRetry(srcPath);
}
}

[TestCase]
Expand Down
Loading