refactor: Bootstrap delle dipendenze non riproducibile
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
function Initialize-PowerShellEnvironment {
|
||||
Write-Host "Initializing PowerShell environment..." -ForegroundColor Yellow
|
||||
|
||||
# Add any environment setup logic here, such as importing modules, setting variables, etc.
|
||||
# Example: Import-Module SomeModule
|
||||
function Import-PowerShellYamlModule {
|
||||
Import-Module powershell-yaml -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host "PowerShell environment initialized." -ForegroundColor Green
|
||||
}
|
||||
|
||||
function Invoke-Main {
|
||||
Write-Host "Preparing environment..." -ForegroundColor Cyan
|
||||
Write-Host
|
||||
|
||||
Initialize-PowerShellEnvironment
|
||||
Write-Host "Initializing PowerShell environment..." -ForegroundColor Yellow
|
||||
Import-PowerShellYamlModule
|
||||
Write-Host "PowerShell environment initialized." -ForegroundColor Green
|
||||
Write-Host
|
||||
|
||||
Write-Host "Environment preparation complete!" -ForegroundColor Green
|
||||
}
|
||||
|
||||
Invoke-Main
|
||||
Invoke-Main
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
$setupToolsScript = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..\scripts\setup-tools.ps1')).Path
|
||||
$expectedOutput = @(
|
||||
'Preparing environment...'
|
||||
''
|
||||
'Initializing PowerShell environment...'
|
||||
'PowerShell environment initialized.'
|
||||
''
|
||||
'Environment preparation complete!'
|
||||
) -join "`n"
|
||||
|
||||
Describe 'setup-tools.ps1' {
|
||||
It 'imports powershell-yaml and preserves the user-facing output' {
|
||||
$originalModulePath = $env:PSModulePath
|
||||
try {
|
||||
$moduleRoot = Join-Path $TestDrive 'available-modules'
|
||||
$moduleDirectory = Join-Path $moduleRoot 'powershell-yaml'
|
||||
$null = New-Item -ItemType Directory -Path $moduleDirectory
|
||||
Set-Content -LiteralPath (Join-Path $moduleDirectory 'powershell-yaml.psm1') -Value ''
|
||||
$env:PSModulePath = $moduleRoot
|
||||
|
||||
$escapedScriptPath = $setupToolsScript.Replace("'", "''")
|
||||
$command = "& '$escapedScriptPath'; if (-not (Get-Module -Name powershell-yaml)) { exit 42 }"
|
||||
|
||||
$output = @(& pwsh -NoProfile -Command $command 6>&1 | ForEach-Object { $_.ToString() })
|
||||
|
||||
$LASTEXITCODE | Should Be 0
|
||||
($output -join "`n") | Should Be $expectedOutput
|
||||
}
|
||||
finally {
|
||||
$env:PSModulePath = $originalModulePath
|
||||
}
|
||||
}
|
||||
|
||||
It 'continues successfully when powershell-yaml is unavailable' {
|
||||
$originalModulePath = $env:PSModulePath
|
||||
try {
|
||||
$env:PSModulePath = Join-Path $TestDrive 'missing-modules'
|
||||
|
||||
$output = @(& pwsh -NoProfile -File $setupToolsScript 6>&1 | ForEach-Object { $_.ToString() })
|
||||
|
||||
$LASTEXITCODE | Should Be 0
|
||||
($output -join "`n") | Should Be $expectedOutput
|
||||
}
|
||||
finally {
|
||||
$env:PSModulePath = $originalModulePath
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user