File: TESTINSTALL_PWSH.ps1

package info (click to toggle)
modules 5.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,036 kB
  • sloc: exp: 79,659; sh: 6,142; tcl: 5,900; makefile: 1,493; ansic: 474; python: 265; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (66 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Installation path can be passed as argument
param ([string]$installpath = "$env:ProgramFiles\Environment Modules")

# Test cmd shell first
try {
   Write-Host "Testing CMD shell environment:"
   cmd /c "TESTINSTALL.bat `"$installpath`""
   if ($LASTEXITCODE -ne 0) {
      Write-Host "TESTINSTALL.bat failed with exit code $LASTEXITCODE"
      exit $LASTEXITCODE
   }
   Write-Host "CMD shell environment works!"
} catch {
   Write-Host "An error occurred while running TESTINSTALL.bat: $_"
   exit 1
}

Write-Host "`nTesting Powershell (pwsh) environment:"

# Initialize Modules if not already done
if (-not $env:MODULES_CMD) {
   . "$installpath\init\pwsh.ps1"
}

# Function to check if a command exists
function Check-Command {
   param ([string]$command)
   if (-not (Get-Command $command -ErrorAction SilentlyContinue)) {
      Write-Host "'$command' command not found"
      exit 1
   }
}

# Check commands exist
Check-Command "envmodule"
Check-Command "ml"

# Function to run a command and check its output
function Run-Command {
   param (
      [string]$command,
      [string]$expectedOutput
   )
   if ((Invoke-Expression $command 2>&1) -notmatch $expectedOutput) {
      Write-Host "'$command' test failed"
      exit 1
   }
}

Run-Command "envmodule --version" "Modules Release"
Run-Command "envmodule list" "No Modulefiles Currently Loaded."
Run-Command "ml" "No Modulefiles Currently Loaded."

# Load null module
Invoke-Expression "envmodule load null"

Run-Command "envmodule list -t" "null"
Run-Command "ml -t" "null"

# Unload null module
Invoke-Expression "ml -null"

Run-Command "envmodule list" "No Modulefiles Currently Loaded."
Run-Command "ml" "No Modulefiles Currently Loaded."

Write-Host "Powershell (pwsh) environment works!"