-
Notifications
You must be signed in to change notification settings - Fork 234
Refactor pester script detection #638
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
Conversation
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.
You might think about adding a test around here - https://github.com/PowerShell/PowerShellEditorServices/blob/master/test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs#L305
I always like to see the test fail first, then after I fix the issue the test should pass.
@rkeithhill Perfect! Didn't realise we had testing for this! I will write a couple of tests and open a PR on that. |
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.
Just a couple of questions, otherwise, LGTM! Awesome that you fixed this :) Let's give @SeeminglyScience a day to see if he wants to look at this since I know ASTs are his thing.
// Find plausible Pester commands | ||
IEnumerable<Ast> commandAsts = scriptFile.ScriptAst.FindAll(IsNamedCommandWithArguments, true); | ||
|
||
return commandAsts.OfType<CommandAst>() |
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.
can commandAsts
ever be null on accident? It looks like there was that commandant != null
check previously
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.
FindAll
promises to return a possibly empty collection, but not null
|
||
return | ||
commandAst != null && | ||
ast is CommandAst commandAst && |
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.
Can ast ever been null on accident? This one I'm pretty sure is no but figured I'd ask.
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.
LGTM, just a couple optional suggestions.
} | ||
// Ensure the first word is a Pester keyword | ||
if (!(commandAst.CommandElements[0] is StringConstantExpressionAst pesterKeywordAst && | ||
PesterSymbolReference.PesterKeywords.ContainsKey(pesterKeywordAst.Value))) |
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.
CommandAst.GetCommandName()
might be a little cleaner here.
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.
Yes I just saw that on something else. Will change it over
if (stringAst == null) | ||
// Search for a name for the test | ||
string testName = null; | ||
for (int i = 1; i < pesterCommandAst.CommandElements.Count; i++) |
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.
StaticParameterBinder.BindCommand()
is excellent for this type of analysis. Might not be available in PowerShell 3 though.
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.
Is there an easy way to find out? I don't really know where I could get a PowerShell v3 instance to run
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.
Is there an easy way to find out?
It'll fail to compile when it tries to build using the v3 reference libs. It won't show any syntax markers because of the compiler directives though, and that's a huge pain.
I don't really know where I could get a PowerShell v3 instance to run
I just have a Windows 7 VM set up in my home lab that I manually upgraded from 2 to 3. It's annoying, but works.
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.
@rjmholt I've got a Windows Server VM for each major version of PowerShell on my Azure subscription. They're all turned off and deallocated (saving that $$$) until needed.
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.
@tylerl0706 Excellent!
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.
If you need me to test something, I can 😄 just give me the script to run. Otherwise, tomorrow I'll add you to those VMs so we can just share them.
Ok, I'm going to merge this one |
Enable debugging of untitled script files
Fixes vscode-powershell #1223.
Previously, Pester test parsing by PSES has made a couple of assumptions that didn't hold and as a result it wouldn't recognise tests with tags.
Now we do all of that, and are even set up to add something like tag-awareness in future more easily.