| 1 |
# Installation path can be passed as argument |
| 2 |
param ([string]$installpath = "$env:ProgramFiles\Environment Modules") |
| 3 |
|
| 4 |
# Test cmd shell first |
| 5 |
try { |
| 6 |
Write-Host "Testing CMD shell environment:" |
| 7 |
cmd /c "TESTINSTALL.bat `"$installpath`"" |
| 8 |
if ($LASTEXITCODE -ne 0) { |
| 9 |
Write-Host "TESTINSTALL.bat failed with exit code $LASTEXITCODE" |
| 10 |
exit $LASTEXITCODE |
| 11 |
} |
| 12 |
Write-Host "CMD shell environment works!" |
| 13 |
} catch { |
| 14 |
Write-Host "An error occurred while running TESTINSTALL.bat: $_" |
| 15 |
exit 1 |
| 16 |
} |
| 17 |
|
| 18 |
Write-Host "`nTesting Powershell (pwsh) environment:" |
| 19 |
|
| 20 |
# Initialize Modules if not already done |
| 21 |
if (-not $env:MODULES_CMD) { |
| 22 |
. "$installpath\init\pwsh.ps1" |
| 23 |
} |
| 24 |
|
| 25 |
# Function to check if a command exists |
| 26 |
function Check-Command { |
| 27 |
param ([string]$command) |
| 28 |
if (-not (Get-Command $command -ErrorAction SilentlyContinue)) { |
| 29 |
Write-Host "'$command' command not found" |
| 30 |
exit 1 |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
# Check commands exist |
| 35 |
Check-Command "envmodule" |
| 36 |
Check-Command "ml" |
| 37 |
|
| 38 |
# Function to run a command and check its output |
| 39 |
function Run-Command { |
| 40 |
param ( |
| 41 |
[string]$command, |
| 42 |
[string]$expectedOutput |
| 43 |
) |
| 44 |
if ((Invoke-Expression $command 2>&1) -notmatch $expectedOutput) { |
| 45 |
Write-Host "'$command' test failed" |
| 46 |
exit 1 |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
Run-Command "envmodule --version" "Modules Release" |
| 51 |
Run-Command "envmodule list" "No Modulefiles Currently Loaded." |
| 52 |
Run-Command "ml" "No Modulefiles Currently Loaded." |
| 53 |
|
| 54 |
# Load null module |
| 55 |
Invoke-Expression "envmodule load null" |
| 56 |
|
| 57 |
Run-Command "envmodule list -t" "null" |
| 58 |
Run-Command "ml -t" "null" |
| 59 |
|
| 60 |
# Unload null module |
| 61 |
Invoke-Expression "ml -null" |
| 62 |
|
| 63 |
Run-Command "envmodule list" "No Modulefiles Currently Loaded." |
| 64 |
Run-Command "ml" "No Modulefiles Currently Loaded." |
| 65 |
|
| 66 |
Write-Host "Powershell (pwsh) environment works!" |