@@ -36,13 +36,13 @@ Describe "TabCompletion" -Tags CI {
3636 It ' Should not include duplicate command results' {
3737 $OldModulePath = $env: PSModulePath
3838 $tempDir = Join-Path - Path $TestDrive - ChildPath " TempPsModuleDir"
39+ $ModuleDirs = @ (
40+ Join-Path $tempDir " TestModule1\1.0"
41+ Join-Path $tempDir " TestModule1\1.1"
42+ Join-Path $tempDir " TestModule2\1.0"
43+ )
3944 try
4045 {
41- $ModuleDirs = @ (
42- Join-Path $tempDir " TestModule1\1.0"
43- Join-Path $tempDir " TestModule1\1.1"
44- Join-Path $tempDir " TestModule2\1.0"
45- )
4646 foreach ($Dir in $ModuleDirs )
4747 {
4848 $NewDir = New-Item - Path $Dir - ItemType Directory - Force
@@ -61,6 +61,36 @@ Describe "TabCompletion" -Tags CI {
6161 finally
6262 {
6363 $env: PSModulePath = $OldModulePath
64+ Remove-Item - LiteralPath $ModuleDirs - Recurse - Force
65+ }
66+ }
67+
68+ It ' Should not include duplicate module results' {
69+ $OldModulePath = $env: PSModulePath
70+ $tempDir = Join-Path - Path $TestDrive - ChildPath " TempPsModuleDir"
71+ try
72+ {
73+ $ModuleDirs = @ (
74+ Join-Path $tempDir " TestModule1\1.0"
75+ Join-Path $tempDir " TestModule1\1.1"
76+ )
77+ foreach ($Dir in $ModuleDirs )
78+ {
79+ $NewDir = New-Item - Path $Dir - ItemType Directory - Force
80+ $ModuleName = $NewDir.Parent.Name
81+ Set-Content - Value ' MyTestFunction{}' - LiteralPath " $ ( $NewDir.FullName ) \$ModuleName .psm1"
82+ New-ModuleManifest - Path " $ ( $NewDir.FullName ) \$ModuleName .psd1" - RootModule " $ModuleName .psm1" - FunctionsToExport " MyTestFunction" - ModuleVersion $NewDir.Name
83+ }
84+
85+ $env: PSModulePath += [System.IO.Path ]::PathSeparator + $tempDir
86+ $Res = TabExpansion2 - inputScript ' Import-Module -Name TestModule'
87+ $Res.CompletionMatches.Count | Should - Be 1
88+ $Res.CompletionMatches [0 ].CompletionText | Should - Be TestModule1
89+ }
90+ finally
91+ {
92+ $env: PSModulePath = $OldModulePath
93+ Remove-Item - LiteralPath $ModuleDirs - Recurse - Force
6494 }
6595 }
6696
0 commit comments