20 lines
1.3 KiB
PowerShell
20 lines
1.3 KiB
PowerShell
param([Parameter(Mandatory)][string]$EvidenceDir,[string]$Source=(Join-Path $PSScriptRoot 'final-common.ps1'))
|
|
$ErrorActionPreference='Stop'
|
|
New-Item -ItemType Directory -Path $EvidenceDir -Force|Out-Null
|
|
$ast=[Management.Automation.Language.Parser]::ParseFile($Source,[ref]$null,[ref]$null)
|
|
foreach($name in @('WorldSafe','TapBall')){
|
|
$function=$ast.Find({param($n)$n-is[Management.Automation.Language.FunctionDefinitionAst]-and$n.Name-eq$name},$true)
|
|
if($function){. ([scriptblock]::Create($function.Extent.Text))}
|
|
}
|
|
$script:taps=0
|
|
function BallPoint($Board,[string]$Id){return $script:point}
|
|
function Step { $script:taps++ }
|
|
$checks=@(foreach($case in @(@{point=@(1200,500);safe=$true},@{point=@(312,108);safe=$false},@{point=@(-30,500);safe=$false},@{point=@(2500,500);safe=$false},@{point=@(1200,900);safe=$false})){
|
|
$script:point=$case.point;$script:taps=0;$rejected=$false
|
|
try{TapBall 'probe' $null 'known-id'}catch{$rejected=$true}
|
|
@{point=$case.point;expectedSafe=$case.safe;rejected=$rejected;taps=$script:taps;passed=if($case.safe){!$rejected-and$script:taps-eq1}else{$rejected-and$script:taps-eq0}}
|
|
})
|
|
$passed=@($checks|Where-Object passed -ne $true).Count-eq0
|
|
@{source=$Source;passed=$passed;checks=$checks}|ConvertTo-Json -Depth 6|Set-Content (Join-Path $EvidenceDir 'safe-tap-result.json')
|
|
if(!$passed){exit 1};exit 0
|