From 558b7e2c0aa300b31c0898a1a6f65ddc9cded279 Mon Sep 17 00:00:00 2001 From: Kevin Willford Date: Mon, 1 Oct 2018 15:58:16 -0600 Subject: [PATCH] Make checks on the modified paths be more strict --- .../EnlistmentPerFixture/GitFilesTests.cs | 6 ++--- .../ModifiedPathsTests.cs | 12 +++------ .../Tests/GitCommands/GitCommandsTests.cs | 6 +++-- .../GVFS.FunctionalTests/Tools/GVFSHelpers.cs | 25 ++++++++++++++++--- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs index 5352f7fc86..3313fb8f68 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs @@ -154,13 +154,13 @@ public void CaseOnlyRenameOfNewFolderKeepsModifiedPathsEntries() this.fileSystem.CreateEmptyFile(Path.Combine(this.Enlistment.RepoRoot, "Folder", "testfile")); this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete."); - GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A Folder/"); + GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "Folder/"); this.fileSystem.RenameDirectory(this.Enlistment.RepoRoot, "Folder", "folder"); this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete."); - GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A folder/"); - GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A folder/testfile"); + GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "folder/"); + GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "folder/testfile"); } [TestCase, Order(7)] diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs index ee4c1e060f..f8e42331e6 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs @@ -53,7 +53,7 @@ public void DeletedTempFileIsRemovedFromModifiedFiles(FileSystemRunner fileSyste tempFile.ShouldNotExistOnDisk(fileSystem); this.Enlistment.UnmountGVFS(); - this.ValidateModifiedPathsDoNotContain(fileSystem, "temp.txt"); + GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, "temp.txt"); } [TestCaseSource(typeof(FileSystemRunner), FileSystemRunner.TestRunners)] @@ -64,7 +64,7 @@ public void DeletedTempFolderIsRemovedFromModifiedFiles(FileSystemRunner fileSys tempFolder.ShouldNotExistOnDisk(fileSystem); this.Enlistment.UnmountGVFS(); - this.ValidateModifiedPathsDoNotContain(fileSystem, "Temp/"); + GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, "Temp/"); } [TestCaseSource(typeof(FileSystemRunner), FileSystemRunner.TestRunners)] @@ -79,7 +79,7 @@ public void DeletedTempFolderDeletesFilesFromModifiedFiles(FileSystemRunner file tempFile2.ShouldNotExistOnDisk(fileSystem); this.Enlistment.UnmountGVFS(); - this.ValidateModifiedPathsDoNotContain(fileSystem, "Temp/", "Temp/temp1.txt", "Temp/temp2.txt"); + GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, "Temp/", "Temp/temp1.txt", "Temp/temp2.txt"); } [Category(Categories.MacTODO.M2)] @@ -219,11 +219,5 @@ private string CreateFile(FileSystemRunner fileSystem, string relativePath) tempFile.ShouldBeAFile(fileSystem); return tempFile; } - - private void ValidateModifiedPathsDoNotContain(FileSystemRunner fileSystem, params string[] paths) - { - GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, paths.Select(x => $"A {x}" + Environment.NewLine).ToArray()); - GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, paths.Select(x => $"D {x}" + Environment.NewLine).ToArray()); - } } } diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitCommandsTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitCommandsTests.cs index c623f5ea72..31ac5cb08c 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitCommandsTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitCommandsTests.cs @@ -980,15 +980,17 @@ public void EditFileNeedingUtf8Encoding() { this.ValidateGitCommand("checkout -b tests/functional/EditFileNeedingUtf8Encoding"); this.ValidateGitCommand("status"); + string virtualFile = Path.Combine(this.Enlistment.RepoRoot, EncodingFileFolder, EncodingFilename); string controlFile = Path.Combine(this.ControlGitRepo.RootPath, EncodingFileFolder, EncodingFilename); + string relativeGitPath = EncodingFileFolder + "/" + EncodingFilename; string contents = virtualFile.ShouldBeAFile(this.FileSystem).WithContents(); string expectedContents = controlFile.ShouldBeAFile(this.FileSystem).WithContents(); contents.ShouldEqual(expectedContents); // Confirm that the entry is not in the the modified paths database - GVFSHelpers.ModifiedPathsShouldNotContain(this.FileSystem, this.Enlistment.DotGVFSRoot, EncodingFilename); + GVFSHelpers.ModifiedPathsShouldNotContain(this.FileSystem, this.Enlistment.DotGVFSRoot, relativeGitPath); this.ValidateGitCommand("status"); this.AppendAllText(ContentWhenEditingFile, virtualFile); @@ -997,7 +999,7 @@ public void EditFileNeedingUtf8Encoding() this.ValidateGitCommand("status"); // Confirm that the entry was added to the modified paths database - GVFSHelpers.ModifiedPathsShouldContain(this.FileSystem, this.Enlistment.DotGVFSRoot, EncodingFilename); + GVFSHelpers.ModifiedPathsShouldContain(this.FileSystem, this.Enlistment.DotGVFSRoot, relativeGitPath); } [TestCase] diff --git a/GVFS/GVFS.FunctionalTests/Tools/GVFSHelpers.cs b/GVFS/GVFS.FunctionalTests/Tools/GVFSHelpers.cs index 95e988c182..58abd79851 100644 --- a/GVFS/GVFS.FunctionalTests/Tools/GVFSHelpers.cs +++ b/GVFS/GVFS.FunctionalTests/Tools/GVFSHelpers.cs @@ -4,10 +4,10 @@ using Microsoft.Data.Sqlite; using Newtonsoft.Json; using NUnit.Framework; +using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; namespace GVFS.FunctionalTests.Tools { @@ -19,6 +19,9 @@ public static class GVFSHelpers public static readonly string PlaceholderListFile = Path.Combine("databases", "PlaceholderList.dat"); public static readonly string RepoMetadataName = Path.Combine("databases", "RepoMetadata.dat"); + private const string ModifedPathsLineAddPrefix = "A "; + private const string ModifedPathsLineDeletePrefix = "D "; + private const string DiskLayoutMajorVersionKey = "DiskLayoutVersion"; private const string DiskLayoutMinorVersionKey = "DiskLayoutMinorVersion"; private const string LocalCacheRootKey = "LocalCacheRoot"; @@ -111,15 +114,29 @@ public static void ModifiedPathsShouldContain(FileSystemRunner fileSystem, strin { string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths); modifiedPathsDatabase.ShouldBeAFile(fileSystem); - GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase).ShouldContain( - gitPaths.Select(path => path + ModifiedPathsNewLine).ToArray()); + string modifedPathsContents = GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase); + string[] modifedPathLines = modifedPathsContents.Split(new[] { ModifiedPathsNewLine }, StringSplitOptions.None); + foreach (string gitPath in gitPaths) + { + modifedPathLines.ShouldContain(path => path.Equals(ModifedPathsLineAddPrefix + gitPath)); + } } public static void ModifiedPathsShouldNotContain(FileSystemRunner fileSystem, string dotGVFSRoot, params string[] gitPaths) { string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths); modifiedPathsDatabase.ShouldBeAFile(fileSystem); - GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase).ShouldNotContain(ignoreCase: true, unexpectedSubstrings: gitPaths); + string modifedPathsContents = GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase); + string[] modifedPathLines = modifedPathsContents.Split(new[] { ModifiedPathsNewLine }, StringSplitOptions.None); + foreach (string gitPath in gitPaths) + { + modifedPathLines.ShouldNotContain( + path => + { + return path.Equals(ModifedPathsLineAddPrefix + gitPath, StringComparison.OrdinalIgnoreCase) || + path.Equals(ModifedPathsLineDeletePrefix + gitPath, StringComparison.OrdinalIgnoreCase); + }); + } } private static byte[] StringToShaBytes(string sha)