File: shell_test.go

package info (click to toggle)
direnv 2.37.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 872 kB
  • sloc: sh: 1,499; csh: 83; makefile: 7
file content (34 lines) | stat: -rw-r--r-- 908 bytes parent folder | download
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 cmd

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, expected, actual string) {
	if expected != actual {
		t.Errorf("Expected \"%v\" to equal \"%v\"", expected, actual)
	}
}