tests now run clean on Windows and Linux

This commit is contained in:
James Truher 2016-07-19 18:13:47 -07:00
parent 2674564542
commit b680b48160
4 changed files with 251 additions and 244 deletions

View file

@ -673,7 +673,7 @@ Describe 'Type building' -Tags "DRT" {
Describe 'RuntimeType created for TypeDefinitionAst' {
It 'can make cast to the right RuntimeType in two different contexts' {
It 'can make cast to the right RuntimeType in two different contexts' -pending {
$ssfe = [System.Management.Automation.Runspaces.SessionStateFunctionEntry]::new("foo", @'
class Base
@ -689,7 +689,7 @@ class Derived : Base
[Derived]::new().foo()
'@)
$iss = [System.Management.Automation.Runspaces.initialsessionstate]::CreateDefault()
$iss = [System.Management.Automation.Runspaces.initialsessionstate]::CreateDefault2()
$iss.Commands.Add($ssfe)
$ps = [powershell]::Create($iss)
@ -745,7 +745,7 @@ namespace Foo
}
'@
It 'doesn''t allow protected methods access outside of inheritance chain' {
It 'doesn''t allow protected methods access outside of inheritance chain' -pending {
$a = [scriptblock]::Create(@'
class A
{

View file

@ -1,85 +1,89 @@
Describe 'using module' -Tags "DRT" {
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
function New-TestModule {
param(
[string]$Name,
[string]$Content,
[switch]$Manifest,
[version]$Version = '1.0', # ignored, if $Manifest -eq $false
[string]$ModulePathPrefix = 'modules' # module is created under TestDrive:\$ModulePathPrefix\$Name
)
Describe 'using module' -Tags "CI" {
BeforeAll {
$originalPSMODULEPATH = $env:PSMODULEPATH
if ($manifest) {
new-item -type directory -Force "${TestDrive}\$ModulePathPrefix\$Name\$Version" > $null
Set-Content -Path "${TestDrive}\$ModulePathPrefix\$Name\$Version\$Name.psm1" -Value $Content
New-ModuleManifest -RootModule "$Name.psm1" -Path "${TestDrive}\$ModulePathPrefix\$Name\$Version\$Name.psd1" -ModuleVersion $Version
} else {
new-item -type directory -Force "${TestDrive}\$ModulePathPrefix\$Name" > $null
Set-Content -Path "${TestDrive}\$ModulePathPrefix\$Name\$Name.psm1" -Value $Content
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
function New-TestModule {
param(
[string]$Name,
[string]$Content,
[switch]$Manifest,
[version]$Version = '1.0', # ignored, if $Manifest -eq $false
[string]$ModulePathPrefix = 'modules' # module is created under TestDrive:\$ModulePathPrefix\$Name
)
if ($manifest) {
new-item -type directory -Force "${TestDrive}\$ModulePathPrefix\$Name\$Version" > $null
Set-Content -Path "${TestDrive}\$ModulePathPrefix\$Name\$Version\$Name.psm1" -Value $Content
New-ModuleManifest -RootModule "$Name.psm1" -Path "${TestDrive}\$ModulePathPrefix\$Name\$Version\$Name.psd1" -ModuleVersion $Version
} else {
new-item -type directory -Force "${TestDrive}\$ModulePathPrefix\$Name" > $null
Set-Content -Path "${TestDrive}\$ModulePathPrefix\$Name\$Name.psm1" -Value $Content
}
$resolvedTestDrivePath = Split-Path ((get-childitem "${TestDrive}\$ModulePathPrefix")[0].FullName)
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
$env:PSMODULEPATH += ";$resolvedTestDrivePath"
}
}
$resolvedTestDrivePath = Split-Path ((get-childitem "${TestDrive}\$ModulePathPrefix")[0].FullName)
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
$env:PSMODULEPATH += ";$resolvedTestDrivePath"
}
}
$originalPSMODULEPATH = $env:PSMODULEPATH
AfterAll {
$env:PSMODULEPATH = $originalPSMODULEPATH
}
try {
It 'Import-Module has ImplementedAssembly, when classes are present in the module' {
# Create modules in TestDrive:\
New-TestModule -Name Foo -Content 'class Foo { [string] GetModuleName() { return "Foo" } }'
New-TestModule -Manifest -Name FooWithManifest -Content 'class Foo { [string] GetModuleName() { return "FooWithManifest" } }'
It 'Import-Module has ImplementedAssembly, when classes are present in the module' {
$module = Import-Module Foo -PassThru
try {
$module.ImplementingAssembly | Should Not Be $null
} finally {
$module | Remove-Module
}
$module = Import-Module Foo -PassThru
try {
$module.ImplementingAssembly | Should Not Be $null
} finally {
$module | Remove-Module
}
}
It "can use class from another module as a base class with using module" {
$barType = [scriptblock]::Create(@"
It "can use class from another module as a base class with using module" {
$barType = [scriptblock]::Create(@"
using module Foo
class Bar : Foo {}
[Bar]
"@).Invoke()
$barType.BaseType.Name | Should Be 'Foo'
}
$barType.BaseType.Name | Should Be 'Foo'
}
It "can use class from another module in New-Object" {
$foo = [scriptblock]::Create(@"
It "can use class from another module in New-Object" {
$foo = [scriptblock]::Create(@"
using module FooWithManifest
using module Foo
New-Object FooWithManifest.Foo
New-Object Foo.Foo
"@).Invoke()
$foo.Count | Should Be 2
$foo[0].GetModuleName() | Should Be 'FooWithManifest'
$foo[1].GetModuleName() | Should Be 'Foo'
}
$foo.Count | Should Be 2
$foo[0].GetModuleName() | Should Be 'FooWithManifest'
$foo[1].GetModuleName() | Should Be 'Foo'
}
It "can use class from another module by full name as base class and [type]" {
$fooObject = [scriptblock]::Create(@"
It "can use class from another module by full name as base class and [type]" {
$fooObject = [scriptblock]::Create(@"
using module Foo
class Bar : Foo.Foo {}
[Foo.Foo]::new()
"@).Invoke()
$fooObject.GetModuleName() | Should Be 'Foo'
}
$fooObject.GetModuleName() | Should Be 'Foo'
}
It "can use modules with classes collision" {
# we use 3 classes with name Foo at the same time
# two of them come from 'using module' and one is defined in the scriptblock itself.
# we should be able to use first two of them by the module-quilified name and the third one it's name.
$fooModuleName = [scriptblock]::Create(@"
It "can use modules with classes collision" {
# we use 3 classes with name Foo at the same time
# two of them come from 'using module' and one is defined in the scriptblock itself.
# we should be able to use first two of them by the module-quilified name and the third one it's name.
$fooModuleName = [scriptblock]::Create(@"
using module Foo
using module FooWithManifest
@ -95,21 +99,21 @@ class Bar : Foo {}
(New-Object Foo).GetModuleName() # This
"@).Invoke()
$fooModuleName.Count | Should Be 4
$fooModuleName[0] | Should Be 'Foo'
$fooModuleName[1] | Should Be 'FooWithManifest'
$fooModuleName[2] | Should Be 'This'
$fooModuleName[3] | Should Be 'This'
}
$fooModuleName.Count | Should Be 4
$fooModuleName[0] | Should Be 'Foo'
$fooModuleName[1] | Should Be 'FooWithManifest'
$fooModuleName[2] | Should Be 'This'
$fooModuleName[3] | Should Be 'This'
}
It "doesn't mess up two consequitive scripts" {
$sb1 = [scriptblock]::Create(@"
It "doesn't mess up two consequitive scripts" {
$sb1 = [scriptblock]::Create(@"
using module Foo
class Bar : Foo {}
[Bar]::new().GetModuleName()
"@)
$sb2 = [scriptblock]::Create(@"
$sb2 = [scriptblock]::Create(@"
using module Foo
class Foo { [string] GetModuleName() { return "This" } }
@ -117,12 +121,12 @@ class Bar : Foo {}
[Bar]::new().GetModuleName()
"@)
$sb1.Invoke() | Should Be 'Foo'
$sb2.Invoke() | Should Be 'This'
}
$sb1.Invoke() | Should Be 'Foo'
$sb2.Invoke() | Should Be 'This'
}
It "can use modules with classes collision simple" {
$fooModuleName = [scriptblock]::Create(@"
It "can use modules with classes collision simple" {
$fooModuleName = [scriptblock]::Create(@"
using module Foo
class Foo { [string] GetModuleName() { return "This" } }
@ -137,300 +141,302 @@ class Bar : Foo {}
(New-Object Foo).GetModuleName() # This
"@).Invoke()
$fooModuleName.Count | Should Be 5
$fooModuleName[0] | Should Be 'Foo'
$fooModuleName[1] | Should Be 'Foo'
$fooModuleName[2] | Should Be 'This'
$fooModuleName[3] | Should Be 'This'
$fooModuleName[4] | Should Be 'This'
}
$fooModuleName.Count | Should Be 5
$fooModuleName[0] | Should Be 'Foo'
$fooModuleName[1] | Should Be 'Foo'
$fooModuleName[2] | Should Be 'This'
$fooModuleName[3] | Should Be 'This'
$fooModuleName[4] | Should Be 'This'
}
It "can use class from another module as a base class with using module with manifest" {
$barType = [scriptblock]::Create(@"
It "can use class from another module as a base class with using module with manifest" {
$barType = [scriptblock]::Create(@"
using module FooWithManifest
class Bar : Foo {}
[Bar]
"@).Invoke()
$barType.BaseType.Name | Should Be 'Foo'
}
$barType.BaseType.Name | Should Be 'Foo'
}
It "can instantiate class from another module" {
$foo = [scriptblock]::Create(@"
It "can instantiate class from another module" {
$foo = [scriptblock]::Create(@"
using module Foo
[Foo]::new()
"@).Invoke()
$foo.GetModuleName() | Should Be 'Foo'
}
$foo.GetModuleName() | Should Be 'Foo'
}
It "cannot instantiate class from another module without using statement" {
$err = Get-RuntimeError @"
It "cannot instantiate class from another module without using statement" {
$err = Get-RuntimeError @"
#using module Foo
[Foo]::new()
"@
$err.FullyQualifiedErrorId | Should Be TypeNotFound
}
$err.FullyQualifiedErrorId | Should Be TypeNotFound
}
It "can use class from another module in New-Object by short name" {
$foo = [scriptblock]::Create(@"
It "can use class from another module in New-Object by short name" {
$foo = [scriptblock]::Create(@"
using module FooWithManifest
New-Object Foo
"@).Invoke()
$foo.GetModuleName() | Should Be 'FooWithManifest'
}
$foo.GetModuleName() | Should Be 'FooWithManifest'
}
It "can use class from this module in New-Object by short name" {
$foo = [scriptblock]::Create(@"
It "can use class from this module in New-Object by short name" {
$foo = [scriptblock]::Create(@"
class Foo {}
New-Object Foo
"@).Invoke()
$foo | Should Not Be $null
}
$foo | Should Not Be $null
}
# Pending reason:
# it's not yet implemented.
It "accept module specification" {
$foo = [scriptblock]::Create(@"
# Pending reason:
# it's not yet implemented.
It "accept module specification" {
$foo = [scriptblock]::Create(@"
using module @{ ModuleName = 'FooWithManifest'; ModuleVersion = '1.0' }
New-Object Foo
"@).Invoke()
$foo.GetModuleName() | Should Be 'FooWithManifest'
$foo.GetModuleName() | Should Be 'FooWithManifest'
}
Context 'parse time errors' {
It "report an error about not found module" {
$err = Get-ParseResults "using module ThisModuleDoesntExist"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'ModuleNotFoundDuringParse'
}
Context 'parse time errors' {
It "report an error about not found module" {
$err = Get-ParseResults "using module ThisModuleDoesntExist"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'ModuleNotFoundDuringParse'
}
It "report an error about misformatted module specification" {
$err = Get-ParseResults "using module @{ Foo = 'Foo' }"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'RequiresModuleInvalid'
}
It "report an error about wildcard in the module name" {
$err = Get-ParseResults "using module fo*"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'WildCardModuleNameError'
}
It "report an error about wildcard in the module path" {
$err = Get-ParseResults "using module C:\fo*"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'WildCardModuleNameError'
}
It "report an error about wildcard in the module name inside ModuleSpecification hashtable" {
$err = Get-ParseResults "using module @{ModuleName = 'Fo*'; RequiredVersion = '1.0'}"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'WildCardModuleNameError'
}
# MSFT:5246105
It "report an error when tokenizer encounters comma" {
$err = Get-ParseResults "using module ,FooWithManifest"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'MissingUsingItemName'
}
It "report an error when tokenizer encounters nothing" {
$err = Get-ParseResults "using module "
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'MissingUsingItemName'
}
It "report an error on badly formatted RequiredVersion" {
$err = Get-ParseResults "using module @{ModuleName = 'FooWithManifest'; RequiredVersion = 1. }"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'RequiresModuleInvalid'
}
# MSFT:6897275
It "report an error on incomplete using input" {
$err = Get-ParseResults "using module @{ModuleName = 'FooWithManifest'; FooWithManifest = 1." # missing closing bracket
$err.Count | Should Be 2
$err[0].ErrorId | Should Be 'IncompleteHashLiteral'
$err[1].ErrorId | Should Be 'RequiresModuleInvalid'
}
It "report an error about misformatted module specification" {
$err = Get-ParseResults "using module @{ Foo = 'Foo' }"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'RequiresModuleInvalid'
}
Context 'short name in case of name collision' {
It "cannot use as base class" {
$err = Get-RuntimeError @"
It "report an error about wildcard in the module name" {
$err = Get-ParseResults "using module fo*"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'WildCardModuleNameError'
}
It "report an error about wildcard in the module path" {
$err = Get-ParseResults "using module C:\fo*"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'WildCardModuleNameError'
}
It "report an error about wildcard in the module name inside ModuleSpecification hashtable" {
$err = Get-ParseResults "using module @{ModuleName = 'Fo*'; RequiredVersion = '1.0'}"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'WildCardModuleNameError'
}
# MSFT:5246105
It "report an error when tokenizer encounters comma" {
$err = Get-ParseResults "using module ,FooWithManifest"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'MissingUsingItemName'
}
It "report an error when tokenizer encounters nothing" {
$err = Get-ParseResults "using module "
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'MissingUsingItemName'
}
It "report an error on badly formatted RequiredVersion" {
$err = Get-ParseResults "using module @{ModuleName = 'FooWithManifest'; RequiredVersion = 1. }"
$err.Count | Should Be 1
$err[0].ErrorId | Should Be 'RequiresModuleInvalid'
}
# MSFT:6897275
It "report an error on incomplete using input" {
$err = Get-ParseResults "using module @{ModuleName = 'FooWithManifest'; FooWithManifest = 1." # missing closing bracket
$err.Count | Should Be 2
$err[0].ErrorId | Should Be 'IncompleteHashLiteral'
$err[1].ErrorId | Should Be 'RequiresModuleInvalid'
}
}
Context 'short name in case of name collision' {
It "cannot use as base class" {
$err = Get-RuntimeError @"
using module Foo
using module FooWithManifest
class Bar : Foo {}
"@
$err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference
}
$err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference
}
It "cannot use as [...]" {
$err = Get-RuntimeError @"
It "cannot use as [...]" {
$err = Get-RuntimeError @"
using module Foo
using module FooWithManifest
[Foo]
"@
$err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference
}
$err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference
}
It "cannot use in New-Object" {
$err = Get-RuntimeError @"
It "cannot use in New-Object" {
$err = Get-RuntimeError @"
using module Foo
using module FooWithManifest
New-Object Foo
"@
$err.FullyQualifiedErrorId | Should Be 'AmbiguousTypeReference,Microsoft.PowerShell.Commands.NewObjectCommand'
}
$err.FullyQualifiedErrorId | Should Be 'AmbiguousTypeReference,Microsoft.PowerShell.Commands.NewObjectCommand'
}
It "cannot use [type] cast from string" {
$err = Get-RuntimeError @"
It "cannot use [type] cast from string" {
$err = Get-RuntimeError @"
using module Foo
using module FooWithManifest
[type]"Foo"
"@
$err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference
}
$err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference
}
}
Context 'using use the latest version of module after Import-Module -Force' {
Context 'using use the latest version of module after Import-Module -Force' {
BeforeAll {
New-TestModule -Name Foo -Content 'class Foo { [string] GetModuleName() { return "Foo2" } }'
Import-Module Foo -Force
It "can use class from another module as a base class with using module" {
$moduleName = [scriptblock]::Create(@"
}
It "can use class from another module as a base class with using module" {
$moduleName = [scriptblock]::Create(@"
using module Foo
[Foo]::new().GetModuleName()
"@).Invoke()
$moduleName | Should Be 'Foo2'
}
$moduleName | Should Be 'Foo2'
}
}
Context 'Side by side' {
BeforeAll {
# Add side-by-side module
$newVersion = '3.4.5'
New-TestModule -Manifest -Name FooWithManifest -Content 'class Foo { [string] GetModuleName() { return "Foo230" } }' -Version '2.3.0'
New-TestModule -Manifest -Name FooWithManifest -Content 'class Foo { [string] GetModuleName() { return "Foo345" } }' -Version '3.4.5' -ModulePathPrefix 'Modules2'
}
# 'using module' behavior must be alligned with Import-Module.
# Import-Module does the following:
# 1) find the first directory from $env:PSMODULEPATH that contains the module
# 2) Import highest available version of the module
# In out case TestDrive:\Module is before TestDrive:\Modules2 and so 2.3.0 is the right version
It "uses the last module, if multiple versions are present" {
$foo = [scriptblock]::Create(@"
# 'using module' behavior must be alligned with Import-Module.
# Import-Module does the following:
# 1) find the first directory from $env:PSMODULEPATH that contains the module
# 2) Import highest available version of the module
# In out case TestDrive:\Module is before TestDrive:\Modules2 and so 2.3.0 is the right version
It "uses the last module, if multiple versions are present" {
$foo = [scriptblock]::Create(@"
using module FooWithManifest
[Foo]::new()
"@).Invoke()
$foo.GetModuleName() | Should Be 'Foo230'
}
$foo.GetModuleName() | Should Be 'Foo230'
}
It "uses right version, when RequiredModule=1.0 specified" {
$foo = [scriptblock]::Create(@"
It "uses right version, when RequiredModule=1.0 specified" {
$foo = [scriptblock]::Create(@"
using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '1.0'}
[Foo]::new()
"@).Invoke()
$foo.GetModuleName() | Should Be 'FooWithManifest'
}
$foo.GetModuleName() | Should Be 'FooWithManifest'
}
It "uses right version, when RequiredModule=2.3.0 specified" {
$foo = [scriptblock]::Create(@"
It "uses right version, when RequiredModule=2.3.0 specified" {
$foo = [scriptblock]::Create(@"
using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '2.3.0'}
[Foo]::new()
"@).Invoke()
$foo.GetModuleName() | Should Be 'Foo230'
}
$foo.GetModuleName() | Should Be 'Foo230'
}
It "uses right version, when RequiredModule=3.4.5 specified" {
$foo = [scriptblock]::Create(@"
It "uses right version, when RequiredModule=3.4.5 specified" {
$foo = [scriptblock]::Create(@"
using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '3.4.5'}
[Foo]::new()
"@).Invoke()
$foo.GetModuleName() | Should Be 'Foo345'
}
$foo.GetModuleName() | Should Be 'Foo345'
}
}
Context 'Use module with runtime error' {
Context 'Use module with runtime error' {
BeforeAll {
New-TestModule -Name ModuleWithRuntimeError -Content @'
class Foo { [string] GetModuleName() { return "ModuleWithRuntimeError" } }
throw 'error'
'@
}
It "handles runtime errors in imported module" {
$err = Get-RuntimeError @"
It "handles runtime errors in imported module" {
$err = Get-RuntimeError @"
using module ModuleWithRuntimeError
[Foo]::new().GetModuleName()
"@
$err | Should Be 'error'
}
}
}
Context 'shared InitialSessionState' {
Context 'shared InitialSessionState' {
It 'can pick the right module' {
It 'can pick the right module' {
$scriptToProcessPath = "${TestDrive}\toProcess.ps1"
Set-Content -Path $scriptToProcessPath -Value @'
$scriptToProcessPath = "${TestDrive}\toProcess.ps1"
Set-Content -Path $scriptToProcessPath -Value @'
using module Foo
function foo()
{
[Foo]::new()
}
'@
# resolve name to absolute path
$scriptToProcessPath = (get-childitem $scriptToProcessPath).FullName
$iss = [System.Management.Automation.Runspaces.initialsessionstate]::CreateDefault()
$iss.StartupScripts.Add($scriptToProcessPath)
# resolve name to absolute path
$scriptToProcessPath = (get-childitem $scriptToProcessPath).FullName
$iss = [System.Management.Automation.Runspaces.initialsessionstate]::CreateDefault()
$iss.StartupScripts.Add($scriptToProcessPath)
$ps = [powershell]::Create($iss)
$ps.AddCommand("foo").Invoke() | Should be Foo
$ps.Streams.Error | Should Be $null
$ps = [powershell]::Create($iss)
$ps.AddCommand("foo").Invoke() | Should be Foo
$ps.Streams.Error | Should Be $null
$ps1 = [powershell]::Create($iss)
$ps1.AddCommand("foo").Invoke() | Should be Foo
$ps1.Streams.Error | Should Be $null
$ps1 = [powershell]::Create($iss)
$ps1.AddCommand("foo").Invoke() | Should be Foo
$ps1.Streams.Error | Should Be $null
$ps.Commands.Clear()
$ps.Streams.Error.Clear()
$ps.AddScript(". foo").Invoke() | Should be Foo
$ps.Streams.Error | Should Be $null
}
$ps.Commands.Clear()
$ps.Streams.Error.Clear()
$ps.AddScript(". foo").Invoke() | Should be Foo
$ps.Streams.Error | Should Be $null
}
# this is a setup for Context "Module by path"
New-TestModule -Name FooForPaths -Content 'class Foo { [string] GetModuleName() { return "FooForPaths" } }'
} finally {
$env:PSMODULEPATH = $originalPSMODULEPATH
}
# here we are back to normal $env:PSMODULEPATH, but all modules are there
Context "Module by path" {
BeforeAll {
# this is a setup for Context "Module by path"
New-TestModule -Name FooForPaths -Content 'class Foo { [string] GetModuleName() { return "FooForPaths" } }'
$env:PSMODULEPATH = $originalPSMODULEPATH
It 'use non-modified PSMODULEPATH' {
$env:PSMODULEPATH | Should Be $originalPSMODULEPATH
}
new-item -type directory -Force TestDrive:\FooRelativeConsumer
Set-Content -Path "${TestDrive}\FooRelativeConsumer\FooRelativeConsumer.ps1" -Value @'
new-item -type directory -Force TestDrive:\FooRelativeConsumer
Set-Content -Path "${TestDrive}\FooRelativeConsumer\FooRelativeConsumer.ps1" -Value @'
using module ..\modules\FooForPaths
class Bar : Foo {}
[Bar]::new()
'@
Set-Content -Path "${TestDrive}\FooRelativeConsumerErr.ps1" -Value @'
Set-Content -Path "${TestDrive}\FooRelativeConsumerErr.ps1" -Value @'
using module FooForPaths
class Bar : Foo {}
[Bar]::new()
'@
}
It 'use non-modified PSMODULEPATH' {
$env:PSMODULEPATH | Should Be $originalPSMODULEPATH
}
It "can be accessed by relative path" {
$barObject = & TestDrive:\FooRelativeConsumer\FooRelativeConsumer.ps1

View file

@ -1,3 +1,4 @@
$powershellexe = (get-process -id $PID).mainmodule.filename
Describe "Clone array" -Tags "CI" {
It "Cast in target expr" {
@ -38,7 +39,7 @@ Describe "MSFT:3309783" -Tags "CI" {
It "Run in another process" {
# For a reliable test, we must run this in a new process because an earlier binding in this process
# could mask the bug/fix.
powershell -noprofile -command "[psobject] | % FullName" | Should Be System.Management.Automation.PSObject
& $powershellexe -noprofile -command "[psobject] | % FullName" | Should Be System.Management.Automation.PSObject
}
It "Run in current process" {
@ -101,7 +102,7 @@ Describe "Hashtable key property syntax" -Tags "CI" {
It "In different process" {
# So also run in a fresh process
$bytes = [System.Text.Encoding]::Unicode.GetBytes($script)
powershell -noprofile -encodedCommand ([Convert]::ToBase64String($bytes)) | Should Be Hello
& $powershellexe -noprofile -encodedCommand ([Convert]::ToBase64String($bytes)) | Should Be Hello
}
}