Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Last active February 3, 2018 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmcnabb/ffbd12d1874d21b411c3f455bde630ce to your computer and use it in GitHub Desktop.
Save mattmcnabb/ffbd12d1874d21b411c3f455bde630ce to your computer and use it in GitHub Desktop.
Get canonical path in PowerShell
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()
}
}
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