File tree 5 files changed +70
-4
lines changed
module/PowerShellEditorServices
src/PowerShellEditorServices/Services/Symbols
PowerShellEditorServices.Test/Language
PowerShellEditorServices.Test.Shared/Symbols
5 files changed +70
-4
lines changed Original file line number Diff line number Diff line change @@ -59,10 +59,24 @@ param(
59
59
[string ] $OutputPath
60
60
)
61
61
62
- $pesterModule = Microsoft.PowerShell.Core\Get-Module Pester
63
62
# add one line, so the subsequent output is not shifted to the side
64
63
Write-Output ' '
65
64
65
+ # checking and importing PSKoans first as it will import the required Pester-version (v4 vs v5)
66
+ if ($ScriptPath -match ' \.Koans\.ps1$' ) {
67
+ $psKoansModule = Microsoft.PowerShell.Core\Get-Module PSKoans
68
+ if (! $psKoansModule ) {
69
+ Write-Output " Importing PSKoans module..."
70
+ $psKoansModule = Microsoft.PowerShell.Core\Import-Module PSKoans - ErrorAction Ignore - PassThru
71
+ }
72
+
73
+ if (! $psKoansModule ) {
74
+ Write-Warning " Failed to import PSKoans. You must install PSKoans module to run or debug tests in *.Koans.ps1 files."
75
+ return
76
+ }
77
+ }
78
+
79
+ $pesterModule = Microsoft.PowerShell.Core\Get-Module Pester
66
80
if (! $pesterModule ) {
67
81
Write-Output " Importing Pester module..."
68
82
if ($MinimumVersion5 ) {
Original file line number Diff line number Diff line change @@ -20,9 +20,8 @@ internal class PesterDocumentSymbolProvider : IDocumentSymbolProvider
20
20
IEnumerable < SymbolReference > IDocumentSymbolProvider . ProvideDocumentSymbols (
21
21
ScriptFile scriptFile )
22
22
{
23
- if ( ! scriptFile . FilePath . EndsWith (
24
- "tests.ps1" ,
25
- StringComparison . OrdinalIgnoreCase ) )
23
+ if ( ! scriptFile . FilePath . EndsWith ( ".tests.ps1" , StringComparison . OrdinalIgnoreCase ) &&
24
+ ! scriptFile . FilePath . EndsWith ( ".Koans.ps1" , StringComparison . OrdinalIgnoreCase ) )
26
25
{
27
26
return Enumerable . Empty < SymbolReference > ( ) ;
28
27
}
Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
5
+
6
+ namespace Microsoft . PowerShell . EditorServices . Test . Shared . Symbols
7
+ {
8
+ public static class FindSymbolsInPSKoansFile
9
+ {
10
+ public static readonly ScriptRegion SourceDetails =
11
+ new (
12
+ file : TestUtilities . NormalizePath ( "Symbols/PesterFile.Koans.ps1" ) ,
13
+ text : string . Empty ,
14
+ startLineNumber : 0 ,
15
+ startColumnNumber : 0 ,
16
+ startOffset : 0 ,
17
+ endLineNumber : 0 ,
18
+ endColumnNumber : 0 ,
19
+ endOffset : 0 ) ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ Describe " Testing Pester symbols in a PSKoans-file" {
2
+ Context " Simple demo" {
3
+ BeforeAll {
4
+
5
+ }
6
+
7
+ BeforeEach {
8
+
9
+ }
10
+
11
+ It " Should return Pester symbols" {
12
+
13
+ }
14
+
15
+ AfterEach {
16
+
17
+ }
18
+ }
19
+
20
+ AfterAll {
21
+
22
+ }
23
+ }
Original file line number Diff line number Diff line change @@ -890,6 +890,15 @@ public void FindsSymbolsInPesterFile()
890
890
Assert . Equal ( 5 , symbol . ScriptRegion . StartColumnNumber ) ;
891
891
}
892
892
893
+ [ Fact ]
894
+ public void FindsSymbolsInPSKoansFile ( )
895
+ {
896
+ IEnumerable < PesterSymbolReference > symbols = FindSymbolsInFile ( FindSymbolsInPSKoansFile . SourceDetails ) . OfType < PesterSymbolReference > ( ) ;
897
+
898
+ // Pester symbols are properly tested in FindsSymbolsInPesterFile so only counting to make sure they appear
899
+ Assert . Equal ( 7 , symbols . Count ( i => i . Type == SymbolType . Function ) ) ;
900
+ }
901
+
893
902
[ Fact ]
894
903
public void FindsSymbolsInPSDFile ( )
895
904
{
You can’t perform that action at this time.
0 commit comments