forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_test.go
34 lines (29 loc) · 873 Bytes
/
shell_test.go
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
package main
import (
"testing"
)
func TestBashEscape(t *testing.T) {
assertEqual(t, `''`, BashEscape(""))
assertEqual(t, `$'escape\'quote'`, BashEscape("escape'quote"))
assertEqual(t, `$'foo\r\n\tbar'`, BashEscape("foo\r\n\tbar"))
assertEqual(t, `$'foo bar'`, BashEscape("foo bar"))
assertEqual(t, `$'\xc3\xa9'`, BashEscape("é"))
}
func TestShellDetection(t *testing.T) {
assertNotNil(t, DetectShell("-bash"))
assertNotNil(t, DetectShell("-/bin/bash"))
assertNotNil(t, DetectShell("-/usr/local/bin/bash"))
assertNotNil(t, DetectShell("-zsh"))
assertNotNil(t, DetectShell("-/bin/zsh"))
assertNotNil(t, DetectShell("-/usr/local/bin/zsh"))
}
func assertNotNil(t *testing.T, a Shell) {
if a == nil {
t.Error("Expected not to be nil")
}
}
func assertEqual(t *testing.T, a, b string) {
if a != b {
t.Errorf("Expected \"%v\" to equal \"%v\"", b, a)
}
}