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

Add regression test for untitled scripts in Windows PowerShell #1830

Merged
merged 7 commits into from
Jun 15, 2022

Conversation

andyleejordan
Copy link
Member

Specifically targeting the edge case where the last line of the script is a comment. Covers PowerShell/vscode-powershell#3965

Since we could theoretically receive any complicated string.
Specifically, just a raw script.
We were depending on the test run to succeed in order to create and
overwrite the file; however, this was very confusing when debugging a
single test while it was failing.
@andyleejordan andyleejordan added Issue-Enhancement A feature request (enhancement). Area-Test labels Jun 15, 2022
@andyleejordan andyleejordan requested a review from a team June 15, 2022 18:47
Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! gj figuring this one out 😁 did not sound fun!

@andyleejordan
Copy link
Member Author

@SeeminglyScience could you please re-review?

Comment on lines +207 to +208
return Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute) &&
!string.Equals(DocumentUri.From(path).Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-check me here please. As far as I can tell, this is expecting a URI?

Comment on lines +155 to +167
public bool TryGetFile(string filePath, out ScriptFile scriptFile)
{
// This might not have been given a file path, in which case the Uri constructor barfs.
try
{
return TryGetFile(new Uri(filePath), out scriptFile);
}
catch (UriFormatException)
{
scriptFile = null;
return false;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this one to catch the exception instead of using Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute) since the path we were being given was like \\foo\\bar, which makes me hesitant about the above too.

@@ -651,6 +651,7 @@ public void DocumentUriReturnsCorrectStringForAbsolutePath()
[InlineData("vscode-notebook-cell:/Users/me/Documents/test.ps1#0001", true)]
[InlineData("https://microsoft.com", true)]
[InlineData("Untitled:Untitled-1", true)]
[InlineData("'a log statement' > 'c:\\Users\\me\\Documents\\test.txt'\r\n", false)]
public void IsUntitledFileIsCorrect(string path, bool expected) => Assert.Equal(expected, ScriptFile.IsUntitledPath(path));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See, this test implies that the function is asking "is this path a URI that indicates we're untitled?"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should expect this case to be true by flipping the logic with IsWellFormedUri. That is, if we're given something that is not a URI, assume it's untitled, but I'm not sure that would work for the first two cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, doesn't work, since /Users/me/Documents/test.ps1 is not a URI.

@andyleejordan
Copy link
Member Author

Tests are passing, but I'm not super happy with it.

@SeeminglyScience SeeminglyScience merged commit 10cff26 into master Jun 15, 2022
@SeeminglyScience SeeminglyScience deleted the andschwa/untitled-tests branch June 15, 2022 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Test Issue-Enhancement A feature request (enhancement).
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants