-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunt.ps1
110 lines (90 loc) · 3.54 KB
/
runt.ps1
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<#
.SYNOPSIS
.DESCRIPTION
.PARAMETER TestScriptName
.PARAMETER SourceFileName
.INPUTS
.OUTPUTS
.EXAMPLE
.LINK
.NOTES
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $false, ValueFromPipeline = $false)]
[switch]
$Keep,
[Parameter(Mandatory = $false, ValueFromPipeline = $false)]
[switch]
$TAPOutput,
[Parameter(Mandatory = $true, ValueFromPipeline = $false)]
[ValidateNotNullOrEmpty()]
[String]
$TestScriptName,
[Parameter(Mandatory = $true, ValueFromPipeline = $false)]
[ValidateNotNullOrEmpty()]
[String]
$SourceFileName
)
#
# Sourced: https://stackoverflow.com/questions/9738535/powershell-test-for-noninteractive-mode
#
function IsNonInteractiveShell {
# Test each Arg for match of abbreviated '-NonInteractive' command.
$NonInteractive = [Environment]::GetCommandLineArgs() | Where-Object{ $_ -like '-NonI*' }
if ([Environment]::UserInteractive -and -not $NonInteractive) {
# We are in an interactive shell.
return $false
}
return $true
}
function Get-Script-Location
{
# Script invocation directory: directory in which script resides, not necessarily current directory
$scriptInvocation = (Get-Variable MyInvocation -Scope 1).Value
return Split-Path $scriptInvocation.MyCommand.Path
}
Set-Variable -Name ScriptLocation (Get-Script-Location) -Option Private
Set-Variable -Name T1RexxPath (-join ($ScriptLocation, "\", "t1.rexx")) -Option Private
Set-Variable -Name T2RexxPath (-join ($ScriptLocation, "\", "t2.rexx")) -Option Private
Set-Variable -Name T3RexxPath (-join ($ScriptLocation, "\", "t3.rexx")) -Option Private
# Ensure all test framework Rexx source files co-located with current script
foreach ($PathName in @($T1RexxPath,$T2RexxPath,$T3RexxPath)) {
if (-not (Test-Path -Path $PathName -Type Leaf)) {
throw [System.IO.FileNotFoundException] "Error: Missing test suite component - $PathName"
}
}
# Assume target location is the current directory (present working directory or PWD)
Set-Variable -Name TargetLocation (Get-Location) -Option Private
Set-Variable -Name TestScriptNamePath (-join ($TargetLocation, "\", $TestScriptName, ".rexx")) -Option Private
Set-Variable -Name SourceFileNamePath (-join ($TargetLocation, "\", $SourceFileName, ".rexx")) -Option Private
# Test runner name and path
Set-Variable -Name Runner "t.rexx" -Option Private
Set-Variable -Name RunnerFileNamePath (-join ($TargetLocation, "\", $Runner)) -Option Private
# Ensure both test script and source file exist
if (-not (Test-Path -Path $TestScriptNamePath -Type Leaf)) {
throw [System.IO.FileNotFoundException] "Error: Missing test script - $TestScriptNamePath"
}
if (-not (Test-Path -Path $SourceFileNamePath -Type Leaf)) {
throw [System.IO.FileNotFoundException] "Error: Missing source file - $SourceFileNamePath"
}
# Assemble test runner from components and supplied files
Get-Content $T1RexxPath, $TestScriptNamePath,
$T2RexxPath, $SourceFileNamePath,
$T3RexxPath | Set-Content $RunnerFileNamePath
# Execute test runner with output option
if ($TAPOutput) {
rexx $RunnerFileNamePath "TAP" # Emit TAP-compliant output
} else {
rexx $RunnerFileNamePath # else report format output
}
# Need to capture return code of test suite run for return to caller
Set-Variable -Name RC -Value $LastExitCode -Option Private
# Unless KEEP option is set, delete the test runner
if (-not $Keep) {
Remove-Item $RunnerFileNamePath
}
# Return code only needed in a non-interactive shell
if (IsNonInteractiveShell) {
[Environment]::Exit($RC)
}