github.com/secure-build/gitlab-runner@v12.5.0+incompatible/shells/powershell_test.go (about)

     1  package shells
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestPowershell_CommandShellEscapes(t *testing.T) {
    10  	writer := &PsWriter{}
    11  	writer.Command("foo", "x&(y)")
    12  
    13  	assert.Equal(t, "& \"foo\" \"x&(y)\"\r\nif(!$?) { Exit &{if($LASTEXITCODE) {$LASTEXITCODE} else {1}} }\r\n\r\n", writer.String())
    14  }
    15  
    16  func TestPowershell_IfCmdShellEscapes(t *testing.T) {
    17  	writer := &PsWriter{}
    18  	writer.IfCmd("foo", "x&(y)")
    19  
    20  	assert.Equal(t, "Set-Variable -Name cmdErr -Value $false\r\nTry {\r\n  & \"foo\" \"x&(y)\" 2>$null\r\n  if(!$?) { throw &{if($LASTEXITCODE) {$LASTEXITCODE} else {1}} }\r\n} Catch {\r\n  Set-Variable -Name cmdErr -Value $true\r\n}\r\nif(!$cmdErr) {\r\n", writer.String())
    21  }