-
Notifications
You must be signed in to change notification settings - Fork 235
Implement better way to test for in-memory file #645
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
Changes from 2 commits
ae975a1
541822d
6d3d665
adab98b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,35 @@ public void CanResolveWorkspaceRelativePath() | |
Assert.Equal(@"..\PeerPath\FilePath.ps1", workspace.GetRelativePath(testPathOutside)); | ||
Assert.Equal(testPathAnotherDrive, workspace.GetRelativePath(testPathAnotherDrive)); | ||
} | ||
|
||
[Fact] | ||
public void CanDetermineIsPathInMemory() | ||
{ | ||
var tempDir = Environment.GetEnvironmentVariable("TEMP"); | ||
|
||
var shortDirPath = Path.Combine(tempDir, "GitHub", "PowerShellEditorServices"); | ||
var shortFilePath = Path.Combine(shortDirPath, "foo.ps1"); | ||
var shortDirUriForm = new Uri(shortDirPath).ToString(); | ||
var shortFileUriForm = new Uri(shortFilePath).ToString(); | ||
|
||
// Test short file absolute paths | ||
Assert.False(Workspace.IsPathInMemory(shortDirPath)); | ||
Assert.False(Workspace.IsPathInMemory(shortFilePath)); | ||
Assert.False(Workspace.IsPathInMemory(shortDirUriForm)); | ||
Assert.False(Workspace.IsPathInMemory(shortFileUriForm)); | ||
|
||
// Test short file relative paths - not sure we'll ever get these but just in case | ||
Assert.False(Workspace.IsPathInMemory("foo.ps1")); | ||
Assert.False(Workspace.IsPathInMemory(".." + Path.DirectorySeparatorChar + "foo.ps1")); | ||
|
||
// Test short non-file paths | ||
Assert.True(Workspace.IsPathInMemory("untitled:untitled-1")); | ||
var shortUriForm = "git:/c%3A/Users/Keith/GitHub/dahlbyk/posh-git/src/PoshGitTypes.ps1?%7B%22path%22%3A%22c%3A%5C%5CUsers%5C%5CKeith%5C%5CGitHub%5C%5Cdahlbyk%5C%5Cposh-git%5C%5Csrc%5C%5CPoshGitTypes.ps1%22%2C%22ref%22%3A%22~%22%7D"; | ||
Assert.True(Workspace.IsPathInMemory(shortUriForm)); | ||
|
||
// Test long non-file path - known to have crashed PSES | ||
var longUriForm = "gitlens-git:c%3A%5CUsers%5CKeith%5CGitHub%5Cdahlbyk%5Cposh-git%5Csrc%5CPoshGitTypes%3Ae0022701.ps1?%7B%22fileName%22%3A%22src%2FPoshGitTypes.ps1%22%2C%22repoPath%22%3A%22c%3A%2FUsers%2FKeith%2FGitHub%2Fdahlbyk%2Fposh-git%22%2C%22sha%22%3A%22e0022701fa12e0bc22d0458673d6443c942b974a%22%7D"; | ||
Assert.True(Workspace.IsPathInMemory(longUriForm)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think you could refactor this test to be an array and an assert? Something like: var testCases = new[]{
{ Path = "foo.ps1", IsInMemory = false },
{ Path = Path.Combine(tempDir, "GitHub", "PowerShellEditorServices"), IsInMemory = false },
{ Path = new Uri(shortDirPath).ToString(), IsInMemory = false }
}
foreach (var testCase in testCases) {
Assert.IsEqual(Worspace.IsPathInMemory(testCase.Path), testCase.IsInMemory);
} I think it's a little cleaner and involves writing less Asserts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can make that change (have actually) but when a test fails, we only get this:
And the line number with no indication of which test case failed. I could do a Debug.WriteLine of the Path being tested. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think I have a solution to that last issue - found an Assert method that allows me to specify a message to emit when the assert fails. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe combine these into 1 line since
uri
isn't used? I don't feel strongly either way but it's something I thought about.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having
uri
as a variable makes it easier to inspect the entire URI when debugging - not just the resulting string.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point 👍