diff --git a/.github/workflows/source-shell-functions.yml b/.github/workflows/source-shell-functions.yml new file mode 100644 index 0000000..071d0d1 --- /dev/null +++ b/.github/workflows/source-shell-functions.yml @@ -0,0 +1,15 @@ +name: Shell-Functions source checks +on: + push: + branches: [fix/build-shell-functions] + pull_request: + branches: [Shell-Functions/develop] +permissions: + contents: read +jobs: + source: + uses: stadub/PowershellScripts/.github/workflows/validate-module-source.yml@d3fa5897213e3ff4e0d64897559bdfb516356512 + with: + module: Shell-Functions + source_sha: ${{ github.event.pull_request.head.sha || github.sha }} + automation_sha: d3fa5897213e3ff4e0d64897559bdfb516356512 diff --git a/.gitignore b/.gitignore index 931f30c..e4d962c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # File types to ignore globally .history .vscode +TestResults/ diff --git a/Shell-Functions/README.md b/Shell-Functions/README.md new file mode 100644 index 0000000..87e8e26 --- /dev/null +++ b/Shell-Functions/README.md @@ -0,0 +1,17 @@ +# Shell-Functions source module + +Import Shell-Function.psd1 to load the existing shell filters and helpers. The +manifest previously imported nothing and exported no commands. The loader now +exports seven existing functions and seven aliases without global-scope alias +writes. The stale pb alias is omitted because Export-Module is absent, and the protected +PowerShell fl (Format-List) alias is preserved; ln/mklink call the link helper. + +This source repair corrects Split-String's accidental method-property access, +binds New-FileSystemLink to its existing LinkType enum, and maps enum values to +PowerShell provider item types. The spelling of existing public command/parameter +names is retained. Windows batch/Visual Studio helpers are not executed at import. + +Run Shell-Function.Tests.ps1 with Pester 4.10.1. CI tests imports/exports, real text +filters and mocked link-provider arguments; it never runs cmd, changes Visual +Studio state, creates links or invokes the interactive prompt. This module has +no configured Gallery publication or release package. diff --git a/Shell-Functions/Shell-Alias.ps1 b/Shell-Functions/Shell-Alias.ps1 index c27b5a2..2a3105b 100644 --- a/Shell-Functions/Shell-Alias.ps1 +++ b/Shell-Functions/Shell-Alias.ps1 @@ -1,3 +1,3 @@ -Set-Alias ln New-FileSystemLink -Scope Global -Set-Alias mklink New-FileSystemLink -Scope Global -Set-Alias which Get-Command -Scope Global +Set-Alias ln New-FileSystemLink +Set-Alias mklink New-FileSystemLink +Set-Alias which Get-Command diff --git a/Shell-Functions/Shell-Function.Tests.ps1 b/Shell-Functions/Shell-Function.Tests.ps1 new file mode 100644 index 0000000..3069177 --- /dev/null +++ b/Shell-Functions/Shell-Function.Tests.ps1 @@ -0,0 +1,42 @@ +$manifest = Join-Path $PSScriptRoot 'Shell-Function.psd1' +Import-Module $manifest -Force -ErrorAction Stop +Describe 'Shell source imports and filters' { + It 'exports callable functions and resolvable aliases from its manifest' { + $module = Get-Module 'Shell-Function' + $module.ExportedFunctions.Count | Should -Be 7 + $module.ExportedAliases.Count | Should -Be 7 + $module.ExportedAliases.ContainsKey('pb') | Should -BeFalse + (Get-Alias fl).Definition | Should -BeExactly 'Format-List' + foreach ($alias in $module.ExportedAliases.Values) { + Get-Command $alias.Definition -ErrorAction Stop | Should -Not -BeNullOrEmpty + } + (Get-Command New-FileSystemLink).Parameters['type'].ParameterType.Name | Should -BeExactly 'LinkType' + } + It 'filters matching pipeline lines' { + @('Alpha', 'Beta' | Get-SearchAndPrint 'alpha').Count | Should -Be 1 + 'Alpha', 'Beta' | grep 'alpha' | Select-Object -ExpandProperty Line | Should -BeExactly 'Alpha' + } + It 'splits pipeline strings using the requested literal separator' { + ('a,b' | cut ',') -join '|' | Should -BeExactly 'a|b' + ('a::b::' | Split-String '::') -join '|' | Should -BeExactly 'a|b|' + ('a b' | Split-String) -join '|' | Should -BeExactly 'a|b' + } +} +InModuleScope 'Shell-Function' { + Describe 'Link provider argument contracts' { + It 'maps without creating a link' -TestCases @( + @{ Type='Symbolic'; Expected='SymbolicLink' } + @{ Type='Hard'; Expected='HardLink' } + @{ Type='Junction'; Expected='Junction' } + ) { + param($Type, $Expected) + Mock New-Item { [pscustomobject]@{ Path=$Path; ItemType=$ItemType; Value=$Value } } + $result = New-FileSystemLink -source 'source file' -destanation 'dest path' -type $Type + $result.Path | Should -BeExactly 'dest path' + $result.Value | Should -BeExactly 'source file' + $result.ItemType | Should -BeExactly $Expected + Assert-MockCalled New-Item -Times 1 -Exactly -Scope It + } + } +} +Remove-Module 'Shell-Function' -Force diff --git a/Shell-Functions/Shell-Function.ps1 b/Shell-Functions/Shell-Function.ps1 index ff3847c..b8e5bf7 100644 --- a/Shell-Functions/Shell-Function.ps1 +++ b/Shell-Functions/Shell-Function.ps1 @@ -51,7 +51,8 @@ filter Get-SearchAndPrint() { filter Split-String() { Param ([string]$separator = $null) - $_.Split | select-string -pattern $separator + if ([string]::IsNullOrEmpty($separator)) { $_.Split() } + else { $_.Split([string[]]@($separator), [StringSplitOptions]::None) } } function Get-Batchfile ($file) { @@ -107,10 +108,11 @@ function New-FileSystemLink { [string]$destanation = $((Get-Location).Path), [Parameter(Position = 2, ParameterSetName = 'Positional', Mandatory = $true)] - [ServerType]$type = [LinkType]::Symbolic + [LinkType]$type = [LinkType]::Symbolic ) - New-Item -Path $destanation -ItemType $type -Value $source + $itemType = @{ Symbolic = 'SymbolicLink'; Hard = 'HardLink'; Junction = 'Junction' }[$type.ToString()] + New-Item -Path $destanation -ItemType $itemType -Value $source } function Propmpt { @@ -133,6 +135,6 @@ Set-Alias grep Get-SearchAndPrint Set-Alias cut Split-String Set-Alias VsVars32 Initialize-VisualStudioEnvieronment Set-Alias ga Get-CmdletAlias -Set-Alias fl New-FileSystemLink -Set-Alias pb Export-Module +# Keep PowerShell's protected fl (Format-List) alias. Use ln or mklink instead. +# Export-Module is not part of this module; do not create a dangling pb alias. diff --git a/Shell-Functions/Shell-Function.psd1 b/Shell-Functions/Shell-Function.psd1 index 6b53241..715b786 100644 --- a/Shell-Functions/Shell-Function.psd1 +++ b/Shell-Functions/Shell-Function.psd1 @@ -9,7 +9,7 @@ @{ # Script module or binary module file associated with this manifest. -# RootModule = '' +RootModule = 'Shell-Function.psm1' # Version number of this module. ModuleVersion = '0.0.1' @@ -69,16 +69,16 @@ Copyright = '(c) Dmitry.Stadub. All rights reserved.' # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @() +FunctionsToExport = @('Get-SearchAndPrint', 'Split-String', 'Get-Batchfile', 'Initialize-VisualStudioEnvieronment', 'Get-CmdletAlias', 'New-FileSystemLink', 'Propmpt') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() # Variables to export from this module -VariablesToExport = '*' +VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() +AliasesToExport = @('grep', 'cut', 'VsVars32', 'ga', 'ln', 'mklink', 'which') # DSC resources to export from this module # DscResourcesToExport = @() diff --git a/Shell-Functions/Shell-Function.psm1 b/Shell-Functions/Shell-Function.psm1 new file mode 100644 index 0000000..0b98339 --- /dev/null +++ b/Shell-Functions/Shell-Function.psm1 @@ -0,0 +1,4 @@ +. (Join-Path $PSScriptRoot 'Shell-Function.ps1') +. (Join-Path $PSScriptRoot 'Shell-Alias.ps1') +# pb targets a removed Export-Module command; do not expose a dangling alias. +Export-ModuleMember -Function Get-SearchAndPrint, Split-String, Get-Batchfile, Initialize-VisualStudioEnvieronment, Get-CmdletAlias, New-FileSystemLink, Propmpt -Alias grep, cut, VsVars32, ga, ln, mklink, which