File: shell_test.go

package info (click to toggle)
go-dlib 5.6.0.9%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,212 kB
  • sloc: ansic: 4,664; xml: 1,456; makefile: 20; sh: 15
file content (33 lines) | stat: -rw-r--r-- 518 bytes parent folder | download | duplicates (3)
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
package shell

import (
	"os/exec"
	"testing"
)

func TestEncode(t *testing.T) {
	_, err := exec.LookPath("sh")
	if err != nil {
		t.Skip("not found sh")
	}

	for _, s := range []string{
		"hello world",
		"hello$world",
		"hello\t\r\nworld",
		"中文 english",
		"`~!#$&*()|\\;'\"<>? ",
	} {
		r := Encode(s)
		t.Log(r)

		cmd := exec.Command("sh", "-c", "echo -n "+r)
		output, err := cmd.Output()
		if err != nil {
			t.Fatal(err)
		}
		if s != string(output) {
			t.Errorf("%q != %q", s, string(output))
		}
	}
}