Last active
February 3, 2018 13:08
-
-
Save mattmcnabb/ffbd12d1874d21b411c3f455bde630ce to your computer and use it in GitHub Desktop.
Get canonical path in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-cPath | |
{ | |
param | |
( | |
$Path | |
) | |
if (!([System.Io.File]::Exists($Path) -or [System.Io.Directory]::Exists($Path))) | |
{ | |
return $Path | |
} | |
$Dir = [System.IO.DirectoryInfo]::new($Path) | |
if ($Dir.Parent -ne $null) | |
{ | |
Join-Path (Get-cPath -Path $Dir.Parent.FullName) ($Dir.Parent.GetFileSystemInfos($Dir.Name)[0].Name) | |
} | |
else | |
{ | |
$Dir.Name.ToUpper() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Describe "PSCore" { | |
# test that the module folder and module file names match case | |
# this is important for cross-compatibility with Unix-like operating systems | |
$FolderName = Get-Item (Get-CanonicalPath $BuildModulePath) | Select -ExpandProperty BaseName | |
$ManifestFileName = Get-Item (Get-CanonicalPath $BuildManifestPath) | Select -ExpandProperty BaseName | |
$ModuleFileName = Get-Item (Get-CanonicalPath $BuildPsm1Path) | Select -ExpandProperty BaseName | |
It "manifest name matches folder name (case-sensitive)" { | |
$FolderName | Should MatchExactly $ManifestFileName | |
} | |
It "module name matches folder name (case-sensitive)" { | |
$FolderName | Should MatchExactly $ModuleFileName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment