2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "Environment-Variables" -Tags "CI" {
|
2015-12-28 11:05:48 -08:00
|
|
|
|
2015-08-24 11:38:32 -07:00
|
|
|
It "Should have environment variables" {
|
2020-01-14 10:24:26 -08:00
|
|
|
Get-Item ENV: | Should -Not -BeNullOrEmpty
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-24 15:04:50 -07:00
|
|
|
It "Should have a nonempty PATH" {
|
2020-01-14 10:24:26 -08:00
|
|
|
$ENV:PATH | Should -Not -BeNullOrEmpty
|
2015-08-24 15:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should contain /bin in the PATH" {
|
2020-01-14 10:24:26 -08:00
|
|
|
if ($IsWindows) {
|
|
|
|
|
$ENV:PATH | Should -Match "C:"
|
|
|
|
|
} else {
|
|
|
|
|
$ENV:PATH | Should -Match "/bin"
|
|
|
|
|
}
|
2015-08-24 15:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-05 10:11:38 -08:00
|
|
|
It "Should have the correct HOME" {
|
2020-01-14 10:24:26 -08:00
|
|
|
if ($IsWindows) {
|
|
|
|
|
# \Windows\System32 is found as $env:HOMEPATH for temporary profiles
|
|
|
|
|
$expected = "\Users", "\Windows"
|
|
|
|
|
Split-Path $ENV:HOMEPATH -Parent | Should -BeIn $expected
|
|
|
|
|
} else {
|
|
|
|
|
$expected = /bin/bash -c "cd ~ && pwd"
|
|
|
|
|
$ENV:HOME | Should -Be $expected
|
|
|
|
|
}
|
2015-08-24 11:38:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to set the environment variables" {
|
2020-01-14 10:24:26 -08:00
|
|
|
$expected = "this is a test environment variable"
|
|
|
|
|
{ $ENV:TESTENVIRONMENTVARIABLE = $expected } | Should -Not -Throw
|
2015-08-24 11:38:32 -07:00
|
|
|
|
2020-01-14 10:24:26 -08:00
|
|
|
$ENV:TESTENVIRONMENTVARIABLE | Should -Not -BeNullOrEmpty
|
|
|
|
|
$ENV:TESTENVIRONMENTVARIABLE | Should -Be $expected
|
2015-07-16 15:52:42 -07:00
|
|
|
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
2020-01-14 10:24:26 -08:00
|
|
|
|
|
|
|
|
Context "~ in PATH" {
|
|
|
|
|
AfterEach {
|
|
|
|
|
$env:PATH = $oldPath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$oldPath = $env:PATH
|
|
|
|
|
$pwsh = (Get-Command pwsh | Select-Object -First 1).Source
|
|
|
|
|
if ($IsWindows) {
|
|
|
|
|
$pwsh2 = "pwsh2.exe"
|
|
|
|
|
} else {
|
|
|
|
|
$pwsh2 = "pwsh2"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Copy-Item -Path $pwsh -Destination "~/$pwsh2"
|
|
|
|
|
$testPath = Join-Path -Path "~" -ChildPath (New-Guid)
|
|
|
|
|
New-Item -Path $testPath -ItemType Directory > $null
|
|
|
|
|
Copy-Item -Path $pwsh -Destination "$testPath/$pwsh2"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterAll {
|
|
|
|
|
Remove-Item -Path "~/pwsh2" -Force
|
|
|
|
|
Remove-Item -Path $testPath -Recurse -Force
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to resolve ~ in PATH" {
|
|
|
|
|
$env:PATH = "~" + [System.IO.Path]::PathSeparator + $env:PATH
|
|
|
|
|
$out = Get-Command pwsh2
|
|
|
|
|
$out.Source | Should -BeExactly (Join-Path -Path ([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)) -ChildPath $pwsh2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to resolve ~/folder in PATH" {
|
|
|
|
|
$env:PATH = $testPath + [System.IO.Path]::PathSeparator + $env:PATH
|
|
|
|
|
$out = Get-Command pwsh2
|
|
|
|
|
$out.Source | Should -BeExactly (Join-Path -Path (Resolve-Path $testPath) -ChildPath $pwsh2)
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-16 15:52:42 -07:00
|
|
|
}
|