File tree Expand file tree Collapse file tree 5 files changed +70
-4
lines changed
module/PowerShellEditorServices
src/PowerShellEditorServices/Services/Symbols
PowerShellEditorServices.Test.Shared/Symbols
PowerShellEditorServices.Test/Language Expand file tree Collapse file tree 5 files changed +70
-4
lines changed Original file line number Diff line number Diff line change @@ -59,10 +59,24 @@ param(
5959 [string ] $OutputPath
6060)
6161
62- $pesterModule = Microsoft.PowerShell.Core\Get-Module Pester
6362# add one line, so the subsequent output is not shifted to the side
6463Write-Output ' '
6564
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
6680if (! $pesterModule ) {
6781 Write-Output " Importing Pester module..."
6882 if ($MinimumVersion5 ) {
Original file line number Diff line number Diff line change @@ -20,9 +20,8 @@ internal class PesterDocumentSymbolProvider : IDocumentSymbolProvider
2020 IEnumerable < SymbolReference > IDocumentSymbolProvider . ProvideDocumentSymbols (
2121 ScriptFile scriptFile )
2222 {
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 ) )
2625 {
2726 return Enumerable . Empty < SymbolReference > ( ) ;
2827 }
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()
890890 Assert . Equal ( 5 , symbol . ScriptRegion . StartColumnNumber ) ;
891891 }
892892
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+
893902 [ Fact ]
894903 public void FindsSymbolsInPSDFile ( )
895904 {
You can’t perform that action at this time.
0 commit comments