Skip to content

Commit a67e557

Browse files
committed
Fix falsely passing PowerShellVersionTests
This change fixes the current PowerShellVersionTests to use an absolute path to the version-specific PowerShell reference assembly. The relative path which was being used somehow caused MSBuild to use the in-box PowerShell v5 assemblies since the HintPath couldn't be found. This caused the tests for PowerShell 3 and 4 to pass even though they should be failing. This change also includes some fixes to existing code that is incompatible with PowerShell 3 and 4.
1 parent bc9473c commit a67e557

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/PowerShellEditorServices/Language/AstOperations.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,24 @@ static public SymbolReference FindDefinitionOfSymbol(
180180
/// <returns>A collection of SymbolReference objects</returns>
181181
static public IEnumerable<SymbolReference> FindSymbolsInDocument(Ast scriptAst, Version powerShellVersion)
182182
{
183+
IEnumerable<SymbolReference> symbolReferences = null;
184+
183185
if (powerShellVersion >= new Version(5,0))
184186
{
187+
#if PowerShellv5
185188
FindSymbolsVisitor2 findSymbolsVisitor = new FindSymbolsVisitor2();
186189
scriptAst.Visit(findSymbolsVisitor);
187-
return findSymbolsVisitor.SymbolReferences;
190+
symbolReferences = findSymbolsVisitor.SymbolReferences;
191+
#endif
188192
}
189193
else
190194
{
191195
FindSymbolsVisitor findSymbolsVisitor = new FindSymbolsVisitor();
192196
scriptAst.Visit(findSymbolsVisitor);
193-
return findSymbolsVisitor.SymbolReferences;
197+
symbolReferences = findSymbolsVisitor.SymbolReferences;
194198
}
199+
200+
return symbolReferences;
195201
}
196202

197203
/// <summary>

src/PowerShellEditorServices/Language/FindSymbolsVisitor2.cs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Microsoft.PowerShell.EditorServices
55
{
6+
#if PowerShellv5
67
/// <summary>
78
/// The visitor used to find all the symbols (function and class defs) in the AST.
89
/// </summary>
@@ -67,4 +68,5 @@ public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinit
6768
return AstVisitAction.Continue;
6869
}
6970
}
71+
#endif
7072
}

test/PowerShellEditorServices.Test/Language/PowerShellVersionTests.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ public class PowerShellVersionTests
1616
[InlineData("5")]
1717
public void CompilesWithPowerShellVersion(string version)
1818
{
19-
var assemblyPath = string.Format(@"..\..\..\..\packages\Microsoft.PowerShell.{0}.ReferenceAssemblies.1.0.0\lib\net4\System.Management.Automation.dll", version);
19+
var assemblyPath =
20+
Path.GetFullPath(
21+
string.Format(
22+
@"..\..\..\..\packages\Microsoft.PowerShell.{0}.ReferenceAssemblies.1.0.0\lib\net4\System.Management.Automation.dll",
23+
version));
24+
2025
var projectPath = @"..\..\..\..\src\PowerShellEditorServices\PowerShellEditorServices.csproj";
2126
FileInfo fi = new FileInfo(projectPath);
2227
var projectVersion = Path.Combine(fi.DirectoryName, version + ".PowerShellEditorServices.csproj");

0 commit comments

Comments
 (0)