Skip to content

Commit 20ecd17

Browse files
feat: Show-Turtle ( Fixes #257 )
Will not show when not interactive
1 parent 0a9524b commit 20ecd17

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Commands/Show-Turtle.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ function Show-Turtle
2929
$extensionPattern = "(?>$($validExtensions -replace '\.','\.' -join '|'))$"
3030
}
3131
process {
32+
# If we are not running interactively,
33+
# we obviously do not want to try to show something on the screen.
34+
if (-not [Environment]::UserInteractive) {
35+
# Instead, just pass thru our input.
36+
return $InputObject
37+
}
3238
if ($InputObject -is [IO.FileInfo] -and $InputObject.Extension -match $extensionPattern) {
3339
Invoke-Item $InputObject.Fullname
3440
} elseif ($InputObject.pstypenames -contains 'Turtle') {

Turtle.tests.ps1

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,23 @@ describe Turtle {
6666
}
6767
}
6868

69-
69+
context 'Turtle Security' {
70+
it 'Can run in a data block' {
71+
$dataBlockTurtle = data -supportedCommand turtle, Get-Random {
72+
turtle rotate 45 forward (Get-Random -Min 21 -Max 42)
73+
}
74+
$dataBlockTurtle.Heading | Should -Be 45
75+
}
76+
it 'Will not show a turtle in non-interactive mode' {
77+
if ([Environment]::UserInteractive) {
78+
Write-Warning "Cannot test non-iteractivity interactively"
79+
} else {
80+
$dataBlockTurtle = data -supportedCommand turtle, Get-Random {
81+
turtle rotate 45 forward (Get-Random -Min 21 -Max 42) show
82+
}
83+
$dataBlockTurtle.Heading | Should -Be 45
84+
}
85+
}
86+
}
7087
}
88+

0 commit comments

Comments
 (0)